You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by pr...@apache.org on 2019/12/20 10:43:46 UTC

[arrow] branch master updated: ARROW-7447: [Java] ComplexCopier does incorrect copy in some cases

This is an automated email from the ASF dual-hosted git repository.

praveenbingo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new bef7418  ARROW-7447: [Java] ComplexCopier does incorrect copy in some cases
bef7418 is described below

commit bef7418112fcedea82ecd1efa46001d5c4573cb3
Author: Projjal Chanda <ia...@pchanda.com>
AuthorDate: Fri Dec 20 16:13:22 2019 +0530

    ARROW-7447: [Java] ComplexCopier does incorrect copy in some cases
    
    Closes #6071 from projjal/complexcopierfix and squashes the following commits:
    
    2657171a1 <Projjal Chanda> Fixeed complexcopier
    
    Authored-by: Projjal Chanda <ia...@pchanda.com>
    Signed-off-by: Praveen <pr...@dremio.com>
---
 .../src/main/codegen/templates/ComplexCopier.java  |  3 +-
 .../vector/complex/impl/TestComplexCopier.java     | 48 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/java/vector/src/main/codegen/templates/ComplexCopier.java b/java/vector/src/main/codegen/templates/ComplexCopier.java
index 3801e2e..b57f76d 100644
--- a/java/vector/src/main/codegen/templates/ComplexCopier.java
+++ b/java/vector/src/main/codegen/templates/ComplexCopier.java
@@ -52,9 +52,8 @@ public class ComplexCopier {
       case FIXED_SIZE_LIST:
         if (reader.isSet()) {
           writer.startList();
-          FieldWriter dataWriter = getListWriterForReader(reader.reader(), writer);
           while (reader.next()) {
-            writeValue(reader.reader(), dataWriter);
+            writeValue(reader.reader(), getListWriterForReader(reader.reader(), writer));
           }
           writer.endList();
         }
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestComplexCopier.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestComplexCopier.java
index 2cabd26..0644a62 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestComplexCopier.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestComplexCopier.java
@@ -24,6 +24,7 @@ import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.memory.RootAllocator;
 import org.apache.arrow.vector.compare.VectorEqualsVisitor;
 import org.apache.arrow.vector.complex.FixedSizeListVector;
+import org.apache.arrow.vector.complex.ListVector;
 import org.apache.arrow.vector.complex.MapVector;
 import org.apache.arrow.vector.complex.reader.FieldReader;
 import org.apache.arrow.vector.complex.writer.FieldWriter;
@@ -152,4 +153,51 @@ public class TestComplexCopier {
 
     }
   }
+
+  @Test
+  public void testCopyListVector() {
+    try (ListVector from = ListVector.empty("from", allocator);
+         ListVector to = ListVector.empty("to", allocator)) {
+
+      UnionListWriter listWriter = from.getWriter();
+      listWriter.allocate();
+
+      for (int i = 0; i < COUNT; i++) {
+        listWriter.setPosition(i);
+        listWriter.startList();
+
+        listWriter.integer().writeInt(i);
+        listWriter.integer().writeInt(i * 2);
+
+        listWriter.list().startList();
+        listWriter.list().bigInt().writeBigInt(i);
+        listWriter.list().bigInt().writeBigInt(i * 2);
+        listWriter.list().bigInt().writeBigInt(i * 3);
+        listWriter.list().endList();
+
+        listWriter.list().startList();
+        listWriter.list().bigInt().writeBigInt(i * 4);
+        listWriter.list().bigInt().writeBigInt(i * 5);
+        listWriter.list().bigInt().writeBigInt(i * 6);
+        listWriter.list().endList();
+        listWriter.endList();
+      }
+      from.setValueCount(COUNT);
+
+      // copy values
+      FieldReader in = from.getReader();
+      FieldWriter out = to.getWriter();
+      for (int i = 0; i < COUNT; i++) {
+        in.setPosition(i);
+        out.setPosition(i);
+        ComplexCopier.copy(in, out);
+      }
+
+      to.setValueCount(COUNT);
+
+      // validate equals
+      assertTrue(VectorEqualsVisitor.vectorEquals(from, to));
+
+    }
+  }
 }