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

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


The following commit(s) were added to refs/heads/master by this push:
     new 03fe61f0a76 HIVE-26989 Fix predicate pushdown for Timestamp with TZ 
(#3985)
03fe61f0a76 is described below

commit 03fe61f0a76dd77a085aa3a08bdc2b810d1382a4
Author: Ramesh Kumar <[email protected]>
AuthorDate: Thu Jan 26 10:58:49 2023 -0800

    HIVE-26989 Fix predicate pushdown for Timestamp with TZ (#3985)
    
    Ramesh Kumar reviewed by Ayush Saxena
---
 .../TestHiveIcebergStorageHandlerTimezone.java     | 24 ++++++++++++++++++++++
 .../hive/ql/io/sarg/ConvertAstToSearchArg.java     |  4 ++++
 2 files changed, 28 insertions(+)

diff --git 
a/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerTimezone.java
 
b/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerTimezone.java
index 122973fb362..865f0856411 100644
--- 
a/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerTimezone.java
+++ 
b/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerTimezone.java
@@ -23,6 +23,8 @@ import java.io.IOException;
 import java.text.DateFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
 import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
@@ -168,4 +170,26 @@ public class TestHiveIcebergStorageHandlerTimezone {
     result = shell.executeStatement("SELECT * FROM ts_test WHERE 
d_ts='2017-01-01 22:30:57.3'");
     Assert.assertEquals(0, result.size());
   }
+
+  @Test
+  public void testTimestampQueryWithTimeZone() throws IOException {
+    Schema timestampSchema = new Schema(optional(1, "d_ts", 
Types.TimestampType.withZone()));
+
+    List<Record> records = 
TestHelper.RecordsBuilder.newInstance(timestampSchema)
+        .add(OffsetDateTime.of(LocalDateTime.of(2019, 1, 22, 9, 44, 54, 
100000000), ZoneOffset.of("+00")))
+        .add(OffsetDateTime.of(LocalDateTime.of(2019, 2, 22, 9, 44, 54, 
200000000), ZoneOffset.of("+00")))
+        .build();
+
+    testTables.createTable(shell, "ts_test_tz", timestampSchema, 
FileFormat.PARQUET, records);
+
+    List<Object[]> result = shell.executeStatement("SELECT d_ts FROM 
ts_test_tz where d_ts='2019-02-22 09:44:54.200Z'");
+    Assert.assertEquals(1, result.size());
+    if (timezoneString.equals("America/New_York")) {
+      Assert.assertEquals("2019-02-22 04:44:54.2 " + timezoneString, 
result.get(0)[0]);
+    } else if (timezoneString.equals("Asia/Kolkata")) {
+      Assert.assertEquals("2019-02-22 15:14:54.2 " + timezoneString, 
result.get(0)[0]);
+    } else if (timezoneString.equals("GMT")) {
+      Assert.assertEquals("2019-02-22 09:44:54.2 " + timezoneString, 
result.get(0)[0]);
+    }
+  }
 }
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/ConvertAstToSearchArg.java 
b/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/ConvertAstToSearchArg.java
index 71bf6d7b5e6..d9d3ef653d9 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/ConvertAstToSearchArg.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/ConvertAstToSearchArg.java
@@ -29,6 +29,7 @@ import org.apache.commons.codec.binary.Base64;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hive.common.type.HiveChar;
 import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.common.type.TimestampTZ;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.ql.exec.SerializationUtilities;
 import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
@@ -138,6 +139,7 @@ public class ConvertAstToSearchArg {
         case DATE:
           return BoxType.DATE;
         case TIMESTAMP:
+        case TIMESTAMPLOCALTZ:
           return BoxType.TIMESTAMP;
         case DECIMAL:
           return BoxType.DECIMAL;
@@ -218,6 +220,8 @@ public class ConvertAstToSearchArg {
         } else if (lit instanceof 
org.apache.hadoop.hive.common.type.Timestamp) {
           ts = ((org.apache.hadoop.hive.common.type.Timestamp) lit)
               .toSqlTimestamp();
+        } else if (lit instanceof 
org.apache.hadoop.hive.common.type.TimestampTZ) {
+          ts =  
Timestamp.valueOf(((TimestampTZ)lit).getZonedDateTime().toLocalDateTime());
         } else {
           ts = 
org.apache.hadoop.hive.common.type.Timestamp.valueOf(lit.toString())
               .toSqlTimestamp();

Reply via email to