You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Dongming Liu (JIRA)" <ji...@apache.org> on 2016/10/31 05:34:58 UTC

[jira] [Created] (CALCITE-1478) SqlDatetimeSubtractionOperator unparse error.

Dongming Liu created CALCITE-1478:
-------------------------------------

             Summary: 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)