-
Notifications
You must be signed in to change notification settings - Fork 19
feat: add schema parameter to tableFromArrays and new recordBatchFromArrays factory #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,9 +80,35 @@ export function vectorFromArray<T extends dtypes.DataType>(data: DataProps<T>): | |
| export function vectorFromArray<T extends TypedArray | BigIntArray | readonly unknown[]>(data: T): Vector<ArrayDataType<T>>; | ||
|
|
||
| export function vectorFromArray(init: any, type?: dtypes.DataType) { | ||
| if (init instanceof Data || init instanceof Vector || init.type instanceof dtypes.DataType || ArrayBuffer.isView(init)) { | ||
| if (init instanceof Data || init instanceof Vector || init.type instanceof dtypes.DataType) { | ||
| return makeVector(init as any); | ||
| } | ||
| if (ArrayBuffer.isView(init) && !type) { | ||
| return makeVector(init as any); | ||
| } | ||
| if (ArrayBuffer.isView(init) && type) { | ||
| // Validate BigInt/number boundary | ||
| const isBigIntInput = init instanceof BigInt64Array || init instanceof BigUint64Array; | ||
| const isBigIntTarget = type.ArrayType === BigInt64Array || type.ArrayType === BigUint64Array; | ||
| if (isBigIntInput && !isBigIntTarget) { | ||
| throw new TypeError( | ||
| `Cannot convert BigInt input to ${type}. BigInt arrays can only target BigInt-based types (e.g. Int64, Uint64).` | ||
| ); | ||
| } | ||
| if (!isBigIntInput && isBigIntTarget) { | ||
| throw new TypeError( | ||
| `Cannot convert non-BigInt input to ${type}. ${type} requires BigInt values.` | ||
| ); | ||
| } | ||
|
|
||
| // Fast path: direct TypedArray conversion for Int and Float types | ||
| if (dtypes.DataType.isInt(type) || dtypes.DataType.isFloat(type)) { | ||
| const data = init.constructor === type.ArrayType | ||
| ? init // zero-copy, same TypedArray type | ||
| : new (type.ArrayType as any)(init); // standard JS TypedArray conversion | ||
| return makeVector({ type, data, offset: 0, length: data.length, nullCount: 0 } as any); | ||
| } | ||
|
Comment on lines
+105
to
+110
|
||
| } | ||
| const options: IterableBuilderOptions = { type: type ?? inferType(init), nullValues: [null] }; | ||
| const chunks = [...builderThroughIterable(options)(init)]; | ||
| const vector = chunks.length === 1 ? chunks[0] : chunks.reduce((a, b) => a.concat(b)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is redundant, as this will happen in
makeVectorviamakeDatacallingtoArrayBufferViewon the incoming typed array here and here.toArrayBufferViewreturns a zero-copy ArrayBufferView of the desired type (here) when given an ArrayBuffer (or any ArrayBufferView).