You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2024/01/25 05:20:42 UTC
(doris) branch master updated: [fix](Nereids) fix create array function type coercion (#30329)
This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 8f49333c4a2 [fix](Nereids) fix create array function type coercion (#30329)
8f49333c4a2 is described below
commit 8f49333c4a2c9dabef84c44581a258c70db7ac53
Author: morrySnow <10...@users.noreply.github.com>
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: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org