@@ -32,57 +32,57 @@ export class ArrowDataProvider implements IDataProvider {
3232 * @param parseOptions Data parse options.
3333 * @param loadData Load data callback.
3434 */
35- public getData ( dataUrl : string , parseOptions : any , loadData : Function ) : void {
35+ public async getData ( dataUrl : string , parseOptions : any , loadData : Function ) : Promise < void > {
3636 const dataFileType : string = dataUrl . substr ( dataUrl . lastIndexOf ( '.' ) ) ; // file extension
3737
38- // get binary arrow data
39- const dataBuffer : Buffer = fileUtils . readDataFile ( dataUrl ) ;
40-
41- // create typed data array
42- const dataArray : Uint8Array = new Uint8Array ( dataBuffer ) ;
43- this . logger . debug ( 'getData(): data size in bytes:' , dataArray . byteLength . toLocaleString ( ) ) ;
44-
45- // create arrow table
46- const dataTable : Table = Table . from ( dataArray ) ;
47-
48- // remap arrow data schema to columns for data viewer
49- const dataSchema = { } ;
50- dataTable . schema . fields . map ( field => {
51- let fieldType : string = field . type . toString ( ) ;
52- const typesIndex : number = fieldType . indexOf ( '<' ) ;
53- if ( typesIndex > 0 ) {
54- fieldType = fieldType . substring ( 0 , typesIndex ) ;
38+ // read binary Arrow data
39+ await fileUtils . readDataFile ( dataUrl , null ) . then ( ( dataBuffer : Buffer ) => {
40+ // create typed data array
41+ const dataArray : Uint8Array = new Uint8Array ( dataBuffer ) ;
42+ this . logger . debug ( 'getData(): data size in bytes:' , dataArray . byteLength . toLocaleString ( ) ) ;
43+
44+ // create arrow table
45+ const dataTable : Table = Table . from ( dataArray ) ;
46+
47+ // remap arrow data schema to columns for data viewer
48+ const dataSchema = { } ;
49+ dataTable . schema . fields . map ( field => {
50+ let fieldType : string = field . type . toString ( ) ;
51+ const typesIndex : number = fieldType . indexOf ( '<' ) ;
52+ if ( typesIndex > 0 ) {
53+ fieldType = fieldType . substring ( 0 , typesIndex ) ;
54+ }
55+ dataSchema [ field . name ] = config . dataTypes [ fieldType ] ;
56+ } ) ;
57+ // cache arrow data view schema
58+ this . dataSchemaMap [ dataUrl ] = dataSchema ;
59+
60+ // create Arrow schema.json file for data schema text data preview
61+ const dataSchemaFilePath : string = dataUrl . replace ( dataFileType , '.schema.json' ) ;
62+ if ( parseOptions . createJsonSchema && ! fs . existsSync ( dataSchemaFilePath ) ) {
63+ fileUtils . createJsonFile ( dataSchemaFilePath , dataTable . schema ) ;
5564 }
56- dataSchema [ field . name ] = config . dataTypes [ fieldType ] ;
57- } ) ;
58- // cache arrow data view schema
59- this . dataSchemaMap [ dataUrl ] = dataSchema ;
6065
61- // create Arrow schema.json file for data schema text data preview
62- const dataSchemaFilePath : string = dataUrl . replace ( dataFileType , '.schema.json' ) ;
63- if ( parseOptions . createJsonSchema && ! fs . existsSync ( dataSchemaFilePath ) ) {
64- fileUtils . createJsonFile ( dataSchemaFilePath , dataTable . schema ) ;
65- }
66-
67- // create arrow data.json for text arrow data preview
68- let dataRows : Array < any > = [ ] ;
69- const jsonFilePath : string = dataUrl . replace ( dataFileType , '.json' ) ;
70- if ( parseOptions . createJsonFiles && ! fs . existsSync ( jsonFilePath ) ) {
71- // convert arrow table data to array of objects (happens only on the 1st run :)
72- dataRows = Array ( dataTable . length ) ;
73- const fields = dataTable . schema . fields . map ( field => field . name ) ;
74- for ( let i = 0 , n = dataRows . length ; i < n ; ++ i ) {
75- const proto = { } ;
76- fields . forEach ( ( fieldName , index ) => {
77- const column = dataTable . getColumnAt ( index ) ;
78- proto [ fieldName ] = column . get ( i ) ;
79- } ) ;
80- dataRows [ i ] = proto ;
66+ // create arrow data.json for text arrow data preview
67+ let dataRows : Array < any > = [ ] ;
68+ const jsonFilePath : string = dataUrl . replace ( dataFileType , '.json' ) ;
69+ if ( parseOptions . createJsonFiles && ! fs . existsSync ( jsonFilePath ) ) {
70+ // convert arrow table data to array of objects (happens only on the 1st run :)
71+ dataRows = Array ( dataTable . length ) ;
72+ const fields = dataTable . schema . fields . map ( field => field . name ) ;
73+ for ( let i = 0 , n = dataRows . length ; i < n ; ++ i ) {
74+ const proto = { } ;
75+ fields . forEach ( ( fieldName , index ) => {
76+ const column = dataTable . getColumnAt ( index ) ;
77+ proto [ fieldName ] = column . get ( i ) ;
78+ } ) ;
79+ dataRows [ i ] = proto ;
80+ }
81+ fileUtils . createJsonFile ( jsonFilePath , dataRows ) ;
8182 }
82- fileUtils . createJsonFile ( jsonFilePath , dataRows ) ;
83- }
8483
85- loadData ( dataArray ) ;
84+ loadData ( dataArray ) ;
85+ } ) ;
8686 } // end of getData()
8787
8888 /**
0 commit comments