From c197e0dbfced63004370314f3ce0e6de79905e81 Mon Sep 17 00:00:00 2001 From: amorynan Date: Mon, 21 Aug 2023 16:58:26 +0800 Subject: [PATCH] fix array() with cast in if --- .../java/org/apache/doris/catalog/Type.java | 5 ++-- .../conditional_functions/test_if_cast.out | 19 ++++++++++++++ .../conditional_functions/test_if_cast.groovy | 25 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 regression-test/data/query_p0/sql_functions/conditional_functions/test_if_cast.out create mode 100644 regression-test/suites/query_p0/sql_functions/conditional_functions/test_if_cast.groovy diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java index c57ad049586f93..436b5e951e99f3 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java @@ -1958,9 +1958,10 @@ public static boolean matchExactType(Type type1, Type type2, boolean ignorePreci } else if (type2.isArrayType()) { // For types array, we also need to check contains null for case like // cast(array as array) - if (((ArrayType) type2).getContainsNull() == ((ArrayType) type1).getContainsNull()) { - return true; + if (!((ArrayType) type2).getContainsNull() == ((ArrayType) type1).getContainsNull()) { + return false; } + return matchExactType(((ArrayType) type2).getItemType(), ((ArrayType) type1).getItemType()); } else { return true; } diff --git a/regression-test/data/query_p0/sql_functions/conditional_functions/test_if_cast.out b/regression-test/data/query_p0/sql_functions/conditional_functions/test_if_cast.out new file mode 100644 index 00000000000000..1fb288a7636df5 --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/conditional_functions/test_if_cast.out @@ -0,0 +1,19 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +["1970-01-01", "1970-01-01"] + +-- !select -- +["1970-01-01", "1970-01-01"] + +-- !select -- +["1970-01-01", "1970-01-01"] + +-- !select -- +[] + +-- !select -- +["1970-01-01"] + +-- !select -- +[NULL] + diff --git a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_if_cast.groovy b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_if_cast.groovy new file mode 100644 index 00000000000000..1b000823943bb9 --- /dev/null +++ b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_if_cast.groovy @@ -0,0 +1,25 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_if_cast") { + qt_select """ select if(job_d is null, cast(array() as array), job_d) as test from (select array('1970-01-01', '1970-01-01') as job_d) t; """ + qt_select """ select if(job_d is null, cast(array(null) as array), job_d) as test from (select array('1970-01-01', '1970-01-01') as job_d) t; """ + qt_select """ select if(job_d is null, cast(array('1970-01-01') as array), job_d) as test from (select array('1970-01-01', '1970-01-01') as job_d) t; """ + qt_select """ select if(job_d is null, job_d, cast(array() as array)) as test from (select array('1970-01-01', '1970-01-01') as job_d) t; """ + qt_select """ select if(job_d is null, job_d, cast(array('1970-01-01') as array)) as test from (select array('1970-01-01', '1970-01-01') as job_d) t; """ + qt_select """ select if(job_d is null, job_d, cast(array(null) as array)) as test from (select array('1970-01-01', '1970-01-01') as job_d) t; """ +}