@@ -44,7 +44,8 @@ define([
4444 'json' : 'json' ,
4545 'pickle' : '' ,
4646 'sas' : '' , // xport or sas7bdat
47- 'spss' : ''
47+ 'spss' : '' ,
48+ 'parquet' :'parquet'
4849 }
4950
5051 this . package = {
@@ -90,7 +91,8 @@ define([
9091 'json' : 'pd_readJson' ,
9192 'pickle' : 'pd_readPickle' ,
9293 'sas' : 'pd_readSas' ,
93- 'spss' : 'pd_readSpss'
94+ 'spss' : 'pd_readSpss' ,
95+ 'parquet' :'pd_readParquet'
9496 } ,
9597 selectedType : 'csv' ,
9698 package : null ,
@@ -104,7 +106,8 @@ define([
104106 'csv' : 'pd_toCsv' ,
105107 'excel' : 'pd_toExcel' ,
106108 'json' : 'pd_toJson' ,
107- 'pickle' : 'pd_toPickle'
109+ 'pickle' : 'pd_toPickle' ,
110+ 'parquet' :'pd_toParquet'
108111 } ,
109112 selectedType : 'csv' ,
110113 package : null ,
@@ -194,22 +197,64 @@ define([
194197 that . state [ 'vp_fileioType' ] = pageType ;
195198 $ ( that . wrapSelector ( '.vp-fileio-box' ) ) . hide ( ) ;
196199 $ ( that . wrapSelector ( '#vp_file' + pageType ) ) . show ( ) ;
197-
200+
201+
198202 //set fileExtensions
199203 that . fileResultState = {
200204 ...that . fileState [ pageType ] . fileResultState
201205 } ;
202206 } ) ;
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+
203239 }
204240
205241 _bindEventByType ( pageType ) {
206242 var that = this ;
207243 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 ;
209250 // select file type
210251 $ ( this . wrapSelector ( prefix + '#fileType' ) ) . change ( function ( ) {
211252 var value = $ ( this ) . val ( ) ;
212253 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+
213258
214259 // reload
215260 that . renderPage ( pageType ) ;
@@ -327,7 +372,7 @@ define([
327372 renderPage ( pageType ) {
328373 var that = this ;
329374 var prefix = '#vp_file' + pageType + ' ' ;
330-
375+
331376 // clear
332377 $ ( this . wrapSelector ( prefix + '#vp_inputOutputBox table tbody' ) ) . html ( '' ) ;
333378 $ ( this . wrapSelector ( prefix + '#vp_optionBox table tbody' ) ) . html ( '' ) ;
@@ -344,7 +389,7 @@ define([
344389 ...this . fileState [ pageType ] . fileResultState
345390 } ;
346391
347- if ( selectedType == 'pickle' ) {
392+ if ( selectedType == 'pickle' || selectedType == 'parquet' ) {
348393 // hide additional option box
349394 $ ( this . wrapSelector ( prefix + '#vp_optionBox' ) ) . closest ( '.vp-accordian-container' ) . hide ( ) ;
350395 } else {
@@ -355,7 +400,7 @@ define([
355400 if ( selectedType == 'json' ) {
356401 this . fileResultState . pathInputId = this . wrapSelector ( prefix + '#path_or_buf' ) ;
357402 }
358- if ( selectedType == 'pickle' ) {
403+ if ( selectedType == 'pickle' || selectedType == 'parquet' ) {
359404 this . fileResultState . pathInputId = this . wrapSelector ( prefix + '#path' ) ;
360405 }
361406 }
@@ -365,18 +410,30 @@ define([
365410 // pdGen.vp_showInterfaceOnPage(this.wrapSelector('#vp_file' + pageType), thisPkg);
366411 pdGen . vp_showInterfaceOnPage ( this , thisPkg , this . state , parent = ( '#vp_file' + pageType ) ) ;
367412
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+
368428 // 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- ) ;
373429 var fileTypeList = Object . keys ( fileTypeObj ) ;
374430 fileTypeList . forEach ( type => {
375431 $ ( this . wrapSelector ( prefix + '#fileType' ) ) . append (
376432 $ ( `<option value="${ type } ">${ type } </option>` )
377433 ) ;
378434 } ) ;
379435
436+
380437 // prepend user option
381438 let hasAllocateTo = $ ( this . wrapSelector ( prefix + '#o0' ) ) . length > 0 ;
382439 if ( hasAllocateTo ) {
@@ -390,17 +447,17 @@ define([
390447 . append ( $ ( '<td><input id="userOption" type="text" class="vp-input vp-state" placeholder="key=value, ..."/></td>' ) )
391448 )
392449 }
393-
450+
394451 $ ( this . wrapSelector ( prefix + '#fileType' ) ) . val ( selectedType ) ;
395-
452+
396453 // add file navigation button
397454 if ( pageType == 'Write' ) {
398455 if ( selectedType == 'json' ) {
399456 $ ( prefix + '#path_or_buf' ) . parent ( ) . html (
400457 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>'
401458 , 'vp-file-browser-button' )
402459 ) ;
403- } else if ( selectedType == 'pickle' ) {
460+ } else if ( selectedType == 'pickle' || selectedType == 'parquet' ) {
404461 $ ( prefix + '#path' ) . parent ( ) . html (
405462 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>'
406463 , 'vp-file-browser-button' )
@@ -493,7 +550,6 @@ define([
493550 var result = pdGen . vp_codeGenerator ( this , thisPkg , this . state , userOption . toString ( ) , parent = '#vp_fileWrite' ) ;
494551 sbCode . append ( result ) ;
495552 }
496-
497553 return sbCode . toString ( ) ;
498554 }
499555
0 commit comments