1515// specific language governing permissions and limitations
1616// under the License.
1717
18- import { Vector } from './vector' ;
19- import { StructVector , StructRow } from './struct' ;
20- import { read , readAsync } from '../reader/arrow' ;
18+ import { Vector } from './vector/vector' ;
19+ import { read , readAsync } from './reader/arrow' ;
2120import { Predicate } from './predicate' ;
2221
2322export type NextFunc = ( idx : number , cols : Vector [ ] ) => void ;
2423
25- export class DataFrameRow extends StructRow < any > {
26- constructor ( batch : Vector [ ] , idx : number ) {
27- super ( new StructVector ( { columns : batch } ) , idx ) ;
24+ export class TableRow {
25+ constructor ( readonly batch : Vector [ ] , readonly idx : number ) { }
26+ toArray ( ) {
27+ return this . batch . map ( ( vec ) => vec . get ( this . idx ) ) ;
2828 }
2929 toString ( ) {
3030 return this . toArray ( ) . map ( ( x ) => JSON . stringify ( x ) ) . join ( ', ' ) ;
3131 }
32+ * [ Symbol . iterator ] ( ) {
33+ for ( const vec of this . batch ) {
34+ yield vec . get ( this . idx ) ;
35+ }
36+ }
3237}
3338
3439export interface DataFrame {
@@ -46,7 +51,7 @@ function columnsFromBatches(batches: Vector[][]) {
4651 ) ;
4752}
4853
49- export class Table extends StructVector < any > implements DataFrame {
54+ export class Table implements DataFrame {
5055 static from ( sources ?: Iterable < Uint8Array | Buffer | string > | object | string ) {
5156 let batches : Vector < any > [ ] [ ] = [ [ ] ] ;
5257 if ( sources ) {
@@ -73,20 +78,20 @@ export class Table extends StructVector<any> implements DataFrame {
7378 readonly lengths : Uint32Array ;
7479 readonly length : number ;
7580 constructor ( argv : { batches : Vector < any > [ ] [ ] } ) {
76- super ( { columns : columnsFromBatches ( argv . batches ) } ) ;
7781 this . batches = argv . batches ;
82+ this . columns = columnsFromBatches ( this . batches ) ;
7883 this . lengths = new Uint32Array ( this . batches . map ( ( batch ) => batch [ 0 ] . length ) ) ;
7984
8085 this . length = this . lengths . reduce ( ( acc , length ) => acc + length ) ;
8186 }
82- get ( idx : number ) : DataFrameRow {
87+ get ( idx : number ) : TableRow {
8388 let batch = 0 ;
8489 while ( idx > this . lengths [ batch ] && batch < this . lengths . length )
8590 idx -= this . lengths [ batch ++ ] ;
8691
8792 if ( batch === this . lengths . length ) throw new Error ( "Overflow" )
8893
89- else return new DataFrameRow ( this . batches [ batch ] , idx ) ;
94+ else return new TableRow ( this . batches [ batch ] , idx ) ;
9095 }
9196 filter ( predicate : Predicate ) : DataFrame {
9297 return new FilteredDataFrame ( this , predicate ) ;
@@ -116,7 +121,7 @@ export class Table extends StructVector<any> implements DataFrame {
116121
117122 // yield all indices
118123 for ( let idx = - 1 ; ++ idx < length ; ) {
119- yield new DataFrameRow ( columns , idx ) ;
124+ yield new TableRow ( columns , idx ) ;
120125 }
121126 }
122127 }
0 commit comments