calcite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dongming Liu (JIRA)" <>
Subject [jira] [Created] (CALCITE-1478) SqlDatetimeSubtractionOperator unparse error.
Date Mon, 31 Oct 2016 05:34:58 GMT
Dongming Liu created CALCITE-1478:

             Summary: SqlDatetimeSubtractionOperator unparse error.
                 Key: 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:

 final SqlWriter.Frame frame = writer.startList("(", ")");
    call.operand(0).unparse(writer, leftPrec, rightPrec);
    call.operand(1).unparse(writer, leftPrec, rightPrec);
    call.operand(2).unparse(writer, leftPrec, rightPrec);

*SqlDatetimeSubtractionOperator* must have three operands, now it only has two operands.

The following code convert SqlMonotonicBinaryOperator to SqlDatetimeSubtractionOperator,

        new SqlRexConvertlet() {
          public RexNode convertCall(SqlRexContext cx, SqlCall call) {
            final RexCall e =
                (RexCall) StandardConvertletTable.this.convertCall(cx, call,
            switch (e.getOperands().get(0).getType().getSqlTypeName()) {
            case DATE:
            case TIME:
            case TIMESTAMP:
                return convertDatetimeMinus(cx, SqlStdOperatorTable.MINUS_DATE, call);
              return e;

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

View raw message