You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ju...@apache.org on 2016/10/06 03:19:48 UTC
arrow git commit: ARROW-320: ComplexCopier.copy(FieldReader, FieldWriter) should not st…
Repository: arrow
Updated Branches:
refs/heads/master 04cf8746f -> f1a4bd176
ARROW-320: ComplexCopier.copy(FieldReader, FieldWriter) should not st\u2026
\u2026art a list if reader is not set
Author: adeneche <ad...@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
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/f1a4bd17
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/f1a4bd17
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/f1a4bd17
Branch: refs/heads/master
Commit: f1a4bd176bc2139ba785522200d7630408328911
Parents: 04cf874
Author: adeneche <ad...@dremio.com>
Authored: Wed Oct 5 20:19:42 2016 -0700
Committer: Julien Le Dem <ju...@dremio.com>
Committed: Wed Oct 5 20:19:42 2016 -0700
----------------------------------------------------------------------
.../main/codegen/templates/ComplexCopier.java | 14 ++--
.../org/apache/arrow/vector/TestListVector.java | 87 ++++++++++++++++++++
2 files changed, 95 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1a4bd17/java/vector/src/main/codegen/templates/ComplexCopier.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/ComplexCopier.java b/java/vector/src/main/codegen/templates/ComplexCopier.java
index a5756a4..0dffe5e 100644
--- a/java/vector/src/main/codegen/templates/ComplexCopier.java
+++ b/java/vector/src/main/codegen/templates/ComplexCopier.java
@@ -47,23 +47,25 @@ public class ComplexCopier {
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 />
http://git-wip-us.apache.org/repos/asf/arrow/blob/f1a4bd17/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java
new file mode 100644
index 0000000..bb71033
--- /dev/null
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java
@@ -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());
+ }
+ }
+}