diff --git a/js/src/builder.ts b/js/src/builder.ts index 5b124f7982ba5..3f6eaac755136 100644 --- a/js/src/builder.ts +++ b/js/src/builder.ts @@ -290,7 +290,7 @@ export abstract class Builder { 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); } diff --git a/js/src/builder/buffer.ts b/js/src/builder/buffer.ts index c9ffc255cca7d..6d70934102de5 100644 --- a/js/src/builder/buffer.ts +++ b/js/src/builder/buffer.ts @@ -101,7 +101,7 @@ export class BufferBuilder extends BufferBuilder { +export class DataBufferBuilder extends BufferBuilder { public last() { return this.get(this.length - 1); } public get(index: number) { return this.buffer[index]; } public set(index: number, value: number) { @@ -137,10 +137,10 @@ export class BitmapBufferBuilder extends DataBufferBuilder { /** @ignore */ export class OffsetsBufferBuilder extends DataBufferBuilder { 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++) { diff --git a/js/src/type.ts b/js/src/type.ts index 482846d37934e..9cc5bc06166c8 100644 --- a/js/src/type.ts +++ b/js/src/type.ts @@ -43,7 +43,7 @@ export interface DataType | BigIntArrayConstructor; + readonly OffsetType: TypedArrayConstructor | BigIntArrayConstructor; readonly children: Field[]; } @@ -251,7 +251,7 @@ export class Binary extends DataType { } /** @ignore */ -export interface Utf8 extends DataType { TArray: Uint8Array; TOffset: Uint32Array; TValue: string; ArrayType: TypedArrayConstructor; OffsetType: TypedArrayConstructor } +export interface Utf8 extends DataType { TArray: Uint8Array; TOffset: Int32Array; TValue: string; ArrayType: TypedArrayConstructor; OffsetType: TypedArrayConstructor } /** @ignore */ export class Utf8 extends DataType { constructor() { @@ -261,13 +261,13 @@ export class Utf8 extends DataType { public toString() { return `Utf8`; } protected static [Symbol.toStringTag] = ((proto: Utf8) => { (proto).ArrayType = Uint8Array; - (proto).OffsetType = Uint32Array; + (proto).OffsetType = Int32Array; return proto[Symbol.toStringTag] = 'Utf8'; })(Utf8.prototype); } /** @ignore */ -export interface LargeUtf8 extends DataType { TArray: Uint8Array; TOffset: BigUint64Array; TValue: string; ArrayType: TypedArrayConstructor; OffsetType: BigIntArrayConstructor } +export interface LargeUtf8 extends DataType { TArray: Uint8Array; TOffset: BigInt64Array; TValue: string; ArrayType: TypedArrayConstructor; OffsetType: BigIntArrayConstructor } /** @ignore */ export class LargeUtf8 extends DataType { constructor() { @@ -277,7 +277,7 @@ export class LargeUtf8 extends DataType { public toString() { return `LargeUtf8`; } protected static [Symbol.toStringTag] = ((proto: LargeUtf8) => { (proto).ArrayType = Uint8Array; - (proto).OffsetType = BigUint64Array; + (proto).OffsetType = BigInt64Array; return proto[Symbol.toStringTag] = 'LargeUtf8'; })(LargeUtf8.prototype); } diff --git a/js/src/visitor/get.ts b/js/src/visitor/get.ts index 84e97180016f3..bc30668fe3d0a 100644 --- a/js/src/visitor/get.ts +++ b/js/src/visitor/get.ts @@ -108,7 +108,7 @@ function wrapGet(fn: (data: Data, _1: any) => any) { /** @ignore */ const getNull = (_data: Data, _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; } diff --git a/js/src/visitor/set.ts b/js/src/visitor/set.ts index e356d524fa085..77696492ec60f 100644 --- a/js/src/visitor/set.ts +++ b/js/src/visitor/set.ts @@ -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 = (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)); } };