From f1dead0a243d2fe41f8e06fa04f39db3cfaa4540 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Wed, 24 Jan 2018 20:43:23 -0800 Subject: [PATCH] compute chunked nested childData list correctly --- js/src/vector.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/js/src/vector.ts b/js/src/vector.ts index 4190c64c59fe4..34d1fb0023b4f 100644 --- a/js/src/vector.ts +++ b/js/src/vector.ts @@ -143,12 +143,31 @@ export abstract class ListVectorBase extend export abstract class NestedVector extends Vector { // @ts-ignore public readonly view: NestedView; - public get childData(): Data[] { - return this.data.childData; - } - public getChildAt(index: number) { + // @ts-ignore + protected _childData: Data[]; + public getChildAt(index: number): Vector | null { return this.view.getChildAt(index); } + public get childData(): Data[] { + let data: Data | Data[]; + if ((data = this._childData)) { + // Return the cached childData reference first + return data as Data[]; + } else if (!( (data = this.data) instanceof ChunkedData)) { + // If data isn't chunked, cache and return NestedData's childData + return this._childData = (data as NestedData).childData; + } + // Otherwise if the data is chunked, concatenate the childVectors from each chunk + // to construct a single chunked Vector for each column. Then return the ChunkedData + // instance from each unified chunked column as the childData of a chunked NestedVector + const chunks = ((data as ChunkedData).chunkVectors as NestedVector[]); + return this._childData = chunks + .reduce<(Vector | null)[][]>((cols, chunk) => chunk.childData + .reduce<(Vector | null)[][]>((cols, _, i) => ( + (cols[i] || (cols[i] = [])).push(chunk.getChildAt(i)) + ) && cols || cols, cols), [] as Vector[][]) + .map((vecs) => Vector.concat(...vecs).data); + } } import { List, Binary, Utf8, Bool, } from './type';