Skip to content

Commit

Permalink
[fix](planner) array constructor do type coercion with decimal in wro…
Browse files Browse the repository at this point in the history
…ng way (#23630)

array creator with decimal type and integer type parameters should return array<decimal>,
but the legacy planner return array<double>
  • Loading branch information
amorynan authored and xiaokang committed Aug 30, 2023
1 parent 39366c5 commit 9b4cc90
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,8 @@ private void analyzeArrayFunction(Analyzer analyzer) throws AnalysisException {
|| fnName.getFunction().equalsIgnoreCase("array_cum_sum")
|| fnName.getFunction().equalsIgnoreCase("array_intersect")
|| fnName.getFunction().equalsIgnoreCase("arrays_overlap")
|| fnName.getFunction().equalsIgnoreCase("array_concat")) {
|| fnName.getFunction().equalsIgnoreCase("array_concat")
|| fnName.getFunction().equalsIgnoreCase("array")) {
Type[] childTypes = collectChildReturnTypes();
Type compatibleType = childTypes[0];
for (int i = 1; i < childTypes.length; ++i) {
Expand All @@ -1196,9 +1197,7 @@ private void analyzeArrayFunction(Analyzer analyzer) throws AnalysisException {
for (int i = 0; i < childTypes.length; i++) {
uncheckedCastChild(compatibleType, i);
}
}

if (fnName.getFunction().equalsIgnoreCase("array_exists")) {
} else if (fnName.getFunction().equalsIgnoreCase("array_exists")) {
Type[] newArgTypes = new Type[1];
if (!(getChild(0) instanceof CastExpr)) {
Expr castExpr = getChild(0).castTo(ArrayType.create(Type.BOOLEAN, true));
Expand All @@ -1213,13 +1212,14 @@ private void analyzeArrayFunction(Analyzer analyzer) throws AnalysisException {
throw new AnalysisException(getFunctionNotFoundError(collectChildReturnTypes()));
}
fn.setReturnType(getChild(0).getType());
}

// make nested type with function param can be Compatible otherwise be will not deal with type
if (fnName.getFunction().equalsIgnoreCase("array_position")
} else if (fnName.getFunction().equalsIgnoreCase("array_position")
|| fnName.getFunction().equalsIgnoreCase("array_contains")
|| fnName.getFunction().equalsIgnoreCase("countequal")) {
// make nested type with function param can be Compatible otherwise be will not deal with type
Type[] childTypes = collectChildReturnTypes();
if (childTypes[0].isNull()) {
childTypes[0] = new ArrayType(Type.NULL);
}
Type compatibleType = ((ArrayType) childTypes[0]).getItemType();
for (int i = 1; i < childTypes.length; ++i) {
compatibleType = Type.getAssignmentCompatibleType(compatibleType, childTypes[i], true);
Expand Down Expand Up @@ -1717,8 +1717,10 @@ && collectChildReturnTypes()[0].isDecimalV3()) {
|| (children.get(0).getType().isDecimalV2()
&& ((ArrayType) args[ix]).getItemType().isDecimalV2()))) {
continue;
} else if ((fnName.getFunction().equalsIgnoreCase("array_distinct") || fnName.getFunction()
.equalsIgnoreCase("array_remove") || fnName.getFunction().equalsIgnoreCase("array_sort")
} else if ((fnName.getFunction().equalsIgnoreCase("array")
|| fnName.getFunction().equalsIgnoreCase("array_distinct")
|| fnName.getFunction().equalsIgnoreCase("array_remove")
|| fnName.getFunction().equalsIgnoreCase("array_sort")
|| fnName.getFunction().equalsIgnoreCase("array_reverse_sort")
|| fnName.getFunction().equalsIgnoreCase("array_overlap")
|| fnName.getFunction().equalsIgnoreCase("array_union")
Expand Down
4 changes: 2 additions & 2 deletions gensrc/script/doris_builtins_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@
[['array'], 'ARRAY', ['DATE', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['DATETIMEV2', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['DATEV2', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['FLOAT', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['DOUBLE', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['DECIMALV2', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['DECIMAL32', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['DECIMAL64', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['DECIMAL128', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['FLOAT', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['DOUBLE', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['VARCHAR', '...'], 'ALWAYS_NOT_NULLABLE'],
[['array'], 'ARRAY', ['STRING', '...'], 'ALWAYS_NOT_NULLABLE'],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

suite("test_array_functions_by_literal") {
// array_nested function
sql """ set enable_nereids_planner = false; """
qt_sql "select a from (select array(1, 1, 2, 2, 2, 2) as a) t"

// array with decimal and other types
Expand Down

0 comments on commit 9b4cc90

Please sign in to comment.