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

ARROW-320: ComplexCopier.copy(FieldReader, FieldWriter) should not st… #160

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 8 additions & 6 deletions java/vector/src/main/codegen/templates/ComplexCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@ private static void writeValue(FieldReader reader, FieldWriter writer) {
switch (mt) {

case LIST:
writer.startList();
while (reader.next()) {
writeValue(reader.reader(), getListWriterForReader(reader.reader(), writer));
if (reader.isSet()) {
writer.startList();
while (reader.next()) {
writeValue(reader.reader(), getListWriterForReader(reader.reader(), writer));
}
writer.endList();
}
writer.endList();
break;
case MAP:
writer.start();
if (reader.isSet()) {
writer.start();
for(String name : reader){
FieldReader childReader = reader.reader(name);
if(childReader.isSet()){
writeValue(childReader, getMapWriterForReader(childReader, writer, name));
}
}
writer.end();
}
writer.end();
break;
<#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
<#assign fields = minor.fields!type.fields />
Expand Down
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());
}
}
}