@@ -23,6 +23,20 @@ export function isDatabaseClient(value, mode) {
2323 ) ;
2424}
2525
26+ // Returns true if the vaue is an Apache Arrow table. This uses a “duck” test
27+ // (instead of strict instanceof) because we want it to work with a range of
28+ // Apache Arrow versions at least 7.0.0 or above.
29+ // https://arrow.apache.org/docs/7.0/js/classes/Arrow_dom.Table.html
30+ export function isArrowTable ( value ) {
31+ return (
32+ value &&
33+ typeof value . getChild === "function" &&
34+ typeof value . toArray === "function" &&
35+ value . schema &&
36+ Array . isArray ( value . schema . fields )
37+ ) ;
38+ }
39+
2640// Returns true if the value is a typed array (for a single-column table), or if
2741// it’s an array. In the latter case, the elements of the array must be
2842// consistently typed: either plain objects or primitives or dates.
@@ -145,6 +159,7 @@ export const __query = Object.assign(
145159 source = await loadDataSource ( await source , "table" ) ;
146160 if ( isDatabaseClient ( source ) ) return evaluateQuery ( source , makeQueryTemplate ( operations , source ) , invalidation ) ;
147161 if ( isDataArray ( source ) ) return __table ( source , operations ) ;
162+ if ( isArrowTable ( source ) ) return __arrow ( source , operations ) ;
148163 if ( ! source ) throw new Error ( "missing data source" ) ;
149164 throw new Error ( "invalid data source" ) ;
150165 } ,
@@ -164,6 +179,7 @@ export async function loadDataSource(source, mode) {
164179 case "text/csv" : return source . csv ( { typed : true } ) ;
165180 case "text/tab-separated-values" : return source . tsv ( { typed : true } ) ;
166181 case "application/json" : return source . json ( ) ;
182+ default : if ( / \. a r r o w $ / i. test ( source . name ) ) return source . arrow ( { version : 9 } ) ;
167183 }
168184 }
169185 if ( mode === "table" || mode === "sql" ) {
@@ -390,8 +406,17 @@ function likeOperand(operand) {
390406 return { ...operand , value : `%${ operand . value } %` } ;
391407}
392408
409+ // This function applies table cell operations to an in-memory Apache Arrow
410+ // table; it should be equivalent to the corresponding SQL query.
411+ function __arrow ( source , operations ) {
412+ operations ;
413+ return source ; // TODO
414+ }
415+
393416// This function applies table cell operations to an in-memory table (array of
394- // objects); it should be equivalent to the corresponding SQL query.
417+ // objects); it should be equivalent to the corresponding SQL query. TODO This
418+ // is only exported for testing, but we should be testing the public __query
419+ // instead of this internal method.
395420export function __table ( source , operations ) {
396421 const input = source ;
397422 let { schema, columns} = source ;
0 commit comments