Skip to content

Commit d18d915

Browse files
committed
fix struct and map rows
1 parent 61dc699 commit d18d915

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

js/src/vector.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export abstract class ListVectorBase<T extends ListType> extends Vector<T> {
8080
public get values() { return this._data.values; }
8181
public get valueOffsets() { return this._data.valueOffsets; }
8282
public getValueOffset(index: number) {
83-
return this.data.valueOffsets[index];
83+
return this.valueOffsets[index];
8484
}
8585
public getValueLength(index: number) {
86-
return this.data.valueOffsets[index + 1] - this.data.valueOffsets[index];
86+
return this.valueOffsets[index + 1] - this.valueOffsets[index];
8787
}
8888
}
8989

js/src/vector/nested.ts

+29-28
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ import { View, Vector, createVector } from '../vector';
2121
import { DataType, NestedType, DenseUnion, SparseUnion, Struct, Map_ } from '../type';
2222

2323
export abstract class NestedView<T extends NestedType> implements View<T> {
24-
// @ts-ignore
25-
public typeIds: Int8Array;
26-
// @ts-ignore
27-
public valueOffsets: any;
2824
public readonly numChildren: number;
2925
public readonly childData: Data<any>[];
3026
protected children: { [k: number]: Vector<any> } = Object.create(null);
@@ -56,9 +52,15 @@ export abstract class NestedView<T extends NestedType> implements View<T> {
5652
}
5753

5854
export class UnionView<T extends (DenseUnion | SparseUnion) = SparseUnion> extends NestedView<T> {
55+
public length: number;
56+
// @ts-ignore
57+
public typeIds: Int8Array;
58+
// @ts-ignore
59+
public valueOffsets?: Int32Array;
5960
constructor(data: Data<T>) {
6061
super(data);
61-
this.typeIds = this.typeIds;
62+
this.length = data.length;
63+
this.typeIds = data.typeIds;
6264
}
6365
public getNested(view: NestedView<T>, index: number): T['TValue'] {
6466
return this.getUnionValue(view, index, this.typeIds, this.valueOffsets);
@@ -68,8 +70,8 @@ export class UnionView<T extends (DenseUnion | SparseUnion) = SparseUnion> exten
6870
return child ? child.get(index) : null;
6971
}
7072
public *[Symbol.iterator](): IterableIterator<T['TValue']> {
73+
const length = this.length;
7174
const get = this.getUnionValue;
72-
const length = this.data.length;
7375
const { typeIds, valueOffsets } = this;
7476
for (let index = -1; ++index < length;) {
7577
yield get(this, index, typeIds, valueOffsets);
@@ -78,6 +80,8 @@ export class UnionView<T extends (DenseUnion | SparseUnion) = SparseUnion> exten
7880
}
7981

8082
export class DenseUnionView extends UnionView<DenseUnion> {
83+
// @ts-ignore
84+
public valueOffsets: Int32Array;
8185
constructor(data: Data<DenseUnion>) {
8286
super(data);
8387
this.valueOffsets = data.valueOffsets;
@@ -91,41 +95,38 @@ export class DenseUnionView extends UnionView<DenseUnion> {
9195
}
9296
}
9397

94-
export abstract class TabularView<T extends NestedType> extends NestedView<T> {
95-
constructor(data: Data<T>) {
96-
super(data);
97-
this.typeIds = new Int8Array(data.childData.map((x) => x.typeId));
98-
this.valueOffsets = data.type.children.reduce((xs, x) =>
99-
(xs[x.name] = x.typeId) && xs || xs, Object.create(null));
98+
export class StructView extends NestedView<Struct> {
99+
public getNested(view: StructView, index: number) {
100+
return new RowView(view as any, index);
100101
}
101102
}
102103

103-
export class MapView extends TabularView<Map_> {
104+
export class MapView extends NestedView<Map_> {
105+
// @ts-ignore
106+
public typeIds: { [k: string]: number };
107+
constructor(data: Data<Map_>) {
108+
super(data);
109+
this.typeIds = data.type.children.reduce((xs, x, i) =>
110+
(xs[x.name] = i) && xs || xs, Object.create(null));
111+
}
104112
public getNested(view: MapView, index: number) {
105-
return new MapRow(view as any, index);
113+
return new MapRowView(view as any, index);
106114
}
107115
}
108116

109-
export class MapRow extends DenseUnionView {
110-
constructor(data: Data<DenseUnion>, protected rowIndex: number) {
117+
export class RowView extends UnionView<SparseUnion> {
118+
constructor(data: Data<SparseUnion> & NestedView<any>, protected rowIndex: number) {
111119
super(data);
120+
this.length = data.numChildren;
112121
}
113-
protected getUnionValue(view: NestedView<DenseUnion>, index: number, typeIds: Int8Array, valueOffsets: any): any | null {
114-
const child = view.getChildAt(typeIds[valueOffsets[index]]);
122+
protected getUnionValue(view: NestedView<SparseUnion>, index: number, _typeIds: any, _valueOffsets?: any): any | null {
123+
const child = view.getChildAt(index);
115124
return child ? child.get(this.rowIndex) : null;
116125
}
117126
}
118-
export class StructView extends TabularView<Struct> {
119-
public getNested(view: StructView, index: number) {
120-
return new StructRow(view as any, index);
121-
}
122-
}
123127

124-
export class StructRow extends UnionView<SparseUnion> {
125-
constructor(data: Data<SparseUnion>, protected rowIndex: number) {
126-
super(data);
127-
}
128-
protected getUnionValue(view: NestedView<SparseUnion>, index: number, typeIds: Int8Array, _valueOffsets?: any): any | null {
128+
export class MapRowView extends RowView {
129+
protected getUnionValue(view: NestedView<SparseUnion>, index: number, typeIds: any, _valueOffsets: any): any | null {
129130
const child = view.getChildAt(typeIds[index]);
130131
return child ? child.get(this.rowIndex) : null;
131132
}

0 commit comments

Comments
 (0)