vdiravka commented on a change in pull request #1527: DRILL-4456: Fix Hive translate UDF URL: https://github.com/apache/drill/pull/1527#discussion_r231862125
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillConvertletTable.java ########## @@ -61,13 +69,36 @@ } }; + // Custom convertlet to avoid rewriting TIMESTAMP_DIFF by Calcite. + private static final SqlRexConvertlet TIMESTAMP_DIFF_CONVERTLET = (cx, call) -> { + SqlLiteral unitLiteral = call.operand(0); + SqlIntervalQualifier qualifier = + new SqlIntervalQualifier(unitLiteral.symbolValue(TimeUnit.class), null, SqlParserPos.ZERO); + + List<RexNode> operands = Arrays.asList( + cx.convertExpression(qualifier), + cx.convertExpression(call.operand(1)), + cx.convertExpression(call.operand(2))); + + RelDataTypeFactory typeFactory = cx.getTypeFactory(); + + RelDataType returnType = typeFactory.createTypeWithNullability( + typeFactory.createSqlType(SqlTypeName.BIGINT), + cx.getValidator().getValidatedNodeType(call.operand(1)).isNullable() + || cx.getValidator().getValidatedNodeType(call.operand(2)).isNullable()); + + return cx.getRexBuilder().makeCall(returnType, + SqlStdOperatorTable.TIMESTAMP_DIFF, operands); + }; + static { // Use custom convertlet for EXTRACT function map.put(SqlStdOperatorTable.EXTRACT, DrillExtractConvertlet.INSTANCE); // SQRT needs it's own convertlet because calcite overrides it to POWER(x, 0.5) // which is not suitable for Infinity value case map.put(SqlStdOperatorTable.SQRT, SQRT_CONVERTLET); map.put(SqlStdOperatorTable.COALESCE, COALESCE_CONVERTLET); + map.put(SqlStdOperatorTable.TIMESTAMP_DIFF, TIMESTAMP_DIFF_CONVERTLET); Review comment: move the the string to the end of the block, since it is a last added `SqlFunction` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services