This is an automated email from the ASF dual-hosted git repository.

luoc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git


The following commit(s) were added to refs/heads/master by this push:
     new 80fa266  DRILL-8109: Hive storage plugin support reading parquet 
timestamp type with int64 logical type (#2431)
80fa266 is described below

commit 80fa2662ce207a75e7822b7e5de816cd2c6461ce
Author: Thinking Chen <[email protected]>
AuthorDate: Wed Feb 2 17:34:47 2022 +0800

    DRILL-8109: Hive storage plugin support reading parquet timestamp type with 
int64 logical type (#2431)
---
 .../writers/primitive/HiveTimestampWriter.java     | 14 +++-
 .../exec/store/hive/data/TestHiveDataWriter.java   | 86 ++++++++++++++++++++++
 2 files changed, 96 insertions(+), 4 deletions(-)

diff --git 
a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/writers/primitive/HiveTimestampWriter.java
 
b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/writers/primitive/HiveTimestampWriter.java
index 72108c5..9ce829b 100644
--- 
a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/writers/primitive/HiveTimestampWriter.java
+++ 
b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/writers/primitive/HiveTimestampWriter.java
@@ -20,7 +20,9 @@ package org.apache.drill.exec.store.hive.writers.primitive;
 import org.apache.drill.exec.vector.complex.writer.TimeStampWriter;
 import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
 import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+import org.apache.hadoop.io.LongWritable;
 import org.joda.time.DateTime;
+import org.joda.time.DateTimeConstants;
 import org.joda.time.DateTimeZone;
 
 import java.sql.Timestamp;
@@ -33,10 +35,14 @@ public class HiveTimestampWriter extends 
AbstractSingleValueWriter<PrimitiveObje
 
   @Override
   public void write(Object value) {
-    String timestampString = PrimitiveObjectInspectorUtils.getString(value, 
inspector);
-    long timestampMillis = new 
DateTime(Timestamp.valueOf(timestampString).getTime())
-        .withZoneRetainFields(DateTimeZone.UTC).getMillis();
-    writer.writeTimeStamp(timestampMillis);
+    if (value instanceof LongWritable) {
+      writer.writeTimeStamp(((LongWritable) value).get() / 
DateTimeConstants.MILLIS_PER_SECOND);
+    } else {
+      String timestampString = PrimitiveObjectInspectorUtils.getString(value, 
inspector);
+      long timestampMillis = new 
DateTime(Timestamp.valueOf(timestampString).getTime())
+          .withZoneRetainFields(DateTimeZone.UTC).getMillis();
+      writer.writeTimeStamp(timestampMillis);
+    }
   }
 
 }
diff --git 
a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/data/TestHiveDataWriter.java
 
b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/data/TestHiveDataWriter.java
new file mode 100644
index 0000000..5243fb2
--- /dev/null
+++ 
b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/data/TestHiveDataWriter.java
@@ -0,0 +1,86 @@
+/*
+ * 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.drill.exec.store.hive.data;
+
+import org.apache.drill.exec.expr.holders.TimeStampHolder;
+import org.apache.drill.exec.store.hive.writers.primitive.HiveTimestampWriter;
+import org.apache.drill.exec.vector.complex.writer.FieldWriter;
+import org.apache.drill.exec.vector.complex.writer.TimeStampWriter;
+import org.apache.hadoop.hive.common.type.Timestamp;
+import org.apache.hadoop.hive.serde2.io.TimestampWritableV2;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableTimestampObjectInspector;
+import org.apache.hadoop.io.LongWritable;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestHiveDataWriter {
+
+  @Test
+  public void testTimestampWriter() {
+    TestTimeStampWriter testWriter = new TestTimeStampWriter();
+    HiveTimestampWriter writer = new HiveTimestampWriter(new 
WritableTimestampObjectInspector(), testWriter);
+    long testLong = 1643341736000L;// parquet long logical-type TIMESTAMP_MICRO
+    long expectedLong = 1643341736L;
+
+    // test long value
+    writer.write(new LongWritable(testLong));
+    assertEquals(testWriter.getTimestamp(), expectedLong);
+
+    // test timestampV2 value
+    Timestamp ht = new Timestamp();
+    ht.setTimeInMillis(testWriter.getTimestamp());
+    TimestampWritableV2 tw2 = new TimestampWritableV2(ht);
+    writer.write(tw2);
+    assertEquals(testWriter.getTimestamp(), expectedLong);
+  }
+}
+
+class TestTimeStampWriter implements TimeStampWriter {
+
+  private long timestamp;
+
+  @Override
+  public void write(TimeStampHolder h) { }
+
+  @Override
+  public void writeTimeStamp(long value) {
+    this.timestamp = value;
+  }
+
+  public long getTimestamp() {
+    return timestamp;
+  }
+
+  @Override
+  public FieldWriter getParent() {
+    return null;
+  }
+
+  @Override
+  public int getValueCapacity() {
+    return 0;
+  }
+
+  @Override
+  public void close() throws Exception { }
+
+  @Override
+  public void setPosition(int index) { }
+}

Reply via email to