@@ -8,12 +8,15 @@ import {
88 vectorFromArray ,
99 Vector ,
1010 Float ,
11+ tableFromArrays ,
12+ Utf8 ,
1113} from 'apache-arrow' ;
1214import { Deeptable } from './Deeptable' ;
1315import { add_or_delete_column } from './Deeptable' ;
1416import type * as DS from './types' ;
15- import { extent } from 'd3-array' ;
17+ import { extent , extent , range } from 'd3-array' ;
1618import { Rectangle } from './tile' ;
19+ import { tixToZxy } from './tixrixqid' ;
1720
1821/**
1922 * This function is used to wrap an arrow table into a
@@ -31,22 +34,36 @@ export function wrapArrowTable(
3134) : Deeptable {
3235 let tb = tableFromIPC ( tbArray ) ;
3336 let batches = tb . batches ;
37+ const minIx = [ ]
38+ const maxIx = [ ]
39+ // Extents of each tile, as JSON.
40+ const extents : string [ ] = [ ]
3441 if ( tb . getChild ( 'ix' ) === null ) {
3542 let rowNum = 0 ;
3643 batches = batches . map ( ( batch ) => {
3744 if ( batch . numRows > 2 ** 16 ) {
3845 throw new Error (
39- 'Arrow record batches temporarily limited to 2^16 rows.' ,
46+ 'Arrow record batches limited to 2^16 rows.' ,
4047 ) ;
4148 }
4249 const array = new Int32Array ( batch . numRows ) ;
4350 for ( let i = 0 ; i < batch . numRows ; i ++ ) {
4451 array [ i ] = rowNum ++ ;
4552 }
46- return add_or_delete_column ( batch , 'ix' , vectorFromArray ( array ) ) ;
53+ return add_or_delete_column ( batch , 'ix' , vectorFromArray ( array ) ) ;
4754 } ) ;
4855 tb = new Table ( batches ) ;
4956 }
57+ for ( const batch of batches ) {
58+ minIx . push ( batch . get ( 0 ) [ 'ix' ] )
59+ maxIx . push ( batch . get ( batch . numRows - 1 ) [ 'ix' ] )
60+ extents . push (
61+ JSON . stringify ( {
62+ x : extent ( batch . getChild ( 'x' ) ) ,
63+ y : extent ( batch . getChild ( 'y' ) )
64+ } )
65+ )
66+ }
5067
5168 const proxy = new ArrowProxy ( batches ) ;
5269
@@ -65,12 +82,25 @@ export function wrapArrowTable(
6582 y : extent ( [ ...( y as Iterable < number > ) ] ) ,
6683 } as Rectangle ;
6784
85+
86+ const tileManifest = tableFromArrays ( {
87+ // @ts -expect-error missing types for tableFromArrays in arrow js
88+ key : vectorFromArray ( range ( batches . length ) . map ( t => tixToZxy ( t ) . join ( '/' ) ) , new Utf8 ( ) ) ,
89+ min_ix : minIx ,
90+ max_ix : maxIx ,
91+ nPoints : batches . map ( d => d . numRows ) ,
92+ // @ts -expect-error missing types for tableFromArrays in arrow js
93+ extent : vectorFromArray ( extents , new Utf8 ( ) )
94+ } )
95+
6896 return new Deeptable ( {
6997 baseUrl : `feather://table` ,
7098 plot,
7199 tileProxy : proxy ,
72100 tileStructure : 'other' ,
73101 extent : dataExtent ,
102+ // @ts -expect-error missing types for tableFromArrays in arrow js
103+ tileManifest
74104 } ) ;
75105}
76106
0 commit comments