From bd982ac815e7a12507f7cabcbc634fe34ed04f1b Mon Sep 17 00:00:00 2001 From: xy720 <22125576+xy720@users.noreply.github.com> Date: Wed, 13 Jul 2022 14:54:49 +0800 Subject: [PATCH] [Bug] Fix array functions arguments mismatch (#10549) Currently, we convert array to array For example, the input array_sum([1, 2, 3]) can match function array_sum(Array) as well as array_sum(Array). But when a function has more than one argument, the function may be match incorrectly. For example, the input array_contains([1, 2, 3], 2147483648) will match the function array_contains(Array, BigInt), but the correct match should be array_contains(Array, Int) The correct match should be: array_contains([1, 2, 3], 1) match array_contains(Array, Int) array_contains([1, 2, 3], 2147483648) match array_contains(Array, Int) array_contains([2147483648, 2147483649, 2147483650], 2147483648) match array_contains(Array, BigInt) now is: array_contains([1, 2, 3], 1) match array_contains(Array, Int) array_contains([1, 2, 3], 2147483648) match array_contains(Array, BigInt) array_contains([2147483648, 2147483649, 2147483650], 2147483648) match array_contains(Array, BigInt) And this will cause some trouble. Assume that there are two functions being defined: Int array_functions(Array, Int) BigInt array_functions(Array, BigInt) And array_functions([1,2,3], 2147483648) will match BigInt array_functions(Array, BigInt), but the result type should not be BigInt, but should be Int. --- .../src/main/java/org/apache/doris/catalog/ArrayType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ArrayType.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/ArrayType.java index ff1b51d860..26f4aa0aec 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ArrayType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ArrayType.java @@ -81,7 +81,8 @@ public class ArrayType extends Type { if (itemType.isNull() || ((ArrayType) t).getItemType().isNull()) { return true; } - return Type.isImplicitlyCastable(itemType, ((ArrayType) t).itemType, true) + + return itemType.matchesType(((ArrayType) t).itemType) && (((ArrayType) t).containsNull || !containsNull); }