[ 
https://issues.apache.org/jira/browse/DRILL-7254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16948403#comment-16948403
 ] 

ASF GitHub Bot commented on DRILL-7254:
---------------------------------------

arina-ielchiieva commented on pull request #1869: DRILL-7254: Read Hive union 
w/o nulls
URL: https://github.com/apache/drill/pull/1869#discussion_r333448242
 
 

 ##########
 File path: exec/vector/src/main/codegen/templates/UnionVectorListWriter.java
 ##########
 @@ -0,0 +1,212 @@
+/*
+ * 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.
+ */
+
+import org.apache.drill.exec.vector.complex.DictVector;
+import org.apache.drill.exec.vector.complex.ListVector;
+import org.apache.drill.exec.vector.complex.MapVector;
+import org.apache.drill.exec.vector.complex.impl.UnionVectorWriter;
+import org.apache.drill.exec.vector.complex.writer.FieldWriter;
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile 
name="/org/apache/drill/exec/vector/complex/impl/UnionVectorListWriter.java" />
+<#include "/@includes/license.ftl" />
+package org.apache.drill.exec.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.function.Function;
+
+/**
+ * Union vector writer for writing list of union-type values
+ */
+public class UnionVectorListWriter extends UnionVectorWriter {
+
+  private final ListVector listVector;
+  private final UInt4Vector offsets;
+  private int listPosition;
+
+  public UnionVectorListWriter(ListVector listVector, FieldWriter parent) {
+    super(listVector.promoteToUnion(), parent);
+    this.listVector = listVector;
+    this.offsets = listVector.getOffsetVector();
+  }
+
+  //===============================FACTORIES FOR COMPLEX TYPE 
WRITERS=============================================================
+
+  public UnionVectorWriter union() {
+    return this;
+  }
+
+  public MapWriter map() {
+    return typeWriters.computeIfAbsent(MinorType.MAP, type -> new 
SingleMapUnionListElementWriter(dataVector.getMap(), null, false));
+  }
+
+  public DictWriter dict() {
+    return typeWriters.computeIfAbsent(MinorType.DICT, type -> new 
SingleDictUnionListElementWriter(dataVector.getDict(), null, false));
+  }
+
+  public ListWriter list() {
+    return typeWriters.computeIfAbsent(MinorType.LIST, type -> new 
UnionListUnionElementWriter(dataVector.getList()));
+  }
+
+  //===============================FACTORIES FOR PRIMITIVE LIST ELEMENT 
WRITERS==============================================================
+<#list vv.types as type>
+  <#list type.minor as minor>
+    <#assign lowerName = minor.class?uncap_first />
+    <#assign upperName = minor.class?upper_case />
+    <#assign capName = minor.class?cap_first />
+    <#if lowerName == "int" >
+      <#assign lowerName = "integer" />
+    </#if>
+    <#if !minor.class?starts_with("Decimal")>
+
+  @Override
+  public ${capName}Writer ${lowerName}() {
+    return typeWriters.computeIfAbsent(MinorType.${upperName}, 
${capName}UnionListElementWriter::new);
+  }
+      <#if minor.class == "VarDecimal">
+
+  @Override
+  public ${capName}Writer ${lowerName}(int precision, int scale) {
+    return typeWriters.computeIfAbsent(MinorType.${upperName}, type -> new 
${capName}UnionListElementWriter(type, precision, scale));
+  }
+      </#if>
+    </#if>
+  </#list>
+</#list>
+
+  //===============================WRITER's 
METHODS=====================================================================
+  /**
+   * Since this class is extension of list's data vector writer, index in 
parent writer is
+   * and index in list vector are now different. Parent writer's index is now 
based on list
+   * offsets and current writer index point to index of list inside list 
vector.
 
 Review comment:
   Looks much better.
 
----------------------------------------------------------------
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:
us...@infra.apache.org


> Read Hive union w/o nulls
> -------------------------
>
>                 Key: DRILL-7254
>                 URL: https://issues.apache.org/jira/browse/DRILL-7254
>             Project: Apache Drill
>          Issue Type: Sub-task
>            Reporter: Igor Guzenko
>            Assignee: Igor Guzenko
>            Priority: Major
>              Labels: doc-impacting
>             Fix For: 1.17.0
>
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to