Skip to content

Commit

Permalink
ARROW-320: ComplexCopier.copy(FieldReader, FieldWriter) should not st…
Browse files Browse the repository at this point in the history
…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
adeneche authored and julienledem committed Oct 6, 2016
1 parent 04cf874 commit f1a4bd1
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 6 deletions.
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());
}
}
}

0 comments on commit f1a4bd1

Please sign in to comment.