Skip to content

Commit f1dead0

Browse files
committed
compute chunked nested childData list correctly
1 parent 18807c6 commit f1dead0

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

js/src/vector.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,31 @@ export abstract class ListVectorBase<T extends (ListType | FlatListType)> extend
143143
export abstract class NestedVector<T extends NestedType> extends Vector<T> {
144144
// @ts-ignore
145145
public readonly view: NestedView<T>;
146-
public get childData(): Data<any>[] {
147-
return this.data.childData;
148-
}
149-
public getChildAt<R extends DataType = DataType>(index: number) {
146+
// @ts-ignore
147+
protected _childData: Data<any>[];
148+
public getChildAt<R extends DataType = DataType>(index: number): Vector<R> | null {
150149
return this.view.getChildAt<R>(index);
151150
}
151+
public get childData(): Data<any>[] {
152+
let data: Data<T> | Data<any>[];
153+
if ((data = this._childData)) {
154+
// Return the cached childData reference first
155+
return data as Data<any>[];
156+
} else if (!(<any> (data = this.data) instanceof ChunkedData)) {
157+
// If data isn't chunked, cache and return NestedData's childData
158+
return this._childData = (data as NestedData<T>).childData;
159+
}
160+
// Otherwise if the data is chunked, concatenate the childVectors from each chunk
161+
// to construct a single chunked Vector for each column. Then return the ChunkedData
162+
// instance from each unified chunked column as the childData of a chunked NestedVector
163+
const chunks = ((data as ChunkedData<T>).chunkVectors as NestedVector<T>[]);
164+
return this._childData = chunks
165+
.reduce<(Vector<T> | null)[][]>((cols, chunk) => chunk.childData
166+
.reduce<(Vector<T> | null)[][]>((cols, _, i) => (
167+
(cols[i] || (cols[i] = [])).push(chunk.getChildAt(i))
168+
) && cols || cols, cols), [] as Vector<T>[][])
169+
.map((vecs) => Vector.concat<T>(...vecs).data);
170+
}
152171
}
153172

154173
import { List, Binary, Utf8, Bool, } from './type';

0 commit comments

Comments
 (0)