This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new ae9f04f969 [fix](array) fix typeExtactMatch for array() type (#23264)
ae9f04f969 is described below
commit ae9f04f969c00340d095d38b7554dfe5e9f9ac5f
Author: amory <[email protected]>
AuthorDate: Mon Aug 21 19:41:09 2023 +0800
[fix](array) fix typeExtactMatch for array() type (#23264)
if we write sql with : `select cast(array() as array<varchar(10)>)`
castexpr in fe will call analyze() with `Type.matchExactType(childType,
type, true);`
here array type only check contains_null , but should check inner type to
make array matchExactType right
---
.../main/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(-)
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 c57ad04958..436b5e951e 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 abstract class Type {
} else if (type2.isArrayType()) {
// For types array, we also need to check contains null for
case like
// cast(array<not_null(int)> as array<int>)
- 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 0000000000..1fb288a763
--- /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 0000000000..1b00082394
--- /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<varchar(10)>), 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<varchar(10)>), 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<varchar(10)>), 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<varchar(10)>)) 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<varchar(10)>)) 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<varchar(10)>)) as test from (select array('1970-01-01', '1970-01-01') as
job_d) t; """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]