Skip to content

Commit

Permalink
[fix](Nereids) array_difference and array_position get wrong result (#…
Browse files Browse the repository at this point in the history
…23331)

1. change array_difference signature to let it return same type as arg
2. do not change precision when signature not use wildcard type
  • Loading branch information
morrySnow authored Aug 23, 2023
1 parent 2185268 commit daa4db0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ private static FunctionSignature defaultDecimalV3PrecisionPromotion(
if (!(targetType instanceof DecimalV3Type)) {
continue;
}
// only process wildcard decimalv3
if (((DecimalV3Type) targetType).getPrecision() > 0) {
continue;
}
if (finalType == null) {
finalType = DecimalV3Type.forType(arguments.get(i).getDataType());
} else {
Expand All @@ -347,19 +351,20 @@ private static FunctionSignature defaultDecimalV3PrecisionPromotion(
}
finalType = DecimalV3Type.widerDecimalV3Type((DecimalV3Type) finalType, argType, true);
}
Preconditions.checkState(finalType.isDecimalV3Type(),
"decimalv3 precision promotion failed.");
Preconditions.checkState(finalType.isDecimalV3Type(), "decimalv3 precision promotion failed.");
}
DataType argType = finalType;
List<DataType> newArgTypes = signature.argumentsTypes.stream().map(t -> {
if (t instanceof DecimalV3Type) {
// only process wildcard decimalv3
if (t instanceof DecimalV3Type && ((DecimalV3Type) t).getPrecision() <= 0) {
return argType;
} else {
return t;
}
}).collect(Collectors.toList());
signature = signature.withArgumentTypes(signature.hasVarArgs, newArgTypes);
if (signature.returnType instanceof DecimalV3Type) {
if (signature.returnType instanceof DecimalV3Type
&& ((DecimalV3Type) signature.returnType).getPrecision() <= 0) {
signature = signature.withReturnType(argType);
}
return signature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ public class ArrayDifference extends ScalarFunction
FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(ArrayType.of(LargeIntType.INSTANCE)),
FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(FloatType.INSTANCE)),
FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(DoubleType.INSTANCE)),
FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT))
.args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)),
FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD))
.args(ArrayType.of(DecimalV3Type.WILDCARD))
FunctionSignature.retArgType(0).args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)),
FunctionSignature.retArgType(0).args(ArrayType.of(DecimalV3Type.WILDCARD))
);

/**
Expand Down
48 changes: 24 additions & 24 deletions regression-test/data/nereids_function_p0/scalar_function/Array.out
Original file line number Diff line number Diff line change
Expand Up @@ -8120,33 +8120,33 @@ true
[9, 9, 9, 9, 9, 9, 9, 9, 9]

-- !sql_array_with_constant_DecimalV3 --
[0.100000000]
[0.200000000, 0.200000000]
[0.300000000, 0.300000000, 0.300000000]
[0.400000000, 0.400000000, 0.400000000, 0.400000000]
[0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000]
[0.600000000, 0.600000000, 0.600000000, 0.600000000, 0.600000000, 0.600000000]
[0.700000000, 0.700000000, 0.700000000, 0.700000000, 0.700000000, 0.700000000, 0.700000000]
[0.800000000, 0.800000000, 0.800000000, 0.800000000, 0.800000000, 0.800000000, 0.800000000, 0.800000000]
[0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000]
[1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000]
[1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000]
[1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000]
[0.100]
[0.200, 0.200]
[0.300, 0.300, 0.300]
[0.400, 0.400, 0.400, 0.400]
[0.500, 0.500, 0.500, 0.500, 0.500]
[0.600, 0.600, 0.600, 0.600, 0.600, 0.600]
[0.700, 0.700, 0.700, 0.700, 0.700, 0.700, 0.700]
[0.800, 0.800, 0.800, 0.800, 0.800, 0.800, 0.800, 0.800]
[0.900, 0.900, 0.900, 0.900, 0.900, 0.900, 0.900, 0.900, 0.900]
[1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000]
[1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100]
[1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200]
[]

-- !sql_array_with_constant_DecimalV3_notnull --
[0.100000000]
[0.200000000, 0.200000000]
[0.300000000, 0.300000000, 0.300000000]
[0.400000000, 0.400000000, 0.400000000, 0.400000000]
[0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000]
[0.600000000, 0.600000000, 0.600000000, 0.600000000, 0.600000000, 0.600000000]
[0.700000000, 0.700000000, 0.700000000, 0.700000000, 0.700000000, 0.700000000, 0.700000000]
[0.800000000, 0.800000000, 0.800000000, 0.800000000, 0.800000000, 0.800000000, 0.800000000, 0.800000000]
[0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000, 0.900000000]
[1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.000000000]
[1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000, 1.100000000]
[1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000, 1.200000000]
[0.100]
[0.200, 0.200]
[0.300, 0.300, 0.300]
[0.400, 0.400, 0.400, 0.400]
[0.500, 0.500, 0.500, 0.500, 0.500]
[0.600, 0.600, 0.600, 0.600, 0.600, 0.600]
[0.700, 0.700, 0.700, 0.700, 0.700, 0.700, 0.700]
[0.800, 0.800, 0.800, 0.800, 0.800, 0.800, 0.800, 0.800]
[0.900, 0.900, 0.900, 0.900, 0.900, 0.900, 0.900, 0.900, 0.900]
[1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000]
[1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100, 1.100]
[1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200, 1.200]

-- !sql_array_with_constant_Boolean --
[0, 0, 0, 0, 0, 0, 0]
Expand Down
2 changes: 1 addition & 1 deletion regression-test/pipeline/p0/conf/regression-conf.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ testDirectories = ""
// this groups will not be executed
excludeGroups = ""
// this suites will not be executed
excludeSuites = "nereids_scalar_fn_Array,test_pk_uk_index_change,test_pk_uk_case,test_default_limit,test_profile,test_broker_load,test_spark_load,test_refresh_mtmv,test_bitmap_filter,test_export_parquet,test_doris_jdbc_catalog,test_transactional_hive,nereids_delete_mow_partial_update"
excludeSuites = "test_pk_uk_index_change,test_pk_uk_case,test_default_limit,test_profile,test_broker_load,test_spark_load,test_refresh_mtmv,test_bitmap_filter,test_export_parquet,test_doris_jdbc_catalog,test_transactional_hive,nereids_delete_mow_partial_update"
// this directories will not be executed
excludeDirectories = "workload_manager_p1"

Expand Down

0 comments on commit daa4db0

Please sign in to comment.