This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit f87484d6b3e298ab7b7424e06c4784c2cd071fe5 Author: morrySnow <[email protected]> AuthorDate: Thu Jan 25 13:20:32 2024 +0800 [fix](Nereids) fix create array function type coercion (#30329) --- .../trees/expressions/functions/scalar/Array.java | 70 ++++++++++++---------- .../doris/nereids/util/TypeCoercionUtils.java | 3 +- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java index 0b7523a2d5c..863ec88683a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java @@ -34,6 +34,7 @@ import com.google.common.collect.Sets; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -70,38 +71,43 @@ public class Array extends ScalarFunction public List<FunctionSignature> getSignatures() { if (arity() == 0) { return SIGNATURES; - } else { - Map<Boolean, List<DataType>> partitioned = children.stream() - .map(ExpressionTrait::getDataType) - .collect(Collectors.partitioningBy(TypeCoercionUtils::hasCharacterType)); - List<DataType> needTypeCoercion = Lists.newArrayList(Sets.newHashSet(partitioned.get(true))); - if (needTypeCoercion.size() > 1 || !partitioned.get(false).isEmpty()) { - needTypeCoercion = needTypeCoercion.stream() - .map(TypeCoercionUtils::replaceCharacterToString) - .collect(Collectors.toList()); - } - partitioned = partitioned.get(false).stream() - .collect(Collectors.partitioningBy(TypeCoercionUtils::hasDecimalV2Type)); - if (!partitioned.get(true).isEmpty()) { - needTypeCoercion.addAll(partitioned.get(true).stream() - .map(TypeCoercionUtils::replaceDecimalV2WithDefault).collect(Collectors.toList())); - } - partitioned = partitioned.get(false).stream() - .collect(Collectors.partitioningBy(TypeCoercionUtils::hasDecimalV3Type)); - if (!partitioned.get(true).isEmpty()) { - needTypeCoercion.addAll(partitioned.get(true).stream() - .map(TypeCoercionUtils::replaceDecimalV3WithWildcard).collect(Collectors.toList())); - } - partitioned = partitioned.get(false).stream() - .collect(Collectors.partitioningBy(TypeCoercionUtils::hasDateTimeV2Type)); - if (!partitioned.get(true).isEmpty()) { - needTypeCoercion.addAll(partitioned.get(true).stream() - .map(TypeCoercionUtils::replaceDateTimeV2WithMax).collect(Collectors.toList())); - } - needTypeCoercion.addAll(partitioned.get(false)); - return needTypeCoercion.stream() - .map(dataType -> FunctionSignature.ret(ArrayType.of(new FollowToArgumentType(0))).varArgs(dataType)) - .collect(ImmutableList.toImmutableList()); } + Optional<DataType> commonDataType = TypeCoercionUtils.findWiderCommonTypeForCaseWhen( + children.stream().map(ExpressionTrait::getDataType).collect(Collectors.toList())); + if (commonDataType.isPresent()) { + return ImmutableList.of( + FunctionSignature.ret(ArrayType.of(commonDataType.get())).varArgs(commonDataType.get())); + } + Map<Boolean, List<DataType>> partitioned = children.stream() + .map(ExpressionTrait::getDataType) + .collect(Collectors.partitioningBy(TypeCoercionUtils::hasCharacterType)); + List<DataType> needTypeCoercion = Lists.newArrayList(Sets.newHashSet(partitioned.get(true))); + if (needTypeCoercion.size() > 1 || !partitioned.get(false).isEmpty()) { + needTypeCoercion = needTypeCoercion.stream() + .map(TypeCoercionUtils::replaceCharacterToString) + .collect(Collectors.toList()); + } + partitioned = partitioned.get(false).stream() + .collect(Collectors.partitioningBy(TypeCoercionUtils::hasDecimalV2Type)); + if (!partitioned.get(true).isEmpty()) { + needTypeCoercion.addAll(partitioned.get(true).stream() + .map(TypeCoercionUtils::replaceDecimalV2WithDefault).collect(Collectors.toList())); + } + partitioned = partitioned.get(false).stream() + .collect(Collectors.partitioningBy(TypeCoercionUtils::hasDecimalV3Type)); + if (!partitioned.get(true).isEmpty()) { + needTypeCoercion.addAll(partitioned.get(true).stream() + .map(TypeCoercionUtils::replaceDecimalV3WithWildcard).collect(Collectors.toList())); + } + partitioned = partitioned.get(false).stream() + .collect(Collectors.partitioningBy(TypeCoercionUtils::hasDateTimeV2Type)); + if (!partitioned.get(true).isEmpty()) { + needTypeCoercion.addAll(partitioned.get(true).stream() + .map(TypeCoercionUtils::replaceDateTimeV2WithMax).collect(Collectors.toList())); + } + needTypeCoercion.addAll(partitioned.get(false)); + return needTypeCoercion.stream() + .map(dataType -> FunctionSignature.ret(ArrayType.of(new FollowToArgumentType(0))).varArgs(dataType)) + .collect(ImmutableList.toImmutableList()); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java index 185bcc055b3..ffa41b1c633 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java @@ -1277,8 +1277,7 @@ public class TypeCoercionUtils { /** * find wider common type for data type list. */ - @Developing - private static Optional<DataType> findWiderCommonTypeForCaseWhen(List<DataType> dataTypes) { + public static Optional<DataType> findWiderCommonTypeForCaseWhen(List<DataType> dataTypes) { Map<Boolean, List<DataType>> partitioned = dataTypes.stream() .collect(Collectors.partitioningBy(TypeCoercionUtils::hasCharacterType)); List<DataType> needTypeCoercion = Lists.newArrayList(Sets.newHashSet(partitioned.get(true))); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
