You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2019/04/01 17:45:14 UTC

[GitHub] [incubator-iceberg] edgarRd commented on a change in pull request #139: ORC support integration for Spark 2.4.0

edgarRd commented on a change in pull request #139: ORC support integration for Spark 2.4.0
URL: https://github.com/apache/incubator-iceberg/pull/139#discussion_r270978665
 
 

 ##########
 File path: spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcReader.java
 ##########
 @@ -0,0 +1,823 @@
+/*
+ * Copyright 2018 Hortonworks
+ *
+ * Licensed 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.iceberg.spark.data;
+
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.orc.ColumnIdMap;
+import org.apache.iceberg.orc.ORC;
+import org.apache.iceberg.orc.OrcIterator;
+import org.apache.iceberg.orc.TypeConversion;
+import org.apache.orc.TypeDescription;
+import org.apache.orc.storage.common.type.FastHiveDecimal;
+import org.apache.orc.storage.ql.exec.vector.BytesColumnVector;
+import org.apache.orc.storage.ql.exec.vector.ColumnVector;
+import org.apache.orc.storage.ql.exec.vector.DecimalColumnVector;
+import org.apache.orc.storage.ql.exec.vector.DoubleColumnVector;
+import org.apache.orc.storage.ql.exec.vector.ListColumnVector;
+import org.apache.orc.storage.ql.exec.vector.LongColumnVector;
+import org.apache.orc.storage.ql.exec.vector.MapColumnVector;
+import org.apache.orc.storage.ql.exec.vector.StructColumnVector;
+import org.apache.orc.storage.ql.exec.vector.TimestampColumnVector;
+import org.apache.orc.storage.ql.exec.vector.VectorizedRowBatch;
+import org.apache.orc.storage.serde2.io.DateWritable;
+import org.apache.orc.storage.serde2.io.HiveDecimalWritable;
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.catalyst.expressions.SpecializedGetters;
+import org.apache.spark.sql.catalyst.expressions.UnsafeRow;
+import org.apache.spark.sql.catalyst.expressions.codegen.UnsafeArrayWriter;
+import org.apache.spark.sql.catalyst.expressions.codegen.UnsafeRowWriter;
+import org.apache.spark.sql.catalyst.expressions.codegen.UnsafeWriter;
+import org.apache.spark.sql.catalyst.util.ArrayData;
+import org.apache.spark.sql.catalyst.util.MapData;
+import org.apache.spark.sql.types.Decimal;
+import org.apache.spark.unsafe.Platform;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Converts the OrcInterator, which returns ORC's VectorizedRowBatch to a
+ * set of Spark's UnsafeRows.
+ *
+ * It minimizes allocations by reusing most of the objects in the implementation.
+ */
+public class SparkOrcReader implements Iterator<InternalRow>, Closeable {
+  private final static int INITIAL_SIZE = 128 * 1024;
+  private final OrcIterator reader;
+  private final UnsafeRowWriter writer;
+  private int nextRow = 0;
+  private VectorizedRowBatch current = null;
+  private Converter[] converter;
+
+  public SparkOrcReader(InputFile location,
+                        FileScanTask task,
+                        Schema readSchema) {
+    ColumnIdMap columnIds = new ColumnIdMap();
+    TypeDescription orcSchema = TypeConversion.toOrc(readSchema, columnIds);
+    reader = ORC.read(location)
+        .split(task.start(), task.length())
+        .schema(readSchema)
+        .build();
+    int numFields = readSchema.columns().size();
+    writer = new UnsafeRowWriter(numFields, INITIAL_SIZE);
+    converter = new Converter[numFields];
+    for(int c = 0; c < numFields; ++c) {
+      converter[c] = buildConverter(writer, orcSchema.getChildren().get(c));
+    }
+  }
+
+  @Override
+  public boolean hasNext() {
+    return (current != null && nextRow < current.size) || reader.hasNext();
+  }
+
+  @Override
+  public UnsafeRow next() {
+    if (current == null || nextRow >= current.size) {
+      current = reader.next();
+      nextRow = 0;
+    }
+
+    writer.reset();
+    writer.zeroOutNullBytes();
+    for(int c=0; c < current.cols.length; ++c) {
+      converter[c].convert(writer, c, current.cols[c], nextRow);
+    }
+    nextRow++;
+    return writer.getRow();
+  }
+
+  @Override
+  public void close() throws IOException {
+    reader.close();
+  }
+
+  private static void printRow(SpecializedGetters row, TypeDescription schema) {
 
 Review comment:
   Yeah, I agree with you. Since this code was already merged in the Netflix repo: https://github.com/Netflix/iceberg/blob/master/spark/src/main/java/com/netflix/iceberg/spark/data/SparkOrcReader.java#L122 and https://github.com/Netflix/iceberg/blob/master/spark/src/main/java/com/netflix/iceberg/spark/data/SparkOrcReader.java#L135 I assumed it was alright, but I should've check before again. Thanks for caching this, I'll remove any print statements.

----------------------------------------------------------------
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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org