Skip to content

Commit fe31ee0

Browse files
committed
slice the flat data values before returning an iterator of them
1 parent e537789 commit fe31ee0

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

js/src/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class BaseData<T extends DataType = DataType> implements VectorLike {
8686
let nullCount = this._nullCount;
8787
let nullBitmap: Uint8Array | undefined;
8888
if (nullCount === -1 && (nullBitmap = this[VectorType.VALIDITY])) {
89-
this._nullCount = nullCount = popcnt_bit_range(nullBitmap, this._offset, this._offset + this._length);
89+
this._nullCount = nullCount = this._length - popcnt_bit_range(nullBitmap, this._offset, this._offset + this._length);
9090
}
9191
return nullCount;
9292
}

js/src/type.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ export abstract class DataType<TType extends Type = any> implements Partial<Visi
201201

202202
export interface Null extends DataType<Type.Null> { TArray: void; TValue: null; }
203203
export class Null extends DataType<Type.Null> {
204-
constructor() { super(Type.Null); }
204+
constructor() {
205+
super(Type.Null);
206+
}
205207
public toString() { return `Null`; }
206208
public acceptTypeVisitor(visitor: TypeVisitor): any {
207209
return visitor.visitNull(this);
@@ -269,7 +271,9 @@ export class Float64 extends Float<Float64Array> { constructor() { super(Precisi
269271

270272
export interface Binary extends DataType<Type.Binary> { TArray: Uint8Array; TValue: Uint8Array; }
271273
export class Binary extends DataType<Type.Binary> {
272-
constructor() { super(Type.Binary); }
274+
constructor() {
275+
super(Type.Binary);
276+
}
273277
public toString() { return `Binary`; }
274278
public acceptTypeVisitor(visitor: TypeVisitor): any {
275279
return visitor.visitBinary(this);
@@ -282,7 +286,9 @@ export class Binary extends DataType<Type.Binary> {
282286

283287
export interface Utf8 extends DataType<Type.Utf8> { TArray: Uint8Array; TValue: string; }
284288
export class Utf8 extends DataType<Type.Utf8> {
285-
constructor() { super(Type.Utf8); }
289+
constructor() {
290+
super(Type.Utf8);
291+
}
286292
public toString() { return `Utf8`; }
287293
public acceptTypeVisitor(visitor: TypeVisitor): any {
288294
return visitor.visitUtf8(this);
@@ -295,7 +301,9 @@ export class Utf8 extends DataType<Type.Utf8> {
295301

296302
export interface Bool extends DataType<Type.Bool> { TArray: Uint8Array; TValue: boolean; }
297303
export class Bool extends DataType<Type.Bool> {
298-
constructor() { super(Type.Bool); }
304+
constructor() {
305+
super(Type.Bool);
306+
}
299307
public toString() { return `Bool`; }
300308
public acceptTypeVisitor(visitor: TypeVisitor): any {
301309
return visitor.visitBool(this);
@@ -325,7 +333,9 @@ export class Decimal extends DataType<Type.Decimal> {
325333
/* tslint:disable:class-name */
326334
export interface Date_ extends DataType<Type.Date> { TArray: Int32Array; TValue: Date; }
327335
export class Date_ extends DataType<Type.Date> {
328-
constructor(public readonly unit: DateUnit) { super(Type.Date); }
336+
constructor(public readonly unit: DateUnit) {
337+
super(Type.Date);
338+
}
329339
public toString() { return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`; }
330340
public acceptTypeVisitor(visitor: TypeVisitor): any {
331341
return visitor.visitDate(this);
@@ -485,7 +495,7 @@ export class Map_ extends DataType<Type.Map> {
485495
public toString() { return `Map<${this.children.join(`, `)}>`; }
486496
public acceptTypeVisitor(visitor: TypeVisitor): any { return visitor.visitMap(this); }
487497
protected static [Symbol.toStringTag] = ((proto: Map_) => {
488-
return proto[Symbol.toStringTag] = 'Map';
498+
return proto[Symbol.toStringTag] = 'Map_';
489499
})(Map_.prototype);
490500
}
491501

js/src/vector/flat.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export class FlatView<T extends FlatType> implements View<T> {
4141
return this.values[index] = value;
4242
}
4343
public toArray(): IterableArrayLike<T['TValue']> {
44-
return this.values;
44+
return this.values.subarray(0, this.length);
4545
}
4646
public [Symbol.iterator](): IterableIterator<T['TValue']> {
47-
return this.values[Symbol.iterator]() as IterableIterator<T['TValue']>;
47+
return this.values.subarray(0, this.length)[Symbol.iterator]() as IterableIterator<T['TValue']>;
4848
}
4949
}
5050

@@ -152,7 +152,9 @@ export class PrimitiveView<T extends PrimitiveType> extends FlatView<T> {
152152
return this.setValue(this.values, index, this.size, value);
153153
}
154154
public toArray(): IterableArrayLike<T['TValue']> {
155-
return this.size === 1 ? this.values : new this.ArrayType(this);
155+
return this.size > 1 ?
156+
new this.ArrayType(this) :
157+
this.values.subarray(0, this.length);
156158
}
157159
public *[Symbol.iterator](): IterableIterator<T['TValue']> {
158160
const get = this.getValue;

js/src/vector/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export abstract class ListViewBase<T extends (ListType | FlatListType | FixedSiz
6565

6666
export abstract class VariableListViewBase<T extends (ListType | FlatListType)> extends ListViewBase<T> {
6767
constructor(data: Data<T>) {
68-
super(data)
68+
super(data);
6969
this.length = data.length;
7070
this.valueOffsets = data.valueOffsets;
7171
}

0 commit comments

Comments
 (0)