Skip to content

Commit

Permalink
Switch back to int types
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Jun 11, 2023
1 parent ccdd799 commit fdf9ed6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion js/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export abstract class Builder<T extends DataType = any, TNull = any> {
valueOffsets = _offsets?.flush(length);
} else if (valueOffsets = _offsets?.flush(length)) { // Variable-width primitives (Binary, Utf8), and Lists
// Binary, Utf8
data = _values?.flush(_offsets.last());
data = _values?.flush(Number(_offsets.last()));
} else { // Fixed-width primitives (Int, Float, Decimal, Time, Timestamp, and Interval)
data = _values?.flush(length);
}
Expand Down
6 changes: 3 additions & 3 deletions js/src/builder/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class BufferBuilder<T extends TypedArray | BigIntArray = any, TValue = Da
(BufferBuilder.prototype as any).offset = 0;

/** @ignore */
export class DataBufferBuilder<T extends TypedArray> extends BufferBuilder<T, number> {
export class DataBufferBuilder<T extends TypedArray | BigIntArray> extends BufferBuilder<T, number> {
public last() { return this.get(this.length - 1); }
public get(index: number) { return this.buffer[index]; }
public set(index: number, value: number) {
Expand Down Expand Up @@ -137,10 +137,10 @@ export class BitmapBufferBuilder extends DataBufferBuilder<Uint8Array> {
/** @ignore */
export class OffsetsBufferBuilder<T extends DataType> extends DataBufferBuilder<T['TOffset']> {
constructor(type: T) { super(new type.OffsetType(1), 1); }
public append(value: number) {
public append(value: number | bigint) {
return this.set(this.length - 1, value);
}
public set(index: number, value: number) {
public set(index: number, value: number | bigint) {
const offset = this.length - 1;
const buffer = this.reserve(index - offset + 1).buffer;
if (offset < index++) {
Expand Down
10 changes: 5 additions & 5 deletions js/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface DataType<TType extends Type = Type, TChildren extends TypeMap =
readonly TValue: any;
readonly TChildren: TChildren;
readonly ArrayType: any;
readonly OffsetType: TypedArrayConstructor<Uint32Array> | BigIntArrayConstructor<BigUint64Array>;
readonly OffsetType: TypedArrayConstructor<Int32Array> | BigIntArrayConstructor<BigInt64Array>;
readonly children: Field<TChildren[keyof TChildren]>[];
}

Expand Down Expand Up @@ -251,7 +251,7 @@ export class Binary extends DataType<Type.Binary> {
}

/** @ignore */
export interface Utf8 extends DataType<Type.Utf8> { TArray: Uint8Array; TOffset: Uint32Array; TValue: string; ArrayType: TypedArrayConstructor<Uint8Array>; OffsetType: TypedArrayConstructor<Uint32Array> }
export interface Utf8 extends DataType<Type.Utf8> { TArray: Uint8Array; TOffset: Int32Array; TValue: string; ArrayType: TypedArrayConstructor<Uint8Array>; OffsetType: TypedArrayConstructor<Int32Array> }
/** @ignore */
export class Utf8 extends DataType<Type.Utf8> {
constructor() {
Expand All @@ -261,13 +261,13 @@ export class Utf8 extends DataType<Type.Utf8> {
public toString() { return `Utf8`; }
protected static [Symbol.toStringTag] = ((proto: Utf8) => {
(<any>proto).ArrayType = Uint8Array;
(<any>proto).OffsetType = Uint32Array;
(<any>proto).OffsetType = Int32Array;
return proto[Symbol.toStringTag] = 'Utf8';
})(Utf8.prototype);
}

/** @ignore */
export interface LargeUtf8 extends DataType<Type.LargeUtf8> { TArray: Uint8Array; TOffset: BigUint64Array; TValue: string; ArrayType: TypedArrayConstructor<Uint8Array>; OffsetType: BigIntArrayConstructor<BigUint64Array> }
export interface LargeUtf8 extends DataType<Type.LargeUtf8> { TArray: Uint8Array; TOffset: BigInt64Array; TValue: string; ArrayType: TypedArrayConstructor<Uint8Array>; OffsetType: BigIntArrayConstructor<BigInt64Array> }
/** @ignore */
export class LargeUtf8 extends DataType<Type.LargeUtf8> {
constructor() {
Expand All @@ -277,7 +277,7 @@ export class LargeUtf8 extends DataType<Type.LargeUtf8> {
public toString() { return `LargeUtf8`; }
protected static [Symbol.toStringTag] = ((proto: LargeUtf8) => {
(<any>proto).ArrayType = Uint8Array;
(<any>proto).OffsetType = BigUint64Array;
(<any>proto).OffsetType = BigInt64Array;
return proto[Symbol.toStringTag] = 'LargeUtf8';
})(LargeUtf8.prototype);
}
Expand Down
2 changes: 1 addition & 1 deletion js/src/visitor/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function wrapGet<T extends DataType>(fn: (data: Data<T>, _1: any) => any) {
/** @ignore */
const getNull = <T extends Null>(_data: Data<T>, _index: number): T['TValue'] => null;
/** @ignore */
const getVariableWidthBytes = (values: Uint8Array, valueOffsets: Uint32Array | BigUint64Array, index: number) => {
const getVariableWidthBytes = (values: Uint8Array, valueOffsets: Int32Array | BigInt64Array, index: number) => {
if (index + 1 >= valueOffsets.length) {
return null as any;
}
Expand Down
5 changes: 3 additions & 2 deletions js/src/visitor/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ export const setEpochMsToNanosecondsLong = (data: Int32Array, index: number, epo
};

/** @ignore */
export const setVariableWidthBytes = (values: Uint8Array, valueOffsets: Uint32Array | BigUint64Array, index: number, value: Uint8Array) => {
export const setVariableWidthBytes = <T extends Int32Array | BigInt64Array>(values: Uint8Array, valueOffsets: T, index: number, value: Uint8Array) => {
if (index + 1 < valueOffsets.length) {
const { [index]: x, [index + 1]: y } = valueOffsets as BigUint64Array;
const x = valueOffsets[index] as T extends Int32Array ? number : bigint;
const y = valueOffsets[index + 1] as T extends Int32Array ? number : bigint;
values.set(value.subarray(0, Number(y - x)), Number(x));
}
};
Expand Down

0 comments on commit fdf9ed6

Please sign in to comment.