@@ -44,7 +44,8 @@ define([
44
44
'json' : 'json' ,
45
45
'pickle' : '' ,
46
46
'sas' : '' , // xport or sas7bdat
47
- 'spss' : ''
47
+ 'spss' : '' ,
48
+ 'parquet' :'parquet'
48
49
}
49
50
50
51
this . package = {
@@ -90,7 +91,8 @@ define([
90
91
'json' : 'pd_readJson' ,
91
92
'pickle' : 'pd_readPickle' ,
92
93
'sas' : 'pd_readSas' ,
93
- 'spss' : 'pd_readSpss'
94
+ 'spss' : 'pd_readSpss' ,
95
+ 'parquet' :'pd_readParquet'
94
96
} ,
95
97
selectedType : 'csv' ,
96
98
package : null ,
@@ -104,7 +106,8 @@ define([
104
106
'csv' : 'pd_toCsv' ,
105
107
'excel' : 'pd_toExcel' ,
106
108
'json' : 'pd_toJson' ,
107
- 'pickle' : 'pd_toPickle'
109
+ 'pickle' : 'pd_toPickle' ,
110
+ 'parquet' :'pd_toParquet'
108
111
} ,
109
112
selectedType : 'csv' ,
110
113
package : null ,
@@ -194,22 +197,64 @@ define([
194
197
that . state [ 'vp_fileioType' ] = pageType ;
195
198
$ ( that . wrapSelector ( '.vp-fileio-box' ) ) . hide ( ) ;
196
199
$ ( that . wrapSelector ( '#vp_file' + pageType ) ) . show ( ) ;
197
-
200
+
201
+
198
202
//set fileExtensions
199
203
that . fileResultState = {
200
204
...that . fileState [ pageType ] . fileResultState
201
205
} ;
202
206
} ) ;
207
+
208
+ // fileReadAs change Event, Use PyArrow
209
+ $ ( document ) . on ( 'change' , this . wrapSelector ( '#fileReadAs' ) , function ( ) {
210
+ let isChecked = $ ( this ) . prop ( 'checked' ) ;
211
+ var fileioType = that . state . vp_fileioType ;
212
+ var prefix = '#vp_file' + fileioType + ' ' ;
213
+ var selectedFileFormat = that . fileState [ fileioType ] . selectedType ;
214
+ var fileioTypePrefix = fileioType . toLowerCase ( ) ;
215
+ if ( fileioTypePrefix == 'write' ) {
216
+ fileioTypePrefix = "to" ;
217
+ }
218
+
219
+ if ( isChecked ) { // pyArrow
220
+ that . fileState [ fileioType ] . fileTypeId [ that . state . fileExtension ] = "pa_" + fileioTypePrefix + selectedFileFormat [ 0 ] . toUpperCase ( ) + selectedFileFormat . slice ( 1 ) ;
221
+ $ ( that . wrapSelector ( prefix + '#vp_optionBox' ) ) . closest ( '.vp-accordian-container' ) . hide ( ) ;
222
+ }
223
+ else { // pandas
224
+ that . fileState [ fileioType ] . fileTypeId [ that . state . fileExtension ] = "pd_" + fileioTypePrefix + selectedFileFormat [ 0 ] . toUpperCase ( ) + selectedFileFormat . slice ( 1 ) ;
225
+ if ( that . state . fileExtension != 'parquet' ) { // parquet has no options area
226
+ $ ( that . wrapSelector ( prefix + '#vp_optionBox' ) ) . closest ( '.vp-accordian-container' ) . show ( ) ;
227
+ }
228
+ }
229
+
230
+ var fileTypeObj = that . fileState [ fileioType ] [ 'fileTypeId' ] ;
231
+ var selectedType = that . fileState [ fileioType ] [ 'selectedType' ] ;
232
+ let fileId = fileTypeObj [ selectedType ] ;
233
+ let pdLib = pandasLibrary . PANDAS_FUNCTION ;
234
+ let thisPkg = JSON . parse ( JSON . stringify ( pdLib [ fileId ] ) ) ;
235
+
236
+ that . fileState [ fileioType ] . package = thisPkg ;
237
+ } ) ;
238
+
203
239
}
204
240
205
241
_bindEventByType ( pageType ) {
206
242
var that = this ;
207
243
var prefix = '#vp_file' + pageType + ' ' ;
208
-
244
+
245
+ var fileioTypePrefix = pageType . toLowerCase ( ) ;
246
+ if ( fileioTypePrefix == 'write' ) {
247
+ fileioTypePrefix = "to" ;
248
+ }
249
+ var selectedFileFormat = that . fileState [ pageType ] . selectedType ;
209
250
// select file type
210
251
$ ( this . wrapSelector ( prefix + '#fileType' ) ) . change ( function ( ) {
211
252
var value = $ ( this ) . val ( ) ;
212
253
that . fileState [ pageType ] . selectedType = value ;
254
+
255
+ // Whenever change the file type, change to default pandas
256
+ that . fileState [ pageType ] . fileTypeId [ that . state . fileExtension ] = "pd_" + fileioTypePrefix + selectedFileFormat [ 0 ] . toUpperCase ( ) + selectedFileFormat . slice ( 1 ) ;
257
+
213
258
214
259
// reload
215
260
that . renderPage ( pageType ) ;
@@ -327,7 +372,7 @@ define([
327
372
renderPage ( pageType ) {
328
373
var that = this ;
329
374
var prefix = '#vp_file' + pageType + ' ' ;
330
-
375
+
331
376
// clear
332
377
$ ( this . wrapSelector ( prefix + '#vp_inputOutputBox table tbody' ) ) . html ( '' ) ;
333
378
$ ( this . wrapSelector ( prefix + '#vp_optionBox table tbody' ) ) . html ( '' ) ;
@@ -344,7 +389,7 @@ define([
344
389
...this . fileState [ pageType ] . fileResultState
345
390
} ;
346
391
347
- if ( selectedType == 'pickle' ) {
392
+ if ( selectedType == 'pickle' || selectedType == 'parquet' ) {
348
393
// hide additional option box
349
394
$ ( this . wrapSelector ( prefix + '#vp_optionBox' ) ) . closest ( '.vp-accordian-container' ) . hide ( ) ;
350
395
} else {
@@ -355,7 +400,7 @@ define([
355
400
if ( selectedType == 'json' ) {
356
401
this . fileResultState . pathInputId = this . wrapSelector ( prefix + '#path_or_buf' ) ;
357
402
}
358
- if ( selectedType == 'pickle' ) {
403
+ if ( selectedType == 'pickle' || selectedType == 'parquet' ) {
359
404
this . fileResultState . pathInputId = this . wrapSelector ( prefix + '#path' ) ;
360
405
}
361
406
}
@@ -365,18 +410,30 @@ define([
365
410
// pdGen.vp_showInterfaceOnPage(this.wrapSelector('#vp_file' + pageType), thisPkg);
366
411
pdGen . vp_showInterfaceOnPage ( this , thisPkg , this . state , parent = ( '#vp_file' + pageType ) ) ;
367
412
413
+ // pyarrow can r/w parquet, csv and only read json.
414
+ if ( ( pageType == 'Read' && selectedType == 'json' ) || selectedType == 'parquet' || selectedType == 'csv' ) {
415
+ // add checkbox 'Use PyArrow', next to File Type
416
+ $ ( this . wrapSelector ( prefix + '#vp_inputOutputBox table tbody' ) ) . prepend (
417
+ $ ( '<tr>' ) . append ( $ ( `<td><label for="fileType" class="vp-bold vp-orange-text">File Type</label></td>` ) )
418
+ . append ( $ ( '<td><select id="fileType" class="vp-select"></select> <label><input id="fileReadAs" type="checkbox"/><span>Use PyArrow</span></label></td>' ) )
419
+ ) ;
420
+ }
421
+ else {
422
+ $ ( this . wrapSelector ( prefix + '#vp_inputOutputBox table tbody' ) ) . prepend (
423
+ $ ( '<tr>' ) . append ( $ ( `<td><label for="fileType" class="vp-bold vp-orange-text">File Type</label></td>` ) )
424
+ . append ( $ ( '<td><select id="fileType" class="vp-select"></select> </td>' ) )
425
+ ) ;
426
+ }
427
+
368
428
// prepend file type selector
369
- $ ( this . wrapSelector ( prefix + '#vp_inputOutputBox table tbody' ) ) . prepend (
370
- $ ( '<tr>' ) . append ( $ ( `<td><label for="fileType" class="vp-bold vp-orange-text">File Type</label></td>` ) )
371
- . append ( $ ( '<td><select id="fileType" class="vp-select"></select></td>' ) )
372
- ) ;
373
429
var fileTypeList = Object . keys ( fileTypeObj ) ;
374
430
fileTypeList . forEach ( type => {
375
431
$ ( this . wrapSelector ( prefix + '#fileType' ) ) . append (
376
432
$ ( `<option value="${ type } ">${ type } </option>` )
377
433
) ;
378
434
} ) ;
379
435
436
+
380
437
// prepend user option
381
438
let hasAllocateTo = $ ( this . wrapSelector ( prefix + '#o0' ) ) . length > 0 ;
382
439
if ( hasAllocateTo ) {
@@ -390,17 +447,17 @@ define([
390
447
. append ( $ ( '<td><input id="userOption" type="text" class="vp-input vp-state" placeholder="key=value, ..."/></td>' ) )
391
448
)
392
449
}
393
-
450
+
394
451
$ ( this . wrapSelector ( prefix + '#fileType' ) ) . val ( selectedType ) ;
395
-
452
+
396
453
// add file navigation button
397
454
if ( pageType == 'Write' ) {
398
455
if ( selectedType == 'json' ) {
399
456
$ ( prefix + '#path_or_buf' ) . parent ( ) . html (
400
457
com_util . formatString ( '<input type="text" class="vp-input vp-state" id="path_or_buf" index="0" placeholder="" value="" title=""><div id="vp_openFileNavigationBtn" class="{0}"></div>'
401
458
, 'vp-file-browser-button' )
402
459
) ;
403
- } else if ( selectedType == 'pickle' ) {
460
+ } else if ( selectedType == 'pickle' || selectedType == 'parquet' ) {
404
461
$ ( prefix + '#path' ) . parent ( ) . html (
405
462
com_util . formatString ( '<input type="text" class="vp-input vp-state" id="path" index="0" placeholder="" value="" title="" required="true"><div id="vp_openFileNavigationBtn" class="{0}"></div>'
406
463
, 'vp-file-browser-button' )
@@ -493,7 +550,6 @@ define([
493
550
var result = pdGen . vp_codeGenerator ( this , thisPkg , this . state , userOption . toString ( ) , parent = '#vp_fileWrite' ) ;
494
551
sbCode . append ( result ) ;
495
552
}
496
-
497
553
return sbCode . toString ( ) ;
498
554
}
499
555
0 commit comments