@@ -23,6 +23,16 @@ export function isDatabaseClient(value, mode) {
2323 ) ;
2424}
2525
26+ // Returns true if the vaue is an Apache Arrow table.
27+ export function isArrowTable ( value ) {
28+ return (
29+ value &&
30+ value . schema &&
31+ Array . isArray ( value . schema . fields ) &&
32+ typeof value [ Symbol . iterator ] === "function"
33+ ) ;
34+ }
35+
2636// Returns true if the value is a typed array (for a single-column table), or if
2737// it’s an array. In the latter case, the elements of the array must be
2838// consistently typed: either plain objects or primitives or dates.
@@ -145,6 +155,7 @@ export const __query = Object.assign(
145155 source = await loadDataSource ( await source , "table" ) ;
146156 if ( isDatabaseClient ( source ) ) return evaluateQuery ( source , makeQueryTemplate ( operations , source ) , invalidation ) ;
147157 if ( isDataArray ( source ) ) return __table ( source , operations ) ;
158+ if ( isArrowTable ( source ) ) return __arrow ( source , operations ) ;
148159 if ( ! source ) throw new Error ( "missing data source" ) ;
149160 throw new Error ( "invalid data source" ) ;
150161 } ,
@@ -164,6 +175,7 @@ export async function loadDataSource(source, mode) {
164175 case "text/csv" : return source . csv ( { typed : true } ) ;
165176 case "text/tab-separated-values" : return source . tsv ( { typed : true } ) ;
166177 case "application/json" : return source . json ( ) ;
178+ default : if ( / \. a r r o w $ / i. test ( source . name ) ) return source . arrow ( { version : 10 } ) ;
167179 }
168180 }
169181 if ( mode === "table" || mode === "sql" ) {
@@ -390,8 +402,17 @@ function likeOperand(operand) {
390402 return { ...operand , value : `%${ operand . value } %` } ;
391403}
392404
405+ // This function applies table cell operations to an in-memory Apache Arrow
406+ // table; it should be equivalent to the corresponding SQL query.
407+ function __arrow ( source , operations ) {
408+ operations ;
409+ return source ; // TODO
410+ }
411+
393412// This function applies table cell operations to an in-memory table (array of
394- // objects); it should be equivalent to the corresponding SQL query.
413+ // objects); it should be equivalent to the corresponding SQL query. TODO This
414+ // is only exported for testing, but we should be testing the public __query
415+ // instead of this internal method.
395416export function __table ( source , operations ) {
396417 const input = source ;
397418 let { schema, columns} = source ;
0 commit comments