|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +import '../../jest-extensions.js'; |
| 19 | + |
| 20 | +import { |
| 21 | + makeData, makeVector, |
| 22 | + Schema, Field, RecordBatch, |
| 23 | + Struct, Int32 |
| 24 | +} from 'apache-arrow'; |
| 25 | + |
| 26 | +describe('Struct with zero children', () => { |
| 27 | + |
| 28 | + test('makeData with empty children preserves explicit length', () => { |
| 29 | + const data = makeData({ type: new Struct([]), length: 50, nullCount: 0, children: [] }); |
| 30 | + expect(data).toHaveLength(50); |
| 31 | + }); |
| 32 | + |
| 33 | + test('makeData with empty children and no length defaults to 0', () => { |
| 34 | + const data = makeData({ type: new Struct([]), children: [] }); |
| 35 | + expect(data).toHaveLength(0); |
| 36 | + }); |
| 37 | + |
| 38 | + test('setChildAt preserves numRows after column replacement', () => { |
| 39 | + const field = Field.new({ name: 'a', type: new Int32, nullable: true }); |
| 40 | + const schema = new Schema([field]); |
| 41 | + const childData = makeData({ type: new Int32, length: 10, nullCount: 0 }); |
| 42 | + const structData = makeData({ |
| 43 | + type: new Struct(schema.fields), |
| 44 | + length: 10, |
| 45 | + nullCount: 0, |
| 46 | + children: [childData] |
| 47 | + }); |
| 48 | + const batch = new RecordBatch(schema, structData); |
| 49 | + expect(batch.numRows).toBe(10); |
| 50 | + |
| 51 | + const newChild = makeVector(new Int32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); |
| 52 | + const newBatch = batch.setChildAt(0, newChild); |
| 53 | + expect(newBatch.numRows).toBe(10); |
| 54 | + }); |
| 55 | +}); |
0 commit comments