Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX](array) fix old optimizer with some array literal functions #23630

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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