-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-29033 SQL Calcite: Support UDF and UDTF Overloading #13544
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,27 @@ public void testSameSignatureNotRegistered() throws Exception { | |
| assertEquals(1, schema.getFunctions("SAMESIGN").size()); | ||
| } | ||
|
|
||
| /** */ | ||
| @Test | ||
| public void testOverloadedFunctions() { | ||
| client.getOrCreateCache(new CacheConfiguration<Integer, Object>("overloaded-functions") | ||
| .setSqlSchema("UDF") | ||
| .setSqlFunctionClasses(OverloadedFunctionsLibrary.class)); | ||
|
|
||
| SchemaPlus schema = queryProcessor(client).schemaHolder().schema("UDF"); | ||
|
|
||
| assertEquals(2, schema.getFunctions("OVERLOADED").size()); | ||
| assertEquals(2, schema.getFunctions("OVERLOADED_TABLE").size()); | ||
| assertEquals(1, schema.getFunctions("SQL_EQUIVALENT").size()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder - why ? Behavior is different from java - is it ok ? It can confuse and brings, as minimal, unexpected behavior ? If it calcite related design - plz show me the related links ? And as minimal - i expect it need to be documented somehow ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior intentionally differs from Java because overload resolution uses SQL types. Both int and Integer correspond to SQL INTEGER, so Calcite cannot reliably distinguish these overloads and their resolution would depend on registration order. |
||
| assertEquals(1, schema.getFunctions("SQL_EQUIVALENT_TABLE").size()); | ||
|
|
||
| assertQuery("SELECT UDF.OVERLOADED(1, 'a')").returns("1a").check(); | ||
| assertQuery("SELECT UDF.OVERLOADED('a', 1)").returns("a1").check(); | ||
|
|
||
| assertQuery("SELECT * FROM TABLE(UDF.OVERLOADED_TABLE(1, 'a'))").returns("1a").check(); | ||
| assertQuery("SELECT * FROM TABLE(UDF.OVERLOADED_TABLE('a', 1))").returns("a1").check(); | ||
| } | ||
|
|
||
| /** */ | ||
| @Test | ||
| public void testSystemFunctionOverriding() throws Exception { | ||
|
|
@@ -829,4 +850,55 @@ private static class CustomClass { | |
| return "CustomClass.toString"; | ||
| } | ||
| } | ||
|
|
||
| /** */ | ||
| public static class OverloadedFunctionsLibrary { | ||
| /** */ | ||
| @QuerySqlFunction | ||
| public static String overloaded(int i, String s) { | ||
| return i + s; | ||
| } | ||
|
|
||
| /** */ | ||
| @QuerySqlFunction | ||
| public static String overloaded(String s, int i) { | ||
| return s + i; | ||
| } | ||
|
|
||
| /** */ | ||
| @QuerySqlFunction(alias = "SQL_EQUIVALENT") | ||
| public static String sqlEquivalent(int i) { | ||
| return String.valueOf(i); | ||
| } | ||
|
|
||
| /** */ | ||
| @QuerySqlFunction(alias = "SQL_EQUIVALENT") | ||
| public static String sqlEquivalent(Integer i) { | ||
| return String.valueOf(i); | ||
| } | ||
|
|
||
| /** */ | ||
| @QuerySqlTableFunction(alias = "OVERLOADED_TABLE", columnTypes = {String.class}, columnNames = {"RESULT"}) | ||
| public static Iterable<Collection<?>> overloadedTable(int i, String s) { | ||
| return List.of(List.of(i + s)); | ||
| } | ||
|
|
||
| /** */ | ||
| @QuerySqlTableFunction(alias = "OVERLOADED_TABLE", columnTypes = {String.class}, columnNames = {"RESULT"}) | ||
| public static Iterable<Collection<?>> overloadedTable(String s, int i) { | ||
| return List.of(List.of(s + i)); | ||
| } | ||
|
|
||
| /** */ | ||
| @QuerySqlTableFunction(alias = "SQL_EQUIVALENT_TABLE", columnTypes = {String.class}, columnNames = {"RESULT"}) | ||
| public static Iterable<Collection<?>> sqlEquivalentTable(int i) { | ||
| return List.of(List.of(String.valueOf(i))); | ||
| } | ||
|
|
||
| /** */ | ||
| @QuerySqlTableFunction(alias = "SQL_EQUIVALENT_TABLE", columnTypes = {String.class}, columnNames = {"RESULT"}) | ||
| public static Iterable<Collection<?>> sqlEquivalentTable(Integer i) { | ||
| return List.of(List.of(String.valueOf(i))); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you will use non ignoring nullability comparison:
Seems you can change behavior as it was in java and reduce further overloading missing errors