Skip to content

Commit 18807c6

Browse files
committed
rename ChunkData's fields so it's more clear they're not semantically similar to other similarly named fields
1 parent 7e43b78 commit 18807c6

File tree

3 files changed

+71
-71
lines changed

3 files changed

+71
-71
lines changed

js/src/data.ts

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -60,42 +60,38 @@ export type kUnknownNullCount = -1;
6060
export const kUnknownNullCount = -1;
6161

6262
export class BaseData<T extends DataType = DataType> implements VectorLike {
63-
protected _type: T;
64-
protected _length: number;
65-
protected _offset: number;
63+
public type: T;
64+
public length: number;
65+
public offset: number;
6666
// @ts-ignore
67-
protected _childData: Data<any>[];
67+
public childData: Data<any>[];
6868
protected _nullCount: number | kUnknownNullCount;
6969
protected /* [VectorType.OFFSET]:*/ 0?: Int32Array;
7070
protected /* [VectorType.DATA]:*/ 1?: T['TArray'];
7171
protected /*[VectorType.VALIDITY]:*/ 2?: Uint8Array;
7272
protected /* [VectorType.TYPE]:*/ 3?: Int8Array;
7373
constructor(type: T, length: number, offset?: number, nullCount?: number) {
74-
this._type = type;
75-
this._length = Math.floor(Math.max(length || 0, 0));
76-
this._offset = Math.floor(Math.max(offset || 0, 0));
74+
this.type = type;
75+
this.length = Math.floor(Math.max(length || 0, 0));
76+
this.offset = Math.floor(Math.max(offset || 0, 0));
7777
this._nullCount = Math.floor(Math.max(nullCount || 0, -1));
7878
}
79-
public get type() { return this._type; }
80-
public get length() { return this._length; }
81-
public get offset() { return this._offset; }
82-
public get typeId() { return this._type.TType; }
83-
public get childData() { return this._childData; }
79+
public get typeId() { return this.type.TType; }
8480
public get nullBitmap() { return this[VectorType.VALIDITY]; }
8581
public get nullCount() {
8682
let nullCount = this._nullCount;
8783
let nullBitmap: Uint8Array | undefined;
8884
if (nullCount === -1 && (nullBitmap = this[VectorType.VALIDITY])) {
89-
this._nullCount = nullCount = this._length - popcnt_bit_range(nullBitmap, this._offset, this._offset + this._length);
85+
this._nullCount = nullCount = this.length - popcnt_bit_range(nullBitmap, this.offset, this.offset + this.length);
9086
}
9187
return nullCount;
9288
}
93-
public clone<R extends T>(type: R, length = this._length, offset = this._offset, nullCount = this._nullCount) {
89+
public clone<R extends T>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
9490
return new BaseData(type, length, offset, nullCount);
9591
}
9692
public slice(offset: number, length: number) {
9793
return length <= 0 ? this : this.sliceInternal(this.clone(
98-
this._type, length, this._offset + offset, +(this._nullCount === 0) - 1
94+
this.type, length, this.offset + offset, +(this._nullCount === 0) - 1
9995
) as any, offset, length);
10096
}
10197
protected sliceInternal(clone: this, offset: number, length: number) {
@@ -125,8 +121,8 @@ export class FlatData<T extends FlatType> extends BaseData<T> {
125121
this[VectorType.DATA] = toTypedArray(this.ArrayType, data);
126122
this[VectorType.VALIDITY] = toTypedArray(Uint8Array, nullBitmap);
127123
}
128-
public get ArrayType(): T['ArrayType'] { return this._type.ArrayType; }
129-
public clone<R extends T>(type: R, length = this._length, offset = this._offset, nullCount = this._nullCount) {
124+
public get ArrayType(): T['ArrayType'] { return this.type.ArrayType; }
125+
public clone<R extends T>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
130126
return new (this.constructor as any)(type, length, this[VectorType.VALIDITY], this[VectorType.DATA], offset, nullCount) as FlatData<R>;
131127
}
132128
}
@@ -145,7 +141,7 @@ export class FlatListData<T extends FlatListType> extends FlatData<T> {
145141
super(type, length, nullBitmap, data, offset, nullCount);
146142
this[VectorType.OFFSET] = toTypedArray(Int32Array, valueOffsets);
147143
}
148-
public clone<R extends T>(type: R, length = this._length, offset = this._offset, nullCount = this._nullCount) {
144+
public clone<R extends T>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
149145
return new FlatListData(type, length, this[VectorType.VALIDITY], this[VectorType.OFFSET], this[VectorType.DATA], offset, nullCount);
150146
}
151147
}
@@ -159,19 +155,19 @@ export class DictionaryData<T extends DataType> extends BaseData<Dictionary<T>>
159155
super(type, indicies.length, (indicies as any)._nullCount);
160156
this._indicies = indicies;
161157
this._dictionary = dictionary;
158+
this.length = this._indicies.length;
162159
}
163-
public get length() { return this._indicies.length; }
164160
public get nullCount() { return this._indicies.nullCount; }
165-
public clone<R extends Dictionary<T>>(type: R, length = this._length, offset = this._offset) {
161+
public clone<R extends Dictionary<T>>(type: R, length = this.length, offset = this.offset) {
166162
const data = this._dictionary.data.clone(type.dictionary as any);
167163
return new DictionaryData<R>(
168-
this._type as any,
164+
this.type as any,
169165
this._dictionary.clone(data) as any,
170-
this._indicies.slice(offset - this._offset, length)
166+
this._indicies.slice(offset - this.offset, length)
171167
) as any;
172168
}
173169
protected sliceInternal(clone: this, _offset: number, _length: number) {
174-
clone._length = clone._indicies.length;
170+
clone.length = clone._indicies.length;
175171
clone._nullCount = (clone._indicies as any)._nullCount;
176172
return clone;
177173
}
@@ -181,15 +177,15 @@ export class NestedData<T extends NestedType = NestedType> extends BaseData<T> {
181177
public /*[VectorType.VALIDITY]:*/ 2: Uint8Array;
182178
constructor(type: T, length: number, nullBitmap: Uint8Array | null | undefined, childData: Data<any>[], offset?: number, nullCount?: number) {
183179
super(type, length, offset, nullCount);
184-
this._childData = childData;
180+
this.childData = childData;
185181
this[VectorType.VALIDITY] = toTypedArray(Uint8Array, nullBitmap);
186182
}
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);
183+
public clone<R extends T>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
184+
return new NestedData<R>(type, length, this[VectorType.VALIDITY], this.childData, offset, nullCount);
189185
}
190186
protected sliceInternal(clone: this, offset: number, length: number) {
191187
if (!this[VectorType.OFFSET]) {
192-
clone._childData = this._childData.map((child) => child.slice(offset, length));
188+
clone.childData = this.childData.map((child) => child.slice(offset, length));
193189
}
194190
return super.sliceInternal(clone, offset, length);
195191
}
@@ -212,7 +208,7 @@ export class ListData<T extends ListType> extends SingleNestedData<T> {
212208
super(type, length, nullBitmap, valueChildData, offset, nullCount);
213209
this[VectorType.OFFSET] = toTypedArray(Int32Array, valueOffsets);
214210
}
215-
public clone<R extends T>(type: R, length = this._length, offset = this._offset, nullCount = this._nullCount) {
211+
public clone<R extends T>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
216212
return new ListData<R>(type, length, this[VectorType.VALIDITY], this[VectorType.OFFSET], this._valuesData as any, offset, nullCount);
217213
}
218214
}
@@ -224,22 +220,22 @@ export class UnionData<T extends (DenseUnion | SparseUnion) = any> extends Neste
224220
super(type, length, nullBitmap, childData, offset, nullCount);
225221
this[VectorType.TYPE] = toTypedArray(Int8Array, typeIds);
226222
}
227-
public clone<R extends T>(type: R, length = this._length, offset = this._offset, nullCount = this._nullCount) {
228-
return new UnionData<R>(type, length, this[VectorType.VALIDITY], this[VectorType.TYPE], this._childData, offset, nullCount);
223+
public clone<R extends T>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
224+
return new UnionData<R>(type, length, this[VectorType.VALIDITY], this[VectorType.TYPE], this.childData, offset, nullCount);
229225
}
230226
}
231227

