[fix](Nereids)set oepration type coercion is diff with legacy planner (#15982)

This commit is contained in:
morrySnow
2023-01-17 11:41:41 +08:00
committed by GitHub
parent ce1d19b373
commit d98abb12f9
3 changed files with 33 additions and 28 deletions

View File

@ -17,6 +17,7 @@
package org.apache.doris.nereids.trees.plans.logical;
import org.apache.doris.catalog.Type;
import org.apache.doris.nereids.memo.GroupExpression;
import org.apache.doris.nereids.properties.LogicalProperties;
import org.apache.doris.nereids.trees.expressions.Cast;
@ -129,25 +130,16 @@ public abstract class LogicalSetOperation extends AbstractLogicalPlan implements
List<Expression> newRightOutpus = new ArrayList<>();
// Ensure that the output types of the left and right children are consistent and expand upward.
for (int i = 0; i < resetNullableForLeftOutputs.size(); ++i) {
boolean hasPushed = false;
Slot left = resetNullableForLeftOutputs.get(i);
Slot right = child(1).getOutput().get(i);
if (TypeCoercionUtils.canHandleTypeCoercion(left.getDataType(), right.getDataType())) {
Optional<DataType> tightestCommonType =
TypeCoercionUtils.findTightestCommonType(null, left.getDataType(), right.getDataType());
if (tightestCommonType.isPresent()) {
Expression newLeft = TypeCoercionUtils.castIfNotSameType(left, tightestCommonType.get());
Expression newRight = TypeCoercionUtils.castIfNotSameType(right, tightestCommonType.get());
newLeftOutputs.add(newLeft);
newRightOutpus.add(newRight);
hasPushed = true;
}
}
if (!hasPushed) {
newLeftOutputs.add(left);
newRightOutpus.add(right);
}
DataType compatibleType = DataType.convertFromCatalogDataType(Type.getAssignmentCompatibleType(
left.getDataType().toCatalogDataType(),
right.getDataType().toCatalogDataType(),
false));
Expression newLeft = TypeCoercionUtils.castIfNotSameType(left, compatibleType);
Expression newRight = TypeCoercionUtils.castIfNotSameType(right, compatibleType);
newLeftOutputs.add(newLeft);
newRightOutpus.add(newRight);
}
List<List<Expression>> resultExpressions = new ArrayList<>();

View File

@ -406,31 +406,31 @@ d d 3
3 9.0 3 9
-- !union30 --
1.00 2.0
1.01 2.0
0.00 0.0
1.0000 2.0000000
1.0100 2.0000000
0.0001 1E-7
-- !union31 --
1 2
hell0
-- !union32 --
1.0 2.0
1.00000000 2.00000
-- !union33 --
1.0 2.0
1.00000000 2.00000
-- !union34 --
1.0 2.0
1.0 2.0
1.0 2.0
1.00000000 2.00000
1.00000000 2.00000
1.00000000 2.00000
-- !union35 --
1.0 2.0
1.0 2.0
1.00000000 2.00000
1.00000000 2.00000
-- !union36 --
1.0 2.0
1.00000000 2.00000
-- !union38 --
2016-07-01
@ -585,3 +585,7 @@ hell0
2020-05-25
2020-05-25
-- !union44 --
2020-05-25
2020-05-25 00

View File

@ -277,4 +277,13 @@ suite("test_nereids_set_operation") {
"""
qt_union43 """select '2020-05-25' day from test_table union all select day from test_table;"""
qt_union44 """
select * from
(select day from test_table
union all
select DATE_FORMAT(day, '%Y-%m-%d %H') dt_h from test_table
) a
order by 1
"""
}