GeorgeLeePatterson commented on code in PR #320:
URL: https://github.com/apache/arrow-js/pull/320#discussion_r2484810436
##########
src/visitor/get.ts:
##########
@@ -149,10 +154,39 @@ const getFixedSizeBinary = <T extends FixedSizeBinary>({
stride, values }: Data<
/** @ignore */
const getBinary = <T extends Binary | LargeBinary>({ values, valueOffsets }:
Data<T>, index: number): T['TValue'] => getVariableWidthBytes(values,
valueOffsets, index);
/** @ignore */
+const getBinaryViewValue = <T extends BinaryView>(data: Data<T>, index:
number): T['TValue'] => {
+ const values = data.values as Uint8Array;
+ if (!values) {
+ throw new Error('BinaryView data is missing view buffer');
+ }
+ const start = (data.offset + index) * BINARY_VIEW_SIZE;
+ const baseOffset = values.byteOffset + start;
+ const view = new DataView(values.buffer, baseOffset, BINARY_VIEW_SIZE);
+ const size = view.getInt32(0, true);
+ if (size <= 0) {
+ return new Uint8Array(0) as T['TValue'];
+ }
+ if (size <= BINARY_VIEW_INLINE_CAPACITY) {
+ return new Uint8Array(values.buffer, baseOffset + 4, size) as
T['TValue'];
+ }
+ const bufferIndex = view.getInt32(8, true);
+ const offset = view.getInt32(12, true);
+ const variadicBuffer = data.variadicBuffers?.[bufferIndex];
+ if (!variadicBuffer) {
+ throw new Error(`BinaryView variadic buffer ${bufferIndex} is
missing`);
+ }
+ return variadicBuffer.subarray(offset, offset + size) as T['TValue'];
+};
+/** @ignore */
const getUtf8 = <T extends Utf8 | LargeUtf8>({ values, valueOffsets }:
Data<T>, index: number): T['TValue'] => {
const bytes = getVariableWidthBytes(values, valueOffsets, index);
return bytes !== null ? decodeUtf8(bytes) : null as any;
};
+/** @ignore */
+const getUtf8ViewValue = <T extends Utf8View>(data: Data<T>, index: number):
T['TValue'] => {
+ const bytes = getBinaryViewValue(data as unknown as Data<BinaryView>,
index);
+ return decodeUtf8(bytes as unknown as Uint8Array);
Review Comment:
Agreed. As you can tell, some of these conversions were giving me a bit of
problems. But your suggestion makes sense. That should be simple enough.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]