You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kylin.apache.org by "zhong.zhu (Jira)" <ji...@apache.org> on 2023/12/11 03:25:00 UTC

[jira] [Commented] (KYLIN-5738) Query support using '+' to concatenate strings

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

zhong.zhu commented on KYLIN-5738:
----------------------------------

h1. Root Cause
 # String concatenation of constants, such as 'A' + '_' + 'B', will be rewritten in sql validate phase due to CALCITE-1924 changes
'A' || '_' || 'B', after toRel conversion is completed, the type before and after conversion will be compared. The type before conversion is inferred by + sign, and the type after conversion is inferred by ||. some previous issues has changed the type inference logic of + sign. The result of the former is char(1), the latter is char(3). !image-2023-12-11-11-19-24-736.png!
 # For the addition of String and numeric constants such as '123' + 256, constant folding will be attempted during sql optimization, and then an error will be reported that the plus(String, Integer) method cannot be found
 # For very large string concatenation, such as cast(a as string) + cast(b as string), calcite will not convert or report errors, the default logic of saprk will be used, and the string will be converted into numbers and then added !image-2023-12-11-11-24-05-314.png!

> Query support using '+' to concatenate strings
> ----------------------------------------------
>
>                 Key: KYLIN-5738
>                 URL: https://issues.apache.org/jira/browse/KYLIN-5738
>             Project: Kylin
>          Issue Type: Bug
>    Affects Versions: 5.0-beta
>            Reporter: zhong.zhu
>            Assignee: zhong.zhu
>            Priority: Critical
>             Fix For: 5.0.0
>
>         Attachments: image-2023-12-11-11-19-24-736.png, image-2023-12-11-11-24-05-314.png
>
>
> Many queries of the client's mobile reports are SQL queries with + concatenated strings. The client does not agree with the SQL transformation of the front-end reports and hopes that KYLIN 4.X is forward compatible with this function.
> For example:
> Both the company and first_deptname fields are of type varchar(4096)
> Case one:
> SELECT company + '-' + first_deptname FROM Table name
>  
> _KYLIN 4 Query Result with Exception:_
> _Conversion to relational algebra failed to preserve datatypes:_
> _validated type:_
> _RecordType(CHAR(1) CHARACTER SET "UTF-16LE" COLLATE "UTF-16LE$en_US$primary" NOT NULL EXPR$0) NOT NULL_
> _converted type:_
> _RecordType(CHAR(3) CHARACTER SET "UTF-16LE" COLLATE "UTF-16LE$en_US$primary" NOT NULL EXPR$0) NOT NULL_
> _rel:_
> _LogicalSort(fetch=[500])_
> _LogicalProject(EXPR$0=[||(||('A', '_'), 'B')])
> KapTableScan(table=[[APP, A02_HR_ORGANIZATION_TALENT_CHAIN]], ctx=[], fields=
>  
> In KYLIN 3.x, the query result is right: company-deptname



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