[
https://issues.apache.org/jira/browse/CALCITE-3987?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17108777#comment-17108777
]
Drew Schmitt commented on CALCITE-3987:
---------------------------------------
Thanks Julian. I like the idea of going with the conformance approach. However,
I'm having difficulty figuring out how to make that work.
It looks like the SqlStdOperatorTable.PLUS operator is being assigned during
parsing here:
https://github.com/apache/calcite/blob/master/core/src/main/codegen/templates/Parser.jj#L6652
which is using the OperandTypes.PLUS_OPERATOR operand type checker here:
https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java#L542
So, my initial thought was to add something like DATE_NUMERIC and NUMERIC_DATE
to the PLUS_OPERATOR here:
https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java#L478
If we want to only enable this functionality for certain conformance values
(e.g. SqlConformanceEnum.BABEL), is the recommended approach to edit Parser.jj
to conditionally return a different operator at parsing time (instead of
SqlStdOperatorTable.PLUS) which supports numeric and date operands? Or is there
a way to replace/overload the PLUS operator with our own custom one that
supports numeric and date operands during the validation stage?
I came across OracleSqlOperatorTable, which looked like a promising model to
follow for a new class which extends ReflectiveSqlOperatorTable to support our
new PLUS operator. However, that appears to be deprecated.
Any recommendations would be greatly appreciated!
> Allow addition and subtraction operations between DATE and NUMERIC types.
> -------------------------------------------------------------------------
>
> Key: CALCITE-3987
> URL: https://issues.apache.org/jira/browse/CALCITE-3987
> Project: Calcite
> Issue Type: Improvement
> Reporter: Drew Schmitt
> Priority: Minor
>
> We should allow addition (PLUS operator) and subtraction (MINUS operator)
> between DATE and NUMERIC types to be valid during the validation phase.
> Downstream, the result of the operation can be interpreted differently
> depending on the dialect. For example, some dialects would interpret any
> arithmetic with a DATE as implying adding/subtracting a number of days.
> Example query:
> CREATE TABLE foo (bar DATE);
> SELECT bar - 1 FROM foo;
--
This message was sent by Atlassian Jira
(v8.3.4#803005)