[ 
https://issues.apache.org/jira/browse/CALCITE-2854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16776583#comment-16776583
 ] 

Hongze Zhang commented on CALCITE-2854:
---------------------------------------

[~hhlai1990], I do think the patch can solve the current issue.

But technically speaking, there could be opportunity that users/developers 
might custom the SQL-to-Rel converting progress, e.g. they can remove the 
convertlet for UNARY_PLUS, then the same issue will happen on UNARY_PLUS too.
I think you will receive an error when you run the case below:

{code:java}
try {
  Method method = 
ReflectiveConvertletTable.class.getDeclaredMethod("registerOp",
      SqlOperator.class, SqlRexConvertlet.class);
  method.setAccessible(true);
  method.invoke(StandardConvertletTable.INSTANCE, 
SqlStdOperatorTable.UNARY_PLUS, null);
} catch (Exception e) {
  Assert.fail();
}

final CalciteAssert.AssertThat with =
    CalciteAssert.that().withSchema("s", CATCHALL);
with.query("select + \"decimal\" from \"s\".\"everyTypes\"")
    .returnsUnordered(
        "EXPR$0=-1\n"
            + "EXPR$0=1.2");
{code}



> code gen error for UNARY_MINUS operator call with decimal type operands
> -----------------------------------------------------------------------
>
>                 Key: CALCITE-2854
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2854
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.18.0
>            Reporter: Lai Zhou
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> case:
> {code:java}
>   @Test public void test() throws Exception {
>     final String cr = "create table t (a DECIMAL)";
>     final String se = "select -a as aa from t";
>     Connection c = connect();
>     Statement s = c.createStatement();
>     s.execute(cr);
>     s.executeQuery(se);
>   }
> {code}
> error msg: 
> {code:java}
> Caused by: org.codehaus.commons.compiler.CompileException: Line 21, Column 
> 71: Object of type "java.math.BigDecimal" cannot be converted to a numeric 
> type
> {code}
> {code:java}
> public Object current() {
> final java.math.BigDecimal current = inputEnumerator.current() == null ? 
> (java.math.BigDecimal) null : 
> org.apache.calcite.runtime.SqlFunctions.toBigDecimal(inputEnumerator.current());
> return current == null ? (java.math.BigDecimal) null : - current;
> }
> {code}
> `- current` is not right ,we'd better constructor a new BigDecimal object to 
> to replace this code snippet,like 
> {code:java}
> return current == null ? (java.math.BigDecimal) null : 
> SqlFunctions.negativeDecimal(current);
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to