From 0423c3767417ecb699274662b9cbc59253f50252 Mon Sep 17 00:00:00 2001 From: 924060929 Date: Wed, 11 Dec 2024 22:57:51 +0800 Subject: [PATCH] fix --- .../trees/plans/logical/LogicalUnion.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalUnion.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalUnion.java index 7f8ec7a31ff284e..f42f49154c3c5a7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalUnion.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalUnion.java @@ -297,7 +297,15 @@ public void computeFd(DataTrait.Builder builder) { public static Pair>, List> castCommonDataTypeAndNullableByConstants( List> constantExprsList) { int columnCount = constantExprsList.isEmpty() ? 0 : constantExprsList.get(0).size(); + Pair, List> commonInfo + = computeCommonDataTypeAndNullable(constantExprsList, columnCount); + List> castedRows = castToCommonType(constantExprsList, commonInfo.key(), columnCount); + List nullables = commonInfo.second; + return Pair.of(castedRows, nullables); + } + private static Pair, List> computeCommonDataTypeAndNullable( + List> constantExprsList, int columnCount) { List nullables = Lists.newArrayList(); List commonDataTypes = Lists.newArrayListWithCapacity(columnCount); for (int columnId = 0; columnId < columnCount; columnId++) { @@ -312,19 +320,29 @@ public static Pair>, List> castCommonDataTyp nullables.add(nullable); commonDataTypes.add(commonDataType); } + return Pair.of(commonDataTypes, nullables); + } + private static List> castToCommonType( + List> rows, List commonDataTypes, int columnCount) { ImmutableList.Builder> castedConstants - = ImmutableList.builderWithExpectedSize(constantExprsList.size()); - for (List row : constantExprsList) { + = ImmutableList.builderWithExpectedSize(rows.size()); + for (List row : rows) { ImmutableList.Builder castedRow = ImmutableList.builderWithExpectedSize(columnCount); for (int i = 0; i < row.size(); i++) { - NamedExpression constant = row.get(i); - castedRow.add((NamedExpression) constant.withChildren( - TypeCoercionUtils.castIfNotSameTypeStrict(constant, commonDataTypes.get(i)) - )); + NamedExpression constantAlias = row.get(i); + DataType commonType = commonDataTypes.get(i); + Expression constant = constantAlias.child(0); + if (commonType.equals(constant.getDataType())) { + castedRow.add(constantAlias); + } else { + Expression expression + = TypeCoercionUtils.castIfNotSameTypeStrict(constant, commonType); + castedRow.add((NamedExpression) constant.withChildren(expression)); + } } castedConstants.add(castedRow.build()); } - return Pair.of(castedConstants.build(), nullables); + return castedConstants.build(); } }