forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-15060: [JS] Add LargeUtf8 type (apache#35780)
This pull request adds support for the LargeUTF8 type in Arrow. Now we can create, decode, and encode these vectors. However, while the offset vectors support 64 bit integers, note that the value buffers are limited to a length of 32 bits meaning that LargeUTF8 vectors cannot yet be larger than UTF8 vectors. We will see how we can address this limitation in a follow up pull request. The issue is that JS typed arrays can be at most 2**31-1 elements long (implementation defined). This pull request also fixes a bug in a rounding method which prevented us from supporting large vectors so it's already a big step forward. Fixes apache#15060. * Closes: apache#15060 --------- Co-authored-by: Kyle Barron <[email protected]>
- Loading branch information
Showing
36 changed files
with
432 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import { LargeUtf8 } from '../type.js'; | ||
import { encodeUtf8 } from '../util/utf8.js'; | ||
import { BufferBuilder } from './buffer.js'; | ||
import { VariableWidthBuilder, BuilderOptions } from '../builder.js'; | ||
|
||
/** @ignore */ | ||
export class LargeUtf8Builder<TNull = any> extends VariableWidthBuilder<LargeUtf8, TNull> { | ||
constructor(opts: BuilderOptions<LargeUtf8, TNull>) { | ||
super(opts); | ||
this._values = new BufferBuilder(new Uint8Array(0)); | ||
} | ||
public get byteLength(): number { | ||
let size = this._pendingLength + (this.length * 4); | ||
this._offsets && (size += this._offsets.byteLength); | ||
this._values && (size += this._values.byteLength); | ||
this._nulls && (size += this._nulls.byteLength); | ||
return size; | ||
} | ||
public setValue(index: number, value: string) { | ||
return super.setValue(index, encodeUtf8(value) as any); | ||
} | ||
// @ts-ignore | ||
// TODO: move to largeBinaryBuilder when implemented | ||
// protected _flushPending(pending: Map<number, Uint8Array | undefined>, pendingLength: number): void { } | ||
protected _flushPending(pending: Map<number, Uint8Array | undefined>, pendingLength: number) { | ||
const offsets = this._offsets; | ||
const data = this._values.reserve(pendingLength).buffer; | ||
let offset = 0; | ||
for (const [index, value] of pending) { | ||
if (value === undefined) { | ||
offsets.set(index, BigInt(0)); | ||
} else { | ||
const length = value.length; | ||
data.set(value, offset); | ||
offsets.set(index, BigInt(length)); | ||
offset += length; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// (LargeUtf8Builder.prototype as any)._flushPending = (LargeBinaryBuilder.prototype as any)._flushPending; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.