-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARROW-320: ComplexCopier.copy(FieldReader, FieldWriter) should not st…
…art a list if reader is not set Author: adeneche <adeneche@dremio.com> Closes #160 from adeneche/ARROW-320 and squashes the following commits: 5c6ebc5 [adeneche] ARROW-320: ComplexCopier.copy(FieldReader, FieldWriter) should not start a list if reader is not set
- Loading branch information
1 parent
04cf874
commit f1a4bd1
Showing
2 changed files
with
95 additions
and
6 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
87 changes: 87 additions & 0 deletions
87
java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java
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,87 @@ | ||
/** | ||
* 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. | ||
*/ | ||
package org.apache.arrow.vector; | ||
|
||
import org.apache.arrow.memory.BufferAllocator; | ||
import org.apache.arrow.vector.complex.ListVector; | ||
import org.apache.arrow.vector.complex.impl.ComplexCopier; | ||
import org.apache.arrow.vector.complex.impl.UnionListReader; | ||
import org.apache.arrow.vector.complex.impl.UnionListWriter; | ||
import org.apache.arrow.vector.complex.reader.FieldReader; | ||
import org.apache.arrow.vector.types.pojo.Field; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class TestListVector { | ||
private final static String EMPTY_SCHEMA_PATH = ""; | ||
|
||
private BufferAllocator allocator; | ||
|
||
@Before | ||
public void init() { | ||
allocator = new DirtyRootAllocator(Long.MAX_VALUE, (byte) 100); | ||
} | ||
|
||
@After | ||
public void terminate() throws Exception { | ||
allocator.close(); | ||
} | ||
|
||
@Test | ||
public void testCopyFrom() throws Exception { | ||
try (ListVector inVector = new ListVector("input", allocator, null); | ||
ListVector outVector = new ListVector("output", allocator, null)) { | ||
UnionListWriter writer = inVector.getWriter(); | ||
writer.allocate(); | ||
|
||
// populate input vector with the following records | ||
// [1, 2, 3] | ||
// null | ||
// [] | ||
writer.setPosition(0); // optional | ||
writer.startList(); | ||
writer.bigInt().writeBigInt(1); | ||
writer.bigInt().writeBigInt(2); | ||
writer.bigInt().writeBigInt(3); | ||
writer.endList(); | ||
|
||
writer.setPosition(2); | ||
writer.startList(); | ||
writer.endList(); | ||
|
||
writer.setValueCount(3); | ||
|
||
// copy values from input to output | ||
outVector.allocateNew(); | ||
for (int i = 0; i < 3; i++) { | ||
outVector.copyFrom(i, i, inVector); | ||
} | ||
outVector.getMutator().setValueCount(3); | ||
|
||
// assert the output vector is correct | ||
FieldReader reader = outVector.getReader(); | ||
Assert.assertTrue("shouldn't be null", reader.isSet()); | ||
reader.setPosition(1); | ||
Assert.assertFalse("should be null", reader.isSet()); | ||
reader.setPosition(2); | ||
Assert.assertTrue("shouldn't be null", reader.isSet()); | ||
} | ||
} | ||
} |