1
- import * as arrow from "apache-arrow " ;
1
+ import * as flech from "@uwdata/flechette " ;
2
2
// @ts -types="../deps/mosaic-core.d.ts"
3
3
import {
4
4
type Coordinator ,
@@ -24,12 +24,13 @@ import { StatusBar } from "./StatusBar.ts";
24
24
25
25
interface DataTableOptions {
26
26
table : string ;
27
- schema : arrow . Schema ;
27
+ schema : flech . Schema ;
28
28
height ?: number ;
29
29
}
30
30
31
31
// TODO: more
32
32
type ColumnSummaryClient = Histogram | ValueCounts ;
33
+ type TableRow = Record < string , unknown > ;
33
34
34
35
/**
35
36
* Create a DataTable client.
@@ -67,7 +68,7 @@ export async function datatable(
67
68
68
69
export class DataTable extends MosaicClient {
69
70
/** source of the data */
70
- #meta: { table : string ; schema : arrow . Schema } ;
71
+ #meta: { table : string ; schema : flech . Schema } ;
71
72
/** for the component */
72
73
#root: HTMLElement = document . createElement ( "div" ) ;
73
74
/** shadow root for the component */
@@ -97,8 +98,8 @@ export class DataTable extends MosaicClient {
97
98
/** the formatter for the data table entries */
98
99
#format: Record < string , ( value : unknown ) => string > ;
99
100
100
- /** @type {AsyncBatchReader<arrow .StructRowProxy> | null } */
101
- #reader: AsyncBatchReader < arrow . StructRowProxy > | null = null ;
101
+ /** @type {AsyncBatchReader<flech .StructRowProxy> | null } */
102
+ #reader: AsyncBatchReader < TableRow > | null = null ;
102
103
103
104
#sql = signal ( undefined as string | undefined ) ;
104
105
@@ -199,7 +200,7 @@ export class DataTable extends MosaicClient {
199
200
* A Mosiac lifecycle function called with arrow results from `query`.
200
201
* Must be synchronous, and return `this`.
201
202
*/
202
- queryResult ( table : arrow . Table ) : this {
203
+ queryResult ( table : flech . Table ) : this {
203
204
if ( ! this . #pendingInternalRequest) {
204
205
// data is not from an internal request, so reset table
205
206
this . #reader = new AsyncBatchReader ( ( ) => {
@@ -362,7 +363,7 @@ export class DataTable extends MosaicClient {
362
363
}
363
364
}
364
365
365
- #appendRow( d : arrow . StructRowProxy , i : number ) {
366
+ #appendRow( d : TableRow , i : number ) {
366
367
let itr = this . #templateRow?. cloneNode ( true ) ;
367
368
assert ( itr , "Must have a data row" ) ;
368
369
let td = itr . childNodes [ 0 ] as HTMLTableCellElement ;
@@ -389,7 +390,7 @@ const TRUNCATE = /** @type {const} */ ({
389
390
} ) ;
390
391
391
392
function thcol (
392
- field : arrow . Field ,
393
+ field : flech . Field ,
393
394
minWidth : number ,
394
395
vis ?: ColumnSummaryClient ,
395
396
) {
@@ -502,7 +503,7 @@ function thcol(
502
503
/**
503
504
* Return a formatter for each field in the schema
504
505
*/
505
- function formatof ( schema : arrow . Schema ) {
506
+ function formatof ( schema : flech . Schema ) {
506
507
const format : Record < string , ( value : unknown ) => string > = Object . create (
507
508
null ,
508
509
) ;
@@ -515,20 +516,20 @@ function formatof(schema: arrow.Schema) {
515
516
/**
516
517
* Return a class type of each field in the schema.
517
518
*/
518
- function classof ( schema : arrow . Schema ) : Record < string , "number" | "date" > {
519
+ function classof ( schema : flech . Schema ) : Record < string , "number" | "date" > {
519
520
const classes : Record < string , "number" | "date" > = Object . create ( null ) ;
520
521
for ( const field of schema . fields ) {
521
- if (
522
- arrow . DataType . isInt ( field . type ) ||
523
- arrow . DataType . isFloat ( field . type )
524
- ) {
525
- classes [ field . name ] = "number" ;
526
- }
527
- if (
528
- arrow . DataType . isDate ( field . type ) ||
529
- arrow . DataType . isTimestamp ( field . type )
530
- ) {
531
- classes [ field . name ] = "date" ;
522
+ switch ( field . type . typeId ) {
523
+ case flech . Type . Int :
524
+ case flech . Type . Float :
525
+ classes [ field . name ] = "number" ;
526
+ break ;
527
+ case flech . Type . Date :
528
+ case flech . Type . Timestamp :
529
+ classes [ field . name ] = "date" ;
530
+ break ;
531
+ default :
532
+ break ;
532
533
}
533
534
}
534
535
return classes ;
0 commit comments