[ 
https://issues.apache.org/jira/browse/HIVE-27157?focusedWorklogId=852328&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-852328
 ]

ASF GitHub Bot logged work on HIVE-27157:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Mar/23 17:48
            Start Date: 22/Mar/23 17:48
    Worklog Time Spent: 10m 
      Work Description: zabetak commented on code in PR #4135:
URL: https://github.com/apache/hive/pull/4135#discussion_r1145203540


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveToUnixTimestampSqlOperator.java:
##########
@@ -18,15 +18,24 @@
 
 package org.apache.hadoop.hive.ql.optimizer.calcite.reloperators;
 
-import org.apache.calcite.sql.fun.SqlAbstractTimeFunction;
-import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.SqlFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
 
 /**
  * Sql UNIX_TIMESTAMP calcite operator.
  */
-public class HiveToUnixTimestampSqlOperator extends SqlAbstractTimeFunction {
-  public static final HiveToUnixTimestampSqlOperator INSTANCE = new 
HiveToUnixTimestampSqlOperator();
-  protected HiveToUnixTimestampSqlOperator() {
-    super("UNIX_TIMESTAMP", SqlTypeName.BIGINT);
-  }
+public class HiveToUnixTimestampSqlOperator {
+  public static final SqlFunction INSTANCE =
+      new SqlFunction("UNIX_TIMESTAMP", SqlKind.OTHER_FUNCTION, 
ReturnTypes.BIGINT, null,
+          OperandTypes.or(OperandTypes.NILADIC,
+              OperandTypes.or(OperandTypes.STRING, OperandTypes.TIMESTAMP, 
OperandTypes.DATE),
+              OperandTypes.STRING_STRING), SqlFunctionCategory.NUMERIC) {
+        @Override
+        public boolean isDynamicFunction() {
+          return true;
+        }

Review Comment:
   It was the same before and it remains the same now. Ultimately, I would like 
to get rid one of them completely but it was not trivial to do now (correlation 
with code in Druid storage handler) thus in order to keep the PR minimal I 
decided to defer this to HIVE-27162.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 852328)
    Time Spent: 50m  (was: 40m)

> AssertionError when inferring return type for unix_timestamp function
> ---------------------------------------------------------------------
>
>                 Key: HIVE-27157
>                 URL: https://issues.apache.org/jira/browse/HIVE-27157
>             Project: Hive
>          Issue Type: Bug
>          Components: CBO
>    Affects Versions: 4.0.0-alpha-2
>            Reporter: Stamatis Zampetakis
>            Assignee: Stamatis Zampetakis
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Any attempt to derive the return data type for the {{unix_timestamp}} 
> function results into the following assertion error.
> {noformat}
> java.lang.AssertionError: typeName.allowsPrecScale(true, false): BIGINT
>       at 
> org.apache.calcite.sql.type.BasicSqlType.checkPrecScale(BasicSqlType.java:65)
>       at org.apache.calcite.sql.type.BasicSqlType.<init>(BasicSqlType.java:81)
>       at 
> org.apache.calcite.sql.type.SqlTypeFactoryImpl.createSqlType(SqlTypeFactoryImpl.java:67)
>       at 
> org.apache.calcite.sql.fun.SqlAbstractTimeFunction.inferReturnType(SqlAbstractTimeFunction.java:78)
>       at 
> org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:278)
> {noformat}
> due to a faulty implementation of type inference for the respective operators:
>  * 
> [https://github.com/apache/hive/blob/52360151dc43904217e812efde1069d6225e9570/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveUnixTimestampSqlOperator.java]
>  * 
> [https://github.com/apache/hive/blob/52360151dc43904217e812efde1069d6225e9570/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveToUnixTimestampSqlOperator.java]
> Although at this stage in master it is not possible to reproduce the problem 
> with an actual SQL query the buggy implementation must be fixed since slight 
> changes in the code/CBO rules may lead to methods relying on 
> {{{}SqlOperator.inferReturnType{}}}.
> Note that in older versions of Hive it is possible to hit the AssertionError 
> in various ways. For example in Hive 3.1.3 (and older), the error may come 
> from 
> [HiveRelDecorrelator|https://github.com/apache/hive/blob/4df4d75bf1e16fe0af75aad0b4179c34c07fc975/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java#L1933]
>  in the presence of sub-queries.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to