This is an automated email from the ASF dual-hosted git repository. domoritz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push: new 89fdbb9968 GH-45915: [JS] Ensure UnionBuilder yields chunks with correct length (#45916) 89fdbb9968 is described below commit 89fdbb9968b7031be21a41a9874b3dc4a61cf953 Author: Paul Taylor <178183+trxcl...@users.noreply.github.com> AuthorDate: Tue Mar 25 10:25:15 2025 -0700 GH-45915: [JS] Ensure UnionBuilder yields chunks with correct length (#45916) ### Rationale for this change Fixes https://github.com/apache/arrow/issues/45915 ### Are these changes tested? Yes ### Are there any user-facing changes? Yes * GitHub Issue: #45915 --- js/src/builder/union.ts | 2 ++ js/test/unit/builders/utils.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/js/src/builder/union.ts b/js/src/builder/union.ts index 7bee460a77..6b6f4d476d 100644 --- a/js/src/builder/union.ts +++ b/js/src/builder/union.ts @@ -56,6 +56,7 @@ export abstract class UnionBuilder<T extends Union, TNull = any> extends Builder const childIndex = this.type.typeIdToChildIndex[childTypeId!]; const child = this.children[childIndex]; child?.set(index, value); + this.length = Math.max(index + 1, this.length); } public addChild(child: Builder, name = `${this.children.length}`) { @@ -93,5 +94,6 @@ export class DenseUnionBuilder<T extends DenseUnion, TNull = any> extends UnionB const child = this.getChildAt(this.type.typeIdToChildIndex[id])!; const denseIndex = this._offsets.set(index, child.length).buffer[index]; child?.set(denseIndex, value); + this.length = Math.max(index + 1, this.length); } } diff --git a/js/test/unit/builders/utils.ts b/js/test/unit/builders/utils.ts index 7cc0a075d8..1ea6a4e1f2 100644 --- a/js/test/unit/builders/utils.ts +++ b/js/test/unit/builders/utils.ts @@ -141,6 +141,7 @@ export function validateVector<T extends DataType>(vals: (T['TValue'] | null)[], let i = 0, x: T['TValue'] | null, y: T['TValue'] | null; const nulls = nullVals.reduce((m, x) => m.set(x, x), new Map()); try { + expect(vec).toHaveLength(vals.length); for (x of vec) { if (nulls.has(y = vals[i])) { expect(x).toBeNull();