Skip to content

Commit a9d773d

Browse files
committed
move ValidityView into its own module, like ChunkedView is
1 parent 85eb7ee commit a9d773d

4 files changed

Lines changed: 63 additions & 50 deletions

File tree

js/src/vector.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ import { Uint8, Uint16, Uint32, Uint64, Int8, Int16, Int32, Int64, Float16, Floa
180180
import { Struct, Union, SparseUnion, DenseUnion, FixedSizeBinary, FixedSizeList, Map_, Dictionary } from './type';
181181

182182
import { ChunkedView } from './vector/chunked';
183+
import { ValidityView } from './vector/validity';
183184
import { DictionaryView } from './vector/dictionary';
184185
import { ListView, FixedSizeListView, BinaryView, Utf8View } from './vector/list';
185186
import { UnionView, DenseUnionView, NestedView, StructView, MapView } from './vector/nested';
186-
import { FlatView, NullView, BoolView, ValidityView, PrimitiveView, FixedSizeView, Float16View } from './vector/flat';
187+
import { FlatView, NullView, BoolView, PrimitiveView, FixedSizeView, Float16View } from './vector/flat';
187188
import { DateDayView, DateMillisecondView, IntervalYearMonthView } from './vector/flat';
188189
import { TimestampDayView, TimestampSecondView, TimestampMillisecondView, TimestampMicrosecondView, TimestampNanosecondView } from './vector/flat';
189190
import { packBools } from './util/bit';

js/src/vector/flat.ts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import { Data } from '../data';
1919
import { View } from '../vector';
2020
import { getBool, setBool, iterateBits } from '../util/bit';
21+
import { FlatType, PrimitiveType, IterableArrayLike } from '../type';
2122
import { Bool, Float16, Date_, Interval, Null, Int32, Timestamp } from '../type';
22-
import { DataType, FlatType, PrimitiveType, IterableArrayLike } from '../type';
2323

2424
export class FlatView<T extends FlatType> implements View<T> {
2525
public length: number;
@@ -103,53 +103,6 @@ export class BoolView extends FlatView<Bool> {
103103
}
104104
}
105105

106-
export class ValidityView<T extends DataType> implements View<T> {
107-
protected view: View<T>;
108-
protected length: number;
109-
protected offset: number;
110-
protected nullBitmap: Uint8Array;
111-
constructor(data: Data<T>, view: View<T>) {
112-
this.view = view;
113-
this.length = data.length;
114-
this.offset = data.offset;
115-
this.nullBitmap = data.nullBitmap!;
116-
}
117-
public clone(data: Data<T>): this {
118-
return new ValidityView(data, this.view.clone(data)) as this;
119-
}
120-
public toArray(): IterableArrayLike<T['TValue'] | null> {
121-
return [...this];
122-
}
123-
public indexOf(search: T['TValue']) {
124-
let index = 0;
125-
for (let value of this) {
126-
if (value === search) { return index; }
127-
++index;
128-
}
129-
130-
return -1;
131-
}
132-
public isValid(index: number): boolean {
133-
const nullBitIndex = this.offset + index;
134-
return getBool(null, index, this.nullBitmap[nullBitIndex >> 3], nullBitIndex % 8);
135-
}
136-
public get(index: number): T['TValue'] | null {
137-
const nullBitIndex = this.offset + index;
138-
return this.getNullable(this.view, index, this.nullBitmap[nullBitIndex >> 3], nullBitIndex % 8);
139-
}
140-
public set(index: number, value: T['TValue'] | null): void {
141-
if (setBool(this.nullBitmap, this.offset + index, value != null)) {
142-
this.view.set(index, value);
143-
}
144-
}
145-
public [Symbol.iterator](): IterableIterator<T['TValue'] | null> {
146-
return iterateBits<T['TValue'] | null>(this.nullBitmap, this.offset, this.length, this.view, this.getNullable);
147-
}
148-
protected getNullable(view: View<T>, index: number, byte: number, bit: number) {
149-
return getBool(view, index, byte, bit) ? view.get(index) : null;
150-
}
151-
}
152-
153106
export class PrimitiveView<T extends PrimitiveType> extends FlatView<T> {
154107
public size: number;
155108
public ArrayType: T['ArrayType'];

js/src/vector/validity.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Data } from '../data';
2+
import { View, Vector } from '../vector';
3+
import { NestedView } from './nested';
4+
import { DataType, IterableArrayLike } from '../type';
5+
import { getBool, setBool, iterateBits } from '../util/bit';
6+
7+
export class ValidityView<T extends DataType> implements View<T> {
8+
protected view: View<T>;
9+
protected length: number;
10+
protected offset: number;
11+
protected nullBitmap: Uint8Array;
12+
constructor(data: Data<T>, view: View<T>) {
13+
this.view = view;
14+
this.length = data.length;
15+
this.offset = data.offset;
16+
this.nullBitmap = data.nullBitmap!;
17+
}
18+
public get size(): number {
19+
return (this.view as any).size || 1;
20+
}
21+
public clone(data: Data<T>): this {
22+
return new ValidityView(data, this.view.clone(data)) as this;
23+
}
24+
public toArray(): IterableArrayLike<T['TValue'] | null> {
25+
return [...this];
26+
}
27+
public indexOf(search: T['TValue']) {
28+
let index = 0;
29+
for (let value of this) {
30+
if (value === search) { return index; }
31+
++index;
32+
}
33+
34+
return -1;
35+
}
36+
public isValid(index: number): boolean {
37+
const nullBitIndex = this.offset + index;
38+
return getBool(null, index, this.nullBitmap[nullBitIndex >> 3], nullBitIndex % 8);
39+
}
40+
public get(index: number): T['TValue'] | null {
41+
const nullBitIndex = this.offset + index;
42+
return this.getNullable(this.view, index, this.nullBitmap[nullBitIndex >> 3], nullBitIndex % 8);
43+
}
44+
public set(index: number, value: T['TValue'] | null): void {
45+
if (setBool(this.nullBitmap, this.offset + index, value != null)) {
46+
this.view.set(index, value);
47+
}
48+
}
49+
public getChildAt<R extends DataType = DataType>(index: number): Vector<R> | null {
50+
return (this.view as NestedView<any>).getChildAt<R>(index);
51+
}
52+
public [Symbol.iterator](): IterableIterator<T['TValue'] | null> {
53+
return iterateBits<T['TValue'] | null>(this.nullBitmap, this.offset, this.length, this.view, this.getNullable);
54+
}
55+
protected getNullable(view: View<T>, index: number, byte: number, bit: number) {
56+
return getBool(view, index, byte, bit) ? view.get(index) : null;
57+
}
58+
}

js/src/vector/view.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export { ChunkedView } from './chunked';
2+
export { ValidityView } from './validity';
23
export { DictionaryView } from './dictionary';
34
export { ListView, FixedSizeListView, BinaryView, Utf8View } from './list';
45
export { UnionView, DenseUnionView, NestedView, StructView, MapView } from './nested';
5-
export { FlatView, NullView, BoolView, ValidityView, PrimitiveView, FixedSizeView, Float16View } from './flat';
6+
export { FlatView, NullView, BoolView, PrimitiveView, FixedSizeView, Float16View } from './flat';
67
export { DateDayView, DateMillisecondView } from './flat';
78
export { IntervalYearMonthView, IntervalYearView, IntervalMonthView } from './flat';
89
export { TimestampDayView, TimestampSecondView, TimestampMillisecondView, TimestampMicrosecondView, TimestampNanosecondView } from './flat';

0 commit comments

Comments
 (0)