You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Jing Zhang (Jira)" <ji...@apache.org> on 2022/11/22 11:08:00 UTC

[jira] [Commented] (FLINK-28741) Unexpected result if insert 'false' to boolean column

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

Jing Zhang commented on FLINK-28741:
------------------------------------

[~luoyuxia] Good question.

I test this behavior in spark, the result is different with hive 2.X

 cast('XXXX' as boolean): null
 cast ('' as boolean): null

 cast('false' as boolean) : false
 cast ('true' as boolean) : true

> Unexpected result if insert 'false' to boolean column
> -----------------------------------------------------
>
>                 Key: FLINK-28741
>                 URL: https://issues.apache.org/jira/browse/FLINK-28741
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Connectors / Hive
>    Affects Versions: 1.15.0, 1.15.1
>            Reporter: Jing Zhang
>            Priority: Major
>
> Using hive dialect to insert a string 'false' to boolean column, the result is true. It seems to treat all non-empty string as true.
> The error could be reproduced in the following ITCase.
> {code:java}
> @Test
> public void testUnExpectedResult() throws ExecutionException, InterruptedException {
>     HiveModule hiveModule = new HiveModule(hiveCatalog.getHiveVersion());
>     CoreModule coreModule = CoreModule.INSTANCE;
>     for (String loaded : tableEnv.listModules()) {
>         tableEnv.unloadModule(loaded);
>     }
>     tableEnv.loadModule("hive", hiveModule);
>     tableEnv.loadModule("core", coreModule);
> // create source table
>     tableEnv.executeSql(
>             "CREATE TABLE test_table (params string) PARTITIONED BY (`p_date` string)");
> // prepare a data which value is 'false'
>     tableEnv.executeSql("insert overwrite test_table partition(p_date = '20220612') values ('false')")
>             .await();
> // create target table which only contain one boolean column 
>     tableEnv.executeSql(
>             "CREATE TABLE target_table (flag boolean) PARTITIONED BY (`p_date` string)");
> // 
>     tableEnv.executeSql(
>             "insert overwrite table target_table partition(p_date = '20220724') "
>                     + "SELECT params FROM test_table WHERE p_date='20220612'").await();
>     TableImpl flinkTable =
>             (TableImpl) tableEnv.sqlQuery("select flag from target_table where p_date = '20220724'");
>    List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
>     assertEquals(
>             "[false]", results.toString());
> } {code}
>  



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