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

Feng Zhu commented on CALCITE-3864:
-----------------------------------

Hi, [~winipanda], thanks for your investigation. CONCAT_FUNCTION is introduced 
in CALCITE-3235.

>From my understanding, you want to address the following three problems.

(1) *AssertionError* in return type inference for some cases, e.g.,
{code:java}
@Test public void testQuery() throws SQLException {
  final String sql = "select concat(cast('a' as varchar), cast('b' as 
varchar),cast('c' as varchar))";
  CalciteAssert.that()
      .with(CalciteConnectionProperty.FUN, "mysql")
      .query(sql)
      .returns("abc");
}
{code}
The full stacktrace is posted in your description.

(2) *IllegalStateException* because the function is not implemented in runtime.
{code:java}
@Test public void testQuery() throws SQLException {
  final String sql = "select concat('a', 'b', 'c')";
  CalciteAssert.that()
      .with(CalciteConnectionProperty.FUN, "mysql")
      .query(sql)
      .returns("abc");
}
{code}
The stacktrace is:
{code:java}
Suppressed: java.lang.RuntimeException: cannot translate call CONCAT($t1, $t2, 
$t3)
    at 
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translateCall(RexToLixTranslator.java:763)
    at 
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translate0(RexToLixTranslator.java:737)
    at 
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translate(RexToLixTranslator.java:208)
    at 
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translate0(RexToLixTranslator.java:691)
    at 
org.apache.calcite.adapter.enumerable.RexToLixTranslator.translate(RexToLixTranslator.java:208)
{code}
(3) *Unparse* logic for dialect like MySQL.

> Add Implementation for SqlLibraryOperators.CONCAT_FUNCTION in SqlFunctions 
> and correct the return type inference of SqlLibraryOperators.CONCAT_FUNCTION
> -------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-3864
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3864
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: TANG Wen-hui
>            Assignee: TANG Wen-hui
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> Add the Implementation for SqlLibraryOperators.CONCAT_FUNCTION in 
> SqlFunctions rather than register it as a kind of || operator in 
> StandardConvertletTable, because it would be better for Jdbc adaptor to 
> generate CONCAT for mysql rather than || operator, since CONCAT in mysql is 
> not totally same as || operator.
> According to my test, as for PG ,the result of "concat('a', 'b', 'c')" is 
> equal to " 'a' || 'b' || 'c' " , which is 'abc', as for Mysql, the result of 
> "concat('a', 'b', 'c')" is 'abc', but the result of " 'a'||'b'|| 'c' " is 0, 
> as for oracle, concat only have two argument and the the result of 
> 'a'||'b'||'c' is 'abc'.
>  And the return type inference of SqlLibraryOperators.CONCAT_FUNCTION will 
> cause AssertionError when the precsion of its operands are not specified.
> {code:java}
> concat(cast('a' as varchar), cast('b' as varchar),cast('c' as varchar)){code}
> {code:java}
> at 
> org.apache.calcite.sql.type.SqlTypeFactoryImpl.createSqlType(SqlTypeFactoryImpl.java:64)at
>  
> org.apache.calcite.sql.type.SqlTypeFactoryImpl.createSqlType(SqlTypeFactoryImpl.java:64)
>  at 
> org.apache.calcite.sql.fun.SqlLibraryOperators.lambda$static$1(SqlLibraryOperators.java:291)
>  at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>  at org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:486) 
> at org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:453) 
> at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:321) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:218) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5858)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5845)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1800)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1785)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:260) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:423) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5552)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:116) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:259) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:423) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5552)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:116) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1059)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:766)
>  at 
> org.apache.calcite.sql.test.AbstractSqlTester.parseAndValidate(AbstractSqlTester.java:175)
>  at 
> org.apache.calcite.sql.test.AbstractSqlTester.getResultType(AbstractSqlTester.java:163)
>  at 
> org.apache.calcite.sql.test.AbstractSqlTester.getColumnType(AbstractSqlTester.java:155)
>  at 
> org.apache.calcite.sql.test.AbstractSqlTester.check(AbstractSqlTester.java:477)
>  at 
> org.apache.calcite.sql.test.SqlOperatorBaseTest$TesterImpl.check(SqlOperatorBaseTest.java:9489)
>  at 
> org.apache.calcite.sql.test.AbstractSqlTester.check(AbstractSqlTester.java:462)
>  at 
> org.apache.calcite.sql.test.AbstractSqlTester.checkString(AbstractSqlTester.java:447)
>  at 
> org.apache.calcite.sql.test.SqlOperatorBaseTest.testConcatOperator(SqlOperatorBaseTest.java:2184){code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to