Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document arrow data types to perspective data schema load init mapping #601

Closed
RandomFractals opened this issue May 28, 2019 · 4 comments
Closed
Labels
documentation Improvements/bugs/changes to documentation

Comments

@RandomFractals
Copy link

RandomFractals commented May 28, 2019

Support Question

I had to do this fine dance after looking at your utils.js and perspective.js#ArrowColumnLoader to figure out how to inject arrow data types schema and translations into perspective.js from arrow data schema in my config.ts: https://github.com/RandomFractals/vscode-data-preview/blob/master/src/config.ts

// arrow to data view type mappings
// see: https://github.com/finos/perspective/blob/master/packages/perspective/src/js/utils.js
// and https://github.com/finos/perspective/blob/master/packages/perspective/src/js/perspective.js#ArrowColumnLoader
export const dataTypes = { 
  "Binary": "string",
  "Bool": "boolean",
  "Date": "date",
  "Dictionary": "string",
  "Float32": "float",
  "Float64": "float",
  "Int8": "integer",
  "Int16": "integer",
  "Int32": "integer",
  "Int64": "integer",
  "Timestamp": "datetime",
  "Utf8": "string",
};

after hours of code browsing, I found that your load({object, object} method lets me set data schema and utils.js#get_column_types() helped me infer what your corresponding arrow data types are.

Could use better enum or docs on this.

I ended up doing this in my data.preview.ts for arrow data types mapping:

    // remap arrow data schema to columns for data viewer
    this._schema = {};
    dataTable.schema.fields.map(field => {
      let fieldType: string = field.type.toString();
      const typesIndex: number = fieldType.indexOf('<');
      if (typesIndex > 0) {
        fieldType = fieldType.substring(0, typesIndex);
      }
      this._schema[field.name] = config.dataTypes[fieldType];
    });

and then this tricky biz in data.preview.html:

            viewer.restore(viewConfig);
            if (data.schema !== undefined && Object.keys(data.schema).length > 0) {
              // viewer.columns = viewConfig['columns'];
              viewer.load(data.schema);
              viewer.update(tableData);
            }
            else {
              viewer.load(tableData);
            }

It worked! I just wish I did not have to spend hours to figure it out. Thx!

BTW, your arrow data support is awesome! Check out mine too! :)

@timkpaine timkpaine added the documentation Improvements/bugs/changes to documentation label Jul 30, 2019
@RandomFractals
Copy link
Author

@texodus & @timkpaine any updates on this?

@texodus
Copy link
Member

texodus commented Aug 14, 2019

No update; this is a valid issue, but not in my immediate dev plan. For now, perspective supports well only the base types supported by Javascript: 32bit signed int, double, string, bool, datetime. PRs welcome, as always.

@RandomFractals
Copy link
Author

RandomFractals commented Aug 14, 2019

you keep saying that yet dates still could use some work :(

Can you at least address this 1 pesky issue with dates in your next v0.3.7 rc release?

#524

You end all your close tickets with PRs are welcomed, yet you don't merge them due to CLA or some other not developed in house reasons. That 1 is kind of a sticky point for most devs working with data and your lib.

Thx in advance!

@RandomFractals
Copy link
Author

you can close this ticket. I can find my ways around your repo :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements/bugs/changes to documentation
Projects
None yet
Development

No branches or pull requests

3 participants