|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.arrow.vector; |
| 19 | + |
| 20 | +import org.apache.arrow.memory.BufferAllocator; |
| 21 | +import org.apache.arrow.vector.complex.ListVector; |
| 22 | +import org.apache.arrow.vector.complex.impl.ComplexCopier; |
| 23 | +import org.apache.arrow.vector.complex.impl.UnionListReader; |
| 24 | +import org.apache.arrow.vector.complex.impl.UnionListWriter; |
| 25 | +import org.apache.arrow.vector.complex.reader.FieldReader; |
| 26 | +import org.apache.arrow.vector.types.pojo.Field; |
| 27 | +import org.junit.After; |
| 28 | +import org.junit.Assert; |
| 29 | +import org.junit.Before; |
| 30 | +import org.junit.Test; |
| 31 | + |
| 32 | +public class TestListVector { |
| 33 | + private final static String EMPTY_SCHEMA_PATH = ""; |
| 34 | + |
| 35 | + private BufferAllocator allocator; |
| 36 | + |
| 37 | + @Before |
| 38 | + public void init() { |
| 39 | + allocator = new DirtyRootAllocator(Long.MAX_VALUE, (byte) 100); |
| 40 | + } |
| 41 | + |
| 42 | + @After |
| 43 | + public void terminate() throws Exception { |
| 44 | + allocator.close(); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testCopyFrom() throws Exception { |
| 49 | + try (ListVector inVector = new ListVector("input", allocator, null); |
| 50 | + ListVector outVector = new ListVector("output", allocator, null)) { |
| 51 | + UnionListWriter writer = inVector.getWriter(); |
| 52 | + writer.allocate(); |
| 53 | + |
| 54 | + // populate input vector with the following records |
| 55 | + // [1, 2, 3] |
| 56 | + // null |
| 57 | + // [] |
| 58 | + writer.setPosition(0); // optional |
| 59 | + writer.startList(); |
| 60 | + writer.bigInt().writeBigInt(1); |
| 61 | + writer.bigInt().writeBigInt(2); |
| 62 | + writer.bigInt().writeBigInt(3); |
| 63 | + writer.endList(); |
| 64 | + |
| 65 | + writer.setPosition(2); |
| 66 | + writer.startList(); |
| 67 | + writer.endList(); |
| 68 | + |
| 69 | + writer.setValueCount(3); |
| 70 | + |
| 71 | + // copy values from input to output |
| 72 | + outVector.allocateNew(); |
| 73 | + for (int i = 0; i < 3; i++) { |
| 74 | + outVector.copyFrom(i, i, inVector); |
| 75 | + } |
| 76 | + outVector.getMutator().setValueCount(3); |
| 77 | + |
| 78 | + // assert the output vector is correct |
| 79 | + FieldReader reader = outVector.getReader(); |
| 80 | + Assert.assertTrue("shouldn't be null", reader.isSet()); |
| 81 | + reader.setPosition(1); |
| 82 | + Assert.assertFalse("should be null", reader.isSet()); |
| 83 | + reader.setPosition(2); |
| 84 | + Assert.assertTrue("shouldn't be null", reader.isSet()); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments