@@ -143,12 +143,31 @@ export abstract class ListVectorBase<T extends (ListType | FlatListType)> extend
143143export 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
154173import { List , Binary , Utf8 , Bool , } from './type' ;
0 commit comments