Skip to content

Commit

Permalink
[fix](array) fix typeExtactMatch for array() type (#23264)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amorynan authored Aug 21, 2023
1 parent c1fb137 commit ae9f04f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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]

Original file line number Diff line number Diff line change
@@ -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; """
}

0 comments on commit ae9f04f

Please sign in to comment.