@@ -90,13 +90,13 @@ export class BaseData<T extends DataType = DataType> implements VectorLike {
90
90
}
91
91
return nullCount ;
92
92
}
93
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
94
- return new BaseData < T > ( this . _type , length , offset , nullCount ) as this ;
93
+ public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
94
+ return new BaseData ( type , length , offset , nullCount ) ;
95
95
}
96
96
public slice ( offset : number , length : number ) {
97
97
return length <= 0 ? this : this . sliceInternal ( this . clone (
98
- length , this . _offset + offset , + ( this . _nullCount === 0 ) - 1
99
- ) , offset , length ) ;
98
+ this . _type , length , this . _offset + offset , + ( this . _nullCount === 0 ) - 1
99
+ ) as any , offset , length ) ;
100
100
}
101
101
protected sliceInternal ( clone : this, offset : number , length : number ) {
102
102
let arr : any ;
@@ -126,16 +126,13 @@ export class FlatData<T extends FlatType> extends BaseData<T> {
126
126
this [ VectorType . VALIDITY ] = toTypedArray ( Uint8Array , nullBitmap ) ;
127
127
}
128
128
public get ArrayType ( ) : T [ 'ArrayType' ] { return this . _type . ArrayType ; }
129
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
130
- return new FlatData < T > ( this . _type , length , this [ VectorType . VALIDITY ] , this [ VectorType . DATA ] , offset , nullCount ) as this ;
129
+ public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
130
+ return new ( this . constructor as any ) ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . DATA ] , offset , nullCount ) as FlatData < R > ;
131
131
}
132
132
}
133
133
134
134
export class BoolData extends FlatData < Bool > {
135
135
protected sliceData ( data : Uint8Array ) { return data ; }
136
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
137
- return new BoolData ( this . _type , length , this [ VectorType . VALIDITY ] , this [ VectorType . DATA ] , offset , nullCount ) as this;
138
- }
139
136
}
140
137
141
138
export class FlatListData < T extends FlatListType > extends FlatData < T > {
@@ -148,8 +145,8 @@ export class FlatListData<T extends FlatListType> extends FlatData<T> {
148
145
super ( type , length , nullBitmap , data , offset , nullCount ) ;
149
146
this [ VectorType . OFFSET ] = toTypedArray ( Int32Array , valueOffsets ) ;
150
147
}
151
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
152
- return new FlatListData < T > ( this . _type , length , this [ VectorType . VALIDITY ] , this [ VectorType . OFFSET ] , this [ VectorType . DATA ] , offset , nullCount ) as this ;
148
+ public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
149
+ return new FlatListData ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . OFFSET ] , this [ VectorType . DATA ] , offset , nullCount ) ;
153
150
}
154
151
}
155
152
@@ -165,8 +162,13 @@ export class DictionaryData<T extends DataType> extends BaseData<Dictionary<T>>
165
162
}
166
163
public get length ( ) { return this . _indicies . length ; }
167
164
public get nullCount ( ) { return this . _indicies . nullCount ; }
168
- public clone ( length = this . _length , offset = this . _offset ) {
169
- return new DictionaryData < T > ( this . _type , this . _dictionary , this . _indicies . slice ( offset - this . _offset , length ) ) as this;
165
+ public clone < R extends Dictionary < T > > ( type : R , length = this . _length , offset = this . _offset ) {
166
+ const data = this . _dictionary . data . clone ( type . dictionary as any ) ;
167
+ return new DictionaryData < R > (
168
+ this . _type as any ,
169
+ this . _dictionary . clone ( data ) as any ,
170
+ this . _indicies . slice ( offset - this . _offset , length )
171
+ ) as any ;
170
172
}
171
173
protected sliceInternal ( clone : this, _offset : number , _length : number ) {
172
174
clone . _length = clone . _indicies . length ;
@@ -182,8 +184,8 @@ export class NestedData<T extends NestedType = NestedType> extends BaseData<T> {
182
184
this . _childData = childData ;
183
185
this [ VectorType . VALIDITY ] = toTypedArray ( Uint8Array , nullBitmap ) ;
184
186
}
185
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
186
- return new NestedData < T > ( this . _type , length , this [ VectorType . VALIDITY ] , this . _childData , offset , nullCount ) as this ;
187
+ public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
188
+ return new NestedData < R > ( type , length , this [ VectorType . VALIDITY ] , this . _childData , offset , nullCount ) ;
187
189
}
188
190
protected sliceInternal ( clone : this, offset : number , length : number ) {
189
191
if ( ! this [ VectorType . OFFSET ] ) {
@@ -204,8 +206,8 @@ export class ListData<T extends ListType> extends NestedData<T> {
204
206
this . _valuesData = valueChildData ;
205
207
this [ VectorType . OFFSET ] = toTypedArray ( Int32Array , valueOffsets ) ;
206
208
}
207
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
208
- return new ListData < T > ( this . _type , length , this [ VectorType . VALIDITY ] , this [ VectorType . OFFSET ] , this . _valuesData , offset , nullCount ) as this ;
209
+ public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
210
+ return new ListData < R > ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . OFFSET ] , this . _valuesData as any , offset , nullCount ) ;
209
211
}
210
212
}
211
213
@@ -216,17 +218,24 @@ export class UnionData<T extends (DenseUnion | SparseUnion) = any> extends Neste
216
218
super ( type , length , nullBitmap , childData , offset , nullCount ) ;
217
219
this [ VectorType . TYPE ] = toTypedArray ( Int8Array , typeIds ) ;
218
220
}
219
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
220
- return new UnionData < T > ( this . _type , length , this [ VectorType . VALIDITY ] , this [ VectorType . TYPE ] , this . _childData , offset , nullCount ) as this ;
221
+ public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
222
+ return new UnionData < R > ( type , length , this [ VectorType . VALIDITY ] , this [ VectorType . TYPE ] , this . _childData , offset , nullCount ) ;
221
223
}
222
224
}
223
225
224
226
export class SparseUnionData extends UnionData < SparseUnion > {
225
227
constructor ( type : SparseUnion , length : number , nullBitmap : Uint8Array | null | undefined , typeIds : Iterable < number > , childData : Data < any > [ ] , offset ?: number , nullCount ?: number ) {
226
228
super ( type , length , nullBitmap , typeIds , childData , offset , nullCount ) ;
227
229
}
228
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
229
- return new SparseUnionData ( this . _type , length , this [ VectorType . VALIDITY ] , this [ VectorType . TYPE ] , this . _childData , offset , nullCount ) as this;
230
+ public clone < R extends SparseUnion > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
231
+ return new SparseUnionData (
232
+ type ,
233
+ length ,
234
+ this [ VectorType . VALIDITY ] ,
235
+ this [ VectorType . TYPE ] ,
236
+ this . _childData ,
237
+ offset , nullCount
238
+ ) as any as UnionData < R > ;
230
239
}
231
240
}
232
241
@@ -237,8 +246,16 @@ export class DenseUnionData extends UnionData<DenseUnion> {
237
246
super ( type , length , nullBitmap , typeIds , childData , offset , nullCount ) ;
238
247
this [ VectorType . OFFSET ] = toTypedArray ( Int32Array , valueOffsets ) ;
239
248
}
240
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
241
- return new DenseUnionData ( this . _type , length , this [ VectorType . VALIDITY ] , this [ VectorType . TYPE ] , this [ VectorType . OFFSET ] , this . _childData , offset , nullCount ) as this;
249
+ public clone < R extends DenseUnion > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
250
+ return new DenseUnionData (
251
+ type ,
252
+ length ,
253
+ this [ VectorType . VALIDITY ] ,
254
+ this [ VectorType . TYPE ] ,
255
+ this [ VectorType . OFFSET ] ,
256
+ this . _childData ,
257
+ offset , nullCount
258
+ ) as any as UnionData < R > ;
242
259
}
243
260
}
244
261
@@ -263,8 +280,12 @@ export class ChunkedData<T extends DataType> extends BaseData<T> {
263
280
}
264
281
return nullCount ;
265
282
}
266
- public clone ( length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
267
- return new ChunkedData < T > ( this . _type , length , this . _childVectors , offset , nullCount , this . _childOffsets ) as this;
283
+ public clone < R extends T > ( type : R , length = this . _length , offset = this . _offset , nullCount = this . _nullCount ) {
284
+ return new ChunkedData < R > (
285
+ type , length ,
286
+ this . _childVectors . map ( ( vec ) => vec . clone ( vec . data . clone ( type ) ) ) as any ,
287
+ offset , nullCount , this . _childOffsets
288
+ ) ;
268
289
}
269
290
protected sliceInternal ( clone : this, offset : number , length : number ) {
270
291
const chunks = this . _childVectors ;
0 commit comments