Skip to content
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

GH-45862: [JS] Fix FixedSizeListBuilder behavior for null slots #45889

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Modify FixedSizeListBuilder behavior for null slots
amoeba committed Mar 22, 2025
commit d3ecdb4a79fd81074c97c62222da0402c333533a
10 changes: 8 additions & 2 deletions js/src/builder/fixedsizelist.ts
Original file line number Diff line number Diff line change
@@ -24,10 +24,16 @@ export class FixedSizeListBuilder<T extends DataType = any, TNull = any> extends
public setValue(index: number, value: T['TValue']) {
const [child] = this.children;
const start = index * this.stride;
for (let i = -1, n = value.length; ++i < n;) {
child.set(start + i, value[i]);
for (let i = -1, n = this.stride; ++i < n;) {
// Use either the actual value or a null (if the slot is null)
const finalVal = value ? value[i] : null;
child.set(start + i, finalVal);
}
}
public setValid(index: number, valid: boolean) {
this.length = this._nulls.set(index, +valid).length;
return true;
}
public addChild(child: Builder<T>, name = '0') {
if (this.numChildren > 0) {
throw new Error('FixedSizeListBuilder can only have one child.');
39 changes: 38 additions & 1 deletion js/test/unit/vector/vector-tests.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
// under the License.

import {
Bool, DateDay, DateMillisecond, Dictionary, Float64, Int32, List, makeVector, Struct, Utf8, LargeUtf8, util, Vector, vectorFromArray, makeData
Bool, DateDay, DateMillisecond, Dictionary, Float64, Int32, List, makeVector, Struct, Utf8, LargeUtf8, util, Vector, vectorFromArray, makeData, FixedSizeList, Field,
} from 'apache-arrow';

describe(`makeVectorFromArray`, () => {
@@ -323,3 +323,40 @@ function basicVectorTests(vector: Vector, values: any[], extras: any[]) {
}
});
}

// GH-45862: Make sure vectorFromArray produces the correct result for
// FixedSizeList with null slots
describe(`vecorFromArray() with FixedSizeList<T> and null slots`, () => {
test(`correct child length with null slot first`, () => {
let vector = vectorFromArray(
[null, [1, 2, 3]],
new FixedSizeList(3, new Field('item', new Int32())),
);
let child = vector.getChildAt(0);

expect(child).toHaveLength(6);
expect(child?.nullCount).toBe(3);
});

test(`correct child length with null slot last`, () => {
let vector = vectorFromArray(
[[1, 2, 3], null],
new FixedSizeList(3, new Field('item', new Int32())),
);
let child = vector.getChildAt(0);

expect(child).toHaveLength(6);
expect(child?.nullCount).toBe(3);
});

test(`correct child length with null in the middle`, () => {
let vector = vectorFromArray(
[[1, 2, 3], null, [7, 8, 9]],
new FixedSizeList(3, new Field('item', new Int32())),
);
let child = vector.getChildAt(0);

expect(child).toHaveLength(9);
expect(child?.nullCount).toBe(3);
});
});