232228
export class SparseUnionData extends UnionData<SparseUnion> {
233229
constructor(type: SparseUnion, length: number, nullBitmap: Uint8Array | null | undefined, typeIds: Iterable<number>, childData: Data<any>[], offset?: number, nullCount?: number) {
234230
super(type, length, nullBitmap, typeIds, childData, offset, nullCount);
235231
}
236-
public clone<R extends SparseUnion>(type: R, length = this._length, offset = this._offset, nullCount = this._nullCount) {
232+
public clone<R extends SparseUnion>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
237233
return new SparseUnionData(
238234
type,
239235
length,
240236
this[VectorType.VALIDITY],
241237
this[VectorType.TYPE],
242-
this._childData,
238+
this.childData,
243239
offset, nullCount
244240
) as any as UnionData<R>;
245241
}
@@ -252,50 +248,52 @@ export class DenseUnionData extends UnionData<DenseUnion> {
252248
super(type, length, nullBitmap, typeIds, childData, offset, nullCount);
253249
this[VectorType.OFFSET] = toTypedArray(Int32Array, valueOffsets);
254250
}
255-
public clone<R extends DenseUnion>(type: R, length = this._length, offset = this._offset, nullCount = this._nullCount) {
251+
public clone<R extends DenseUnion>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
256252
return new DenseUnionData(
257253
type,
258254
length,
259255
this[VectorType.VALIDITY],
260256
this[VectorType.TYPE],
261257
this[VectorType.OFFSET],
262-
this._childData,
258+
this.childData,
263259
offset, nullCount
264260
) as any as UnionData<R>;
265261
}
266262
}
267263

268264
export class ChunkedData<T extends DataType> extends BaseData<T> {
269-
protected _childVectors: Vector<T>[];
270-
protected _childOffsets: Uint32Array;
271-
public get childVectors() { return this._childVectors; }
272-
public get childOffsets() { return this._childOffsets; }
273-
public get childData() {
274-
return this._childData || (
275-
this._childData = this._childVectors.map(({ data }) => data));
276-
}
277-
constructor(type: T, length: number, childVectors: Vector<T>[], offset?: number, nullCount?: number, childOffsets?: Uint32Array) {
265+
// @ts-ignore
266+
protected _chunkData: Data<T>[];
267+
protected _chunkVectors: Vector<T>[];
268+
protected _chunkOffsets: Uint32Array;
269+
public get chunkVectors() { return this._chunkVectors; }
270+
public get chunkOffsets() { return this._chunkOffsets; }
271+
public get chunkData() {
272+
return this._chunkData || (
273+
this._chunkData = this._chunkVectors.map(({ data }) => data));
274+
}
275+
constructor(type: T, length: number, chunkVectors: Vector<T>[], offset?: number, nullCount?: number, chunkOffsets?: Uint32Array) {
278276
super(type, length, offset, nullCount);
279-
this._childVectors = childVectors;
280-
this._childOffsets = childOffsets || ChunkedData.computeOffsets(childVectors);
277+
this._chunkVectors = chunkVectors;
278+
this._chunkOffsets = chunkOffsets || ChunkedData.computeOffsets(chunkVectors);
281279
}
282280
public get nullCount() {
283281
let nullCount = this._nullCount;
284282
if (nullCount === -1) {
285-
this._nullCount = nullCount = this._childVectors.reduce((x, c) => x + c.nullCount, 0);
283+
this._nullCount = nullCount = this._chunkVectors.reduce((x, c) => x + c.nullCount, 0);
286284
}
287285
return nullCount;
288286
}
289-
public clone<R extends T>(type: R, length = this._length, offset = this._offset, nullCount = this._nullCount) {
287+
public clone<R extends T>(type: R, length = this.length, offset = this.offset, nullCount = this._nullCount) {
290288
return new ChunkedData<R>(
291289
type, length,
292-
this._childVectors.map((vec) => vec.clone(vec.data.clone(type))) as any,
293-
offset, nullCount, this._childOffsets
290+
this._chunkVectors.map((vec) => vec.clone(vec.data.clone(type))) as any,
291+
offset, nullCount, this._chunkOffsets
294292
);
295293
}
296294
protected sliceInternal(clone: this, offset: number, length: number) {
297-
const chunks = this._childVectors;
298-
const offsets = this._childOffsets;
295+
const chunks = this._chunkVectors;
296+
const offsets = this._chunkOffsets;
299297
const chunkSlices: Vector<T>[] = [];
300298
for (let childIndex = -1, numChildren = chunks.length; ++childIndex < numChildren;) {
301299
const child = chunks[childIndex];
@@ -315,8 +313,8 @@ export class ChunkedData<T extends DataType> extends BaseData<T> {
315313
const end = begin + Math.min(childLength - begin, (offset + length) - childOffset);
316314
chunkSlices.push(child.slice(begin, end));
317315
}
318-
clone._childVectors = chunkSlices;
319-
clone._childOffsets = ChunkedData.computeOffsets(chunkSlices);
316+
clone._chunkVectors = chunkSlices;
317+
clone._chunkOffsets = ChunkedData.computeOffsets(chunkSlices);
320318
return clone;
321319
}
322320
static computeOffsets<T extends DataType>(childVectors: Vector<T>[]) {

js/src/vector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class Vector<T extends DataType = any> implements VectorLike, View<T>, Vi
8787
const { view } = this;
8888
const vecs = !(view instanceof ChunkedView)
8989
? [this, ...others]
90-
: [...view.childVectors, ...others];
90+
: [...view.chunkVectors, ...others];
9191
const offsets = ChunkedData.computeOffsets(vecs);
9292
const chunksLength = offsets[offsets.length - 1];
9393
const chunkedData = new ChunkedData(this.type, chunksLength, vecs, 0, -1, offsets);
@@ -380,7 +380,7 @@ export class DictionaryVector<T extends DataType = DataType> extends Vector<Dict
380380
this.indicies = view.indicies;
381381
this.dictionary = data.dictionary;
382382
} else if (data instanceof ChunkedData && view instanceof ChunkedView) {
383-
const chunks = view.childVectors as DictionaryVector<T>[];
383+
const chunks = view.chunkVectors as DictionaryVector<T>[];
384384
// Assume the last chunk's dictionary data is the most up-to-date,
385385
// including data from DictionaryBatches that were marked as deltas
386386
this.dictionary = chunks[chunks.length - 1].dictionary;

js/src/vector/chunked.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,35 @@ import { View, Vector, NestedVector } from '../vector';
2020
import { DataType, TypedArray, IterableArrayLike } from '../type';
2121

2222
export class ChunkedView<T extends DataType> implements View<T> {
23-
public childVectors: Vector<T>[];
24-
public childOffsets: Uint32Array;
25-
protected _childColumns: Vector<any>[];
23+
public chunkVectors: Vector<T>[];
24+
public chunkOffsets: Uint32Array;
25+
protected _children: Vector<any>[];
2626
constructor(data: ChunkedData<T>) {
27-
this.childVectors = data.childVectors;
28-
this.childOffsets = data.childOffsets;
27+
this.chunkVectors = data.chunkVectors;
28+
this.chunkOffsets = data.chunkOffsets;
2929
}
3030
public clone(data: ChunkedData<T>): this {
3131
return new ChunkedView(data) as this;
3232
}
3333
public *[Symbol.iterator](): IterableIterator<T['TValue'] | null> {
34-
for (const vector of this.childVectors) {
34+
for (const vector of this.chunkVectors) {
3535
yield* vector;
3636
}
3737
}
3838
public getChildAt<R extends DataType = DataType>(index: number) {
39-
return (this._childColumns || (this._childColumns = []))[index] || (
40-
this._childColumns[index] = Vector.concat<R>(
41-
...(<any> this.childVectors as NestedVector<any>[]).map((v) => v.getChildAt(index))));
39+
return index < 0 ? null
40+
: (this._children || (this._children = []))[index] ||
41+
(this._children[index] = Vector.concat<R>(
42+
...(<any> this.chunkVectors as NestedVector<any>[])
43+
.map((chunk) => chunk.getChildAt<R>(index))));
4244
}
4345
public isValid(index: number): boolean {
4446
// binary search to find the child vector and value index offset (inlined for speed)
45-
let offsets = this.childOffsets, pos = 0;
47+
let offsets = this.chunkOffsets, pos = 0;
4648
let lhs = 0, mid = 0, rhs = offsets.length - 1;
4749
while (index < offsets[rhs] && index >= (pos = offsets[lhs])) {
4850
if (lhs + 1 === rhs) {
49-
return this.childVectors[lhs].isValid(index - pos);
51+
return this.chunkVectors[lhs].isValid(index - pos);
5052
}
5153
mid = lhs + ((rhs - lhs) / 2) | 0;
5254
index >= offsets[mid] ? (lhs = mid) : (rhs = mid);
@@ -55,11 +57,11 @@ export class ChunkedView<T extends DataType> implements View<T> {
5557
}
5658
public get(index: number): T['TValue'] | null {
5759
// binary search to find the child vector and value index offset (inlined for speed)
58-
let offsets = this.childOffsets, pos = 0;
60+
let offsets = this.chunkOffsets, pos = 0;
5961
let lhs = 0, mid = 0, rhs = offsets.length - 1;
6062
while (index < offsets[rhs] && index >= (pos = offsets[lhs])) {
6163
if (lhs + 1 === rhs) {
62-
return this.childVectors[lhs].get(index - pos);
64+
return this.chunkVectors[lhs].get(index - pos);
6365
}
6466
mid = lhs + ((rhs - lhs) / 2) | 0;
6567
index >= offsets[mid] ? (lhs = mid) : (rhs = mid);
@@ -68,18 +70,18 @@ export class ChunkedView<T extends DataType> implements View<T> {
6870
}
6971
public set(index: number, value: T['TValue'] | null): void {
7072
// binary search to find the child vector and value index offset (inlined for speed)
71-
let offsets = this.childOffsets, pos = 0;
73+
let offsets = this.chunkOffsets, pos = 0;
7274
let lhs = 0, mid = 0, rhs = offsets.length - 1;
7375
while (index < offsets[rhs] && index >= (pos = offsets[lhs])) {
7476
if (lhs + 1 === rhs) {
75-
return this.childVectors[lhs].set(index - pos, value);
77+
return this.chunkVectors[lhs].set(index - pos, value);
7678
}
7779
mid = lhs + ((rhs - lhs) / 2) | 0;
7880
index >= offsets[mid] ? (lhs = mid) : (rhs = mid);
7981
}
8082
}
8183
public toArray(): IterableArrayLike<T['TValue'] | null> {
82-
const chunks = this.childVectors;
84+
const chunks = this.chunkVectors;
8385
const numChunks = chunks.length;
8486
if (numChunks === 1) {
8587
return chunks[0].toArray();

0 commit comments

Comments
 (0)