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

Shuiqiang Chen commented on FLINK-28882:
----------------------------------------

I have encountered the same problem in latest master branch (1.17-SNAPSHOT).
 !screenshot-1.png! 
We can see that the result type of Encode('kyuubi', 'UTF-8') call is BINARY(1). 
However, the type of RexLiteral `X'6b7975756269'` is BINARY(6)). According to 
[FLINK-24419 title|https://issues.apache.org/jira/browse/FLINK-24419]

{code:java}
    /* Example generated code for BINARY(2):

    // legacy behavior
    ((byte[])(inputValue))

    // new behavior
    ((((byte[])(inputValue)).length == 2) ? (((byte[])(inputValue))) : 
(java.util.Arrays.copyOf(((byte[])(inputValue)), 2)))

    */
{code}

The BINARY(6) is trimmed to BINARY(1) in BinaryToBinaryCastRule during the 
generation of cast call.

There are two optional solutions:
1. Apply the legacy cast behaviour with LegacyCastBehaviour.ENABLE in 
TableConfig when it is ENCODE call;
2. Make the output type of  `CAST(X'6b7975756269':BINARY(6)):BINARY(1)` to be 
BINARY(6) that equals to the type of RexLiteral `X'6b7975756269'`.


> ENCODE return error
> -------------------
>
>                 Key: FLINK-28882
>                 URL: https://issues.apache.org/jira/browse/FLINK-28882
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table SQL / API, Table SQL / Planner
>    Affects Versions: 1.15.0
>            Reporter: Luning Wang
>            Priority: Major
>         Attachments: screenshot-1.png
>
>
> Run the following in SQL Client, it will return 'k' rather than 'kyuubi' but 
> it returns 'kyuubi' in the 1.14 version.
> {code:java}
> select encode('kyuubi', 'UTF-8') {code}
>  



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

Reply via email to