[
https://issues.apache.org/jira/browse/CALCITE-1478?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15623159#comment-15623159
]
Julian Hyde commented on CALCITE-1478:
--------------------------------------
I think {{datetime - interval}} (e.g. {{DATE '1998-12-01' - INTERVAL '108'
DAY(3)}}) should be represented as a {{SqlMonotonicBinaryOperator}}. It doesn't
need a third argument, because it is clear what the result type should be: the
same as the {{datetime}}.
When you subtract two datetime values, the result is an interval, and you
always have to specify the units of the interval: {{(datetime - datetime)
intervalType}} (e.g. {{(DATE '1998-12-01' - DATE '1998-06-01') MONTH}}), so
this should be a {{SqlDatetimeSubtractionOperator}} with 3 arguments.
Hope this clarifies.
> SqlDatetimeSubtractionOperator unparse error.
> ---------------------------------------------
>
> Key: CALCITE-1478
> URL: https://issues.apache.org/jira/browse/CALCITE-1478
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.11.0
> Reporter: Dongming Liu
> Assignee: Julian Hyde
>
> The expression _date '1998-12-01' - interval '108' day(3)_ parse to SqlNode
> its operator is *SqlMonotonicBinaryOperator*, when convert it to RelNode, its
> operator is *SqlDatetimeSubtractionOperator*. When I use *RelToSqlConverter*
> to convert the RelNode to SqlNode, its operator is also
> *SqlDatetimeSubtractionOperator*. Now,
> *sqlNode.toSqlString(sqlDialect).getSql()* has a *IndexOutOfBoundsException*.
> The source code as follows:
> {code}
> final SqlWriter.Frame frame = writer.startList("(", ")");
> call.operand(0).unparse(writer, leftPrec, rightPrec);
> writer.sep("-");
> call.operand(1).unparse(writer, leftPrec, rightPrec);
> writer.endList(frame);
> call.operand(2).unparse(writer, leftPrec, rightPrec);
> {code}
> *SqlDatetimeSubtractionOperator* must have three operands, now it only has
> two operands.
> The following code convert SqlMonotonicBinaryOperator to
> SqlDatetimeSubtractionOperator,
> {code}
> registerOp(SqlStdOperatorTable.MINUS,
> new SqlRexConvertlet() {
> public RexNode convertCall(SqlRexContext cx, SqlCall call) {
> final RexCall e =
> (RexCall) StandardConvertletTable.this.convertCall(cx, call,
> call.getOperator());
> switch (e.getOperands().get(0).getType().getSqlTypeName()) {
> case DATE:
> case TIME:
> case TIMESTAMP:
> return convertDatetimeMinus(cx,
> SqlStdOperatorTable.MINUS_DATE, call);
> default:
> return e;
> }
> }
> });
> {code}
> For _date '1998-12-01' - interval '108' day(3)_, this converter is OK? It
> only has two operands.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)