You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/01/26 22:53:18 UTC

[GitHub] [arrow] BryanCutler commented on a change in pull request #9151: ARROW-11173: [Java] Add map type in complex reader / writer

BryanCutler commented on a change in pull request #9151:
URL: https://github.com/apache/arrow/pull/9151#discussion_r564772738



##########
File path: java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
##########
@@ -144,6 +179,16 @@ public ListWriter list() {
     return getWriter(MinorType.LIST).list();
   }
 
+  @Override
+  public MapWriter map() {
+    return getWriter(MinorType.LIST).map();
+  }
+
+  @Override
+  public MapWriter map(boolean keysSorted) {
+    return getWriter(MinorType.MAP, new org.apache.arrow.vector.types.pojo.ArrowType.Map(keysSorted));

Review comment:
       you should just be able to do `ArrowType.Map(keysSorted)`, it's imported already 

##########
File path: java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
##########
@@ -44,7 +44,11 @@
    * @param type the type of the values we want to write

Review comment:
       Could you remove the imports from line 21 and above while we are here, they aren't used.
   https://github.com/apache/arrow/pull/9151/files#diff-d8951dca853745d4e19fc70856ff955b02ffe333cdcd34bb2ce02c1c83c4f1fcR21

##########
File path: java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java
##########
@@ -546,6 +548,54 @@ private void checkUnionList(ListVector listVector) {
     }
   }
 
+  @Test
+  public void testListMapType() {
+    try (ListVector listVector = ListVector.empty("list", allocator)) {
+      listVector.allocateNew();
+      UnionListWriter listWriter = new UnionListWriter(listVector);
+      MapWriter innerMapWriter = listWriter.map(true);

Review comment:
       can you verify the final vector has attribute `keysSorted` to `true`?

##########
File path: java/vector/src/main/codegen/templates/UnionWriter.java
##########
@@ -110,6 +143,26 @@ public ListWriter asList() {
     return getListWriter();
   }
 
+  private MapWriter getMapWriter() {
+    // returns existing writer
+    Preconditions.checkNotNull(mapWriter);

Review comment:
       Should this also create a writer if there is no existing?

##########
File path: java/vector/src/main/codegen/templates/UnionFixedSizeListWriter.java
##########
@@ -169,6 +169,29 @@ public StructWriter struct(String name) {
     return structWriter;
   }
 
+  @Override
+  public MapWriter map() {
+    return writer;
+  }
+
+  @Override
+  public MapWriter map(String name) {
+    MapWriter mapWriter = writer.map(name);
+    return mapWriter;
+  }
+
+  @Override
+  public MapWriter map(boolean keysSorted) {
+    writer.map(keysSorted);

Review comment:
       should be this ?
   
   ```Java
   MapWriter mapWriter = writer.map(keysSorted);
   return mapWriter;
   ```

##########
File path: java/vector/src/main/codegen/templates/StructWriters.java
##########
@@ -184,6 +189,44 @@ public ListWriter list(String name) {
     return writer;
   }
 
+  @Override
+  public MapWriter map(String name) {
+    // returns existing writer
+    final FieldWriter writer = fields.get(handleCase(name));
+    Preconditions.checkNotNull(writer);
+    return writer;
+  }
+
+  @Override
+  public MapWriter map(String name, boolean keysSorted) {
+    FieldWriter writer = fields.get(handleCase(name));
+    if(writer == null) {
+      ValueVector vector;
+      ValueVector currentVector = container.getChild(name);
+      MapVector v = container.addOrGet(name,
+          new FieldType(addVectorAsNullable,
+            new org.apache.arrow.vector.types.pojo.ArrowType.Map(keysSorted)

Review comment:
       can use `ArrowType.Map`

##########
File path: java/vector/src/main/codegen/templates/UnionListWriter.java
##########
@@ -176,6 +176,29 @@ public StructWriter struct(String name) {
     return structWriter;
   }
 
+  @Override
+  public MapWriter map() {
+    return writer;
+  }
+
+  @Override
+  public MapWriter map(String name) {
+    MapWriter mapWriter = writer.map(name);
+    return mapWriter;
+  }
+
+  @Override
+  public MapWriter map(boolean keysSorted) {
+    writer.map(keysSorted);

Review comment:
       same here, return the new `mapWriter`?

##########
File path: java/vector/src/main/codegen/templates/StructWriters.java
##########
@@ -184,6 +189,44 @@ public ListWriter list(String name) {
     return writer;
   }
 
+  @Override
+  public MapWriter map(String name) {
+    // returns existing writer
+    final FieldWriter writer = fields.get(handleCase(name));
+    Preconditions.checkNotNull(writer);

Review comment:
       why this precondition? It seems other places it will create a writer if NULL?

##########
File path: java/vector/src/main/codegen/templates/StructWriters.java
##########
@@ -64,6 +64,11 @@
       case LIST:
         list(child.getName());
         break;
+      case MAP:{
+        org.apache.arrow.vector.types.pojo.ArrowType.Map arrowType = (org.apache.arrow.vector.types.pojo.ArrowType.Map) child.getType();

Review comment:
       Should be able to use `ArrowType.Map`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org