Skip to content

Commit

Permalink
fix function signature of array_contains/position([null],null)
Browse files Browse the repository at this point in the history
Signed-off-by: silverbullet233 <[email protected]>
  • Loading branch information
silverbullet233 committed Feb 20, 2025
1 parent 9c31daf commit 0beabd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,14 @@ private static Function getAdjustedAnalyzedFunction(ConnectContext session,
newFn.setUserVisible(fn.isUserVisible());
fn = newFn;
}
} else if (FunctionSet.ARRAY_CONTAINS.equalsIgnoreCase(fnName) || FunctionSet.ARRAY_POSITION.equalsIgnoreCase(fnName)) {
Preconditions.checkState(argumentTypes.length == 2);
if (argumentTypes[1].isNull() &&
argumentTypes[0].isArrayType() && ((ArrayType) argumentTypes[0]).getItemType().isNull()) {
argumentTypes[0] = Type.ARRAY_BOOLEAN;
argumentTypes[1] = Type.BOOLEAN;
fn = Expr.getBuiltinFunction(fnName, argumentTypes, Function.CompareMode.IS_IDENTICAL);
}
}
// add new argument types
Arrays.stream(argumentTypes).forEach(newArgumentTypes::add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,13 @@ public void testArrayPolymorphicFunction() throws Exception {
assertCContains(plan, "array_slice[([5: d_2, ARRAY<DECIMAL64(4,3)>, true], 1, 3); " +
"args: INVALID_TYPE,BIGINT,BIGINT; result: ARRAY<DECIMAL64(4,3)>;");

sql = "select array_contains([null], null), array_position([null], null)";
plan = getVerboseExplain(sql);
assertContains(plan, " | output columns:\n" +
" | 2 <-> array_contains[([NULL], NULL); " +
"args: INVALID_TYPE,BOOLEAN; result: BOOLEAN; args nullable: true; result nullable: true]\n" +
" | 3 <-> array_position[([NULL], NULL); " +
"args: INVALID_TYPE,BOOLEAN; result: INT; args nullable: true; result nullable: true]");
}

@Test
Expand Down

0 comments on commit 0beabd2

Please sign in to comment.