You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "jackye1995 (via GitHub)" <gi...@apache.org> on 2023/04/03 06:10:34 UTC

[GitHub] [iceberg] jackye1995 commented on a diff in pull request #6962: Support vectorized reading int96 timestamps in imported data

jackye1995 commented on code in PR #6962:
URL: https://github.com/apache/iceberg/pull/6962#discussion_r1155515365


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/data/SparkParquetReaders.java:
##########
@@ -392,11 +391,7 @@ public Long read(Long ignored) {
     public long readLong() {
       final ByteBuffer byteBuffer =
           column.nextBinary().toByteBuffer().order(ByteOrder.LITTLE_ENDIAN);
-      final long timeOfDayNanos = byteBuffer.getLong();
-      final int julianDay = byteBuffer.getInt();
-
-      return TimeUnit.DAYS.toMicros(julianDay - UNIX_EPOCH_JULIAN)
-          + TimeUnit.NANOSECONDS.toMicros(timeOfDayNanos);
+      return TimestampUtil.extractTimestampInt96(byteBuffer);

Review Comment:
   thanks for the refactoring!



##########
spark/v3.3/spark/src/test/java/org/apache/iceberg/spark/source/TestIcebergSourceTablesBase.java:
##########
@@ -1763,6 +1771,71 @@ public void testAllManifestTableSnapshotFiltering() throws Exception {
     }
   }
 
+  @Test
+  public void testTableWithInt96Timestamp() throws IOException {
+    try {

Review Comment:
   Looks like we always have a `parquet_table` that might need to be dropped. We could add that to `@After` and do `DROP TABLE IF EXISTS`



##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/TimestampUtil.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+package org.apache.iceberg.arrow.vectorized.parquet;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.TimeUnit;
+
+public class TimestampUtil {
+
+  private TimestampUtil() {}
+
+  private static final long UNIX_EPOCH_JULIAN = 2_440_588L;
+
+  public static long extractTimestampInt96(ByteBuffer buffer) {

Review Comment:
   this feels like something that could live in `ParquetUtil`, instead of creating a new class?



##########
spark/v3.3/spark/src/test/java/org/apache/iceberg/spark/source/TestIcebergSourceHiveTables.java:
##########
@@ -43,11 +43,10 @@ public static void start() {
 
   @After
   public void dropTable() throws IOException {
-    Table table = catalog.loadTable(currentIdentifier);
-    Path tablePath = new Path(table.location());
-    FileSystem fs = tablePath.getFileSystem(spark.sessionState().newHadoopConf());
-    fs.delete(tablePath, true);
-    catalog.dropTable(currentIdentifier, false);
+    if (!catalog.tableExists(currentIdentifier)) {
+      return;
+    }
+    dropTable(currentIdentifier);

Review Comment:
   seems like the newline is not added? Overall we encourage newline after any logical blocks like if, for, while, try, etc.



##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/TimestampUtil.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+package org.apache.iceberg.arrow.vectorized.parquet;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.TimeUnit;
+
+public class TimestampUtil {
+
+  private TimestampUtil() {}
+
+  private static final long UNIX_EPOCH_JULIAN = 2_440_588L;
+
+  public static long extractTimestampInt96(ByteBuffer buffer) {

Review Comment:
   nit: add javadoc for public util method.



##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/GenericArrowVectorAccessorFactory.java:
##########
@@ -156,6 +158,8 @@ public ArrowVectorAccessor<DecimalT, Utf8StringT, ArrayT, ChildVectorT> getVecto
           return new DictionaryFloatAccessor<>((IntVector) vector, dictionary);
         case INT64:
           return new DictionaryLongAccessor<>((IntVector) vector, dictionary);
+        case INT96:
+          return new DictionaryTimestampInt96Accessor<>((IntVector) vector, dictionary);

Review Comment:
   we probably want to provide some historical contexts for INT96, maybe add a comment to link to https://issues.apache.org/jira/browse/PARQUET-323



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

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


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