You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by sm...@apache.org on 2016/10/07 21:44:27 UTC
arrow git commit: ARROW-326: Initialize nested writers in MapWriter
based on the underlying MapVector's field
Repository: arrow
Updated Branches:
refs/heads/master 2d8e82056 -> 1196691e2
ARROW-326: Initialize nested writers in MapWriter based on the underlying MapVector's field
Closes #163
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/1196691e
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/1196691e
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/1196691e
Branch: refs/heads/master
Commit: 1196691e221c5b00bbf9bf47eead6f684b61fe62
Parents: 2d8e820
Author: Steven Phillips <st...@dremio.com>
Authored: Fri Oct 7 13:12:35 2016 -0700
Committer: Steven Phillips <st...@dremio.com>
Committed: Fri Oct 7 14:43:27 2016 -0700
----------------------------------------------------------------------
.../src/main/codegen/templates/MapWriters.java | 22 ++++++++++++++++++++
.../complex/impl/TestPromotableWriter.java | 21 ++++++++++++++++++-
2 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/1196691e/java/vector/src/main/codegen/templates/MapWriters.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/MapWriters.java b/java/vector/src/main/codegen/templates/MapWriters.java
index 7f319a9..9fe20df 100644
--- a/java/vector/src/main/codegen/templates/MapWriters.java
+++ b/java/vector/src/main/codegen/templates/MapWriters.java
@@ -56,6 +56,28 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
}
</#if>
this.container = container;
+ for (Field child : container.getField().getChildren()) {
+ switch (Types.getMinorTypeForArrowType(child.getType())) {
+ case MAP:
+ map(child.getName());
+ break;
+ case LIST:
+ list(child.getName());
+ break;
+ case UNION:
+ UnionWriter writer = new UnionWriter(container.addOrGet(child.getName(), MinorType.UNION, UnionVector.class));
+ fields.put(child.getName().toLowerCase(), writer);
+ break;
+<#list vv.types as type><#list type.minor as minor>
+<#assign lowerName = minor.class?uncap_first />
+<#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+<#assign upperName = minor.class?upper_case />
+ case ${upperName}:
+ ${lowerName}(child.getName());
+ break;
+</#list></#list>
+ }
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/arrow/blob/1196691e/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java
index 689c96f..d439ceb 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java
@@ -21,13 +21,16 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import org.apache.arrow.flatbuf.Type;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.DirtyRootAllocator;
import org.apache.arrow.vector.complex.AbstractMapVector;
import org.apache.arrow.vector.complex.MapVector;
import org.apache.arrow.vector.complex.NullableMapVector;
import org.apache.arrow.vector.complex.UnionVector;
+import org.apache.arrow.vector.complex.writer.BaseWriter.MapWriter;
import org.apache.arrow.vector.types.Types.MinorType;
+import org.apache.arrow.vector.types.pojo.Field;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -50,7 +53,7 @@ public class TestPromotableWriter {
@Test
public void testPromoteToUnion() throws Exception {
- try (final AbstractMapVector container = new MapVector(EMPTY_SCHEMA_PATH, allocator, null);
+ try (final MapVector container = new MapVector(EMPTY_SCHEMA_PATH, allocator, null);
final NullableMapVector v = container.addOrGet("test", MinorType.MAP, NullableMapVector.class);
final PromotableWriter writer = new PromotableWriter(v, container)) {
@@ -92,6 +95,22 @@ public class TestPromotableWriter {
assertFalse("4 shouldn't be null", accessor.isNull(4));
assertEquals(100, accessor.getObject(4));
+
+ container.clear();
+ container.allocateNew();
+
+ ComplexWriterImpl newWriter = new ComplexWriterImpl(EMPTY_SCHEMA_PATH, container);
+
+ MapWriter newMapWriter = newWriter.rootAsMap();
+
+ newMapWriter.start();
+
+ newMapWriter.setPosition(2);
+ newMapWriter.integer("A").writeInt(10);
+
+ Field childField = container.getField().getChildren().get(0).getChildren().get(0);
+ assertEquals("Child field should be union type: " + childField.getName(), Type.Union, childField.getType().getTypeType());
+
}
}
}