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

ASF GitHub Bot commented on KYLIN-5359:
---------------------------------------

Mukvin commented on PR #2045:
URL: https://github.com/apache/kylin/pull/2045#issuecomment-1365631225

   LGTM




> Kylin4 replace function expression convert error
> ------------------------------------------------
>
>                 Key: KYLIN-5359
>                 URL: https://issues.apache.org/jira/browse/KYLIN-5359
>             Project: Kylin
>          Issue Type: Bug
>          Components: Query Engine
>    Affects Versions: v4.0.1, v4.0.2
>            Reporter: Liu Zhao
>            Assignee: Liu Zhao
>            Priority: Major
>         Attachments: image-2022-12-12-11-25-32-037.png, 
> image-2022-12-12-11-25-41-178.png
>
>
> 查询语句形如:select name, replace(name, substring(name, 1, 1), '--') as new_name 
> from LZ_TEST_YUFA 执行出错
> errorMsg:java.lang.ClassCastException: org.apache.spark.sql.Column cannot be 
> cast to java.lang.String while executing SQL: "select * from (select name, 
> replace(name, substring(name, 1, 1), '--') as new_name from LZ_TEST_YUFA) 
> limit 50000
> 原因:在ExpressionConverter中subtring返回的是一个column对象,而在replace转换中强制将函数参数转换为string
> {code:java}
> // ExpressionConverter
> case "replace " =>
>       regexp_replace(k_lit(children.head),
>         {color:red}children.apply(1).asInstanceOf[String],
>         children.apply(2).asInstanceOf[String]{color})
> case "substring" | "substr" =>
>       if (children.length == 3) { //substr(str1,startPos,length)
>        {color:red} k_lit(children.head)
>               .substr(k_lit(children.apply(1)), 
> k_lit(children.apply(2))){color}
>       } else if (children.length == 2) { //substr(str1,startPos)
>         k_lit(children.head).
>               substr(k_lit(children.apply(1)), k_lit(Int.MaxValue))
>       } else {
>         throw new UnsupportedOperationException(
>               s"substring must provide three or two parameters under sparder")
>       }
> case "initcapb" =>
>       initcap(k_lit(children.head))
> {code}
>  !image-2022-12-12-11-25-32-037.png! 
>  !image-2022-12-12-11-25-41-178.png! 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to