julianhyde commented on code in PR #3714:
URL: https://github.com/apache/calcite/pull/3714#discussion_r1511756364
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -2161,9 +2161,12 @@ private static RelDataType
deriveTypeMapFromEntries(SqlOperatorBinding opBinding
public static final SqlFunction POW =
SqlStdOperatorTable.POWER.withName("POW");
+ /** The "TRUNC(numeric1 [, integer2])" function. Identical to the standard
<code>TRUNCATE</code>
+ * function except the return type should be a double if numeric1 is an
integer. */
@LibraryOperator(libraries = {BIG_QUERY})
- public static final SqlFunction TRUNC =
- SqlStdOperatorTable.TRUNCATE.withName("TRUNC");
+ public static final SqlFunction TRUNC = SqlStdOperatorTable.TRUNCATE
Review Comment:
Consider renaming the function to TRUNC_BIG_QUERY. The BigQuery FLOOR and
TRUNC functions are now in sync, but need to remain so, and linking their names
will make that more likely.
In Jira please link to CALCITE-5747. That's where these came adrift in the
first place.
##########
core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java:
##########
@@ -550,12 +550,12 @@ public static SqlCall stripSeparator(SqlCall call) {
*/
public static final SqlReturnTypeInference ARG0_EXCEPT_INTEGER = opBinding
-> {
RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
- SqlTypeName op = opBinding.getOperandType(0).getSqlTypeName();
- if (SqlTypeName.INT_TYPES.contains(op)) {
+ RelDataType op = opBinding.getOperandType(0);
Review Comment:
`op` is no longer a good name for this variable
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -592,6 +592,20 @@ private static String toSql(RelNode root, SqlDialect
dialect,
+ "created_thing\nFROM foodmart.product");
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6290">[CALCITE-6290]
+ * Incorrect return type for BigQuery TRUNC</a>. */
+ @Test void testBigQueryTruncPreservesCast() {
+ final String query = "SELECT CAST(TRUNC(3) AS BIGINT) "
+ + "as created_thing\n FROM `foodmart`.`product`";
Review Comment:
add line break after `\n`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]