-
Notifications
You must be signed in to change notification settings - Fork 5.5k
test(native): Add scalar function tests to native-tests #26013
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?
Conversation
Reviewer's GuideIntroduce a new scalar function test framework in presto-main-tests, refactor existing Java tests to use this abstraction, update Maven configurations to include the new module, and add a native test harness with projection rewriting for running tests on C++ workers. Class diagram for refactored scalar function testsclassDiagram
class AbstractTestArraySort {
+void testArraySort()
}
class AbstractTestArrayExcept {
+void testArrayExcept()
}
class TestFunctions {
+void testFunctions()
}
class AbstractTestNativeFunctions {
+void testNativeFunctions()
}
class TestArraySortFunction {
+void testArraySortNative()
}
class TestArrayExceptFunction {
+void testArrayExceptNative()
}
AbstractTestArraySort <|-- TestArraySortFunction
AbstractTestArrayExcept <|-- TestArrayExceptFunction
AbstractTestNativeFunctions <|-- TestArraySortFunction
AbstractTestNativeFunctions <|-- TestArrayExceptFunction
TestFunctions <|-- AbstractTestArraySort
TestFunctions <|-- AbstractTestArrayExcept
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
ced76f5
to
3bc39d6
Compare
3bc39d6
to
6ca0db9
Compare
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.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `presto-main-tests/src/main/java/com/facebook/presto/tests/operator/scalar/AbstractTestArraySort.java:37` </location>
<code_context>
+ assertFunction("array_sort(reverse(sequence(-4, 3)))", new ArrayType(BIGINT),
+ asList(-4L, -3L, -2L, -1L, 0L, 1L, 2L, 3L));
+ assertFunction("repeat(1,4)", new ArrayType(INTEGER), asList(1, 1, 1, 1));
+ assertFunctionNoRewrite("cast(array[] as array<int>)", new ArrayType(INTEGER), asList());
+ }
+
</code_context>
<issue_to_address>
**suggestion (testing):** Suggestion: Add tests for array_sort on arrays containing only nulls and arrays with mixed nulls and values.
Please add tests for array_sort with arrays such as ARRAY[null, null] and ARRAY[1, null, 2] to verify correct null handling.
```suggestion
assertFunction("repeat(1,4)", new ArrayType(INTEGER), asList(1, 1, 1, 1));
// Test array_sort with only nulls
assertFunction("array_sort(ARRAY [null, null])", new ArrayType(INTEGER), asList(null, null));
// Test array_sort with mixed nulls and values
assertFunction("array_sort(ARRAY [1, null, 2])", new ArrayType(INTEGER), asList(1, 2, null));
```
</issue_to_address>
### Comment 2
<location> `presto-main-tests/src/main/java/com/facebook/presto/tests/operator/scalar/AbstractTestArrayExcept.java:34-42` </location>
<code_context>
- assertFunction("array_except(ARRAY[1, 5, 3], ARRAY[3])", new ArrayType(INTEGER), ImmutableList.of(1, 5));
- assertFunction("array_except(ARRAY[CAST(1 as BIGINT), 5, 3], ARRAY[5])", new ArrayType(BIGINT), ImmutableList.of(1L, 3L));
- assertFunction("array_except(ARRAY[CAST('x' as VARCHAR), 'y', 'z'], ARRAY['x'])", new ArrayType(VARCHAR), ImmutableList.of("y", "z"));
- assertFunction("array_except(ARRAY[true, false, null], ARRAY[true])", new ArrayType(BOOLEAN), asList(false, null));
- assertFunction("array_except(ARRAY[1.1E0, 5.4E0, 3.9E0], ARRAY[5, 5.4E0])", new ArrayType(DOUBLE), ImmutableList.of(1.1, 3.9));
- }
</code_context>
<issue_to_address>
**suggestion (testing):** Suggestion: Add tests for array_except with arrays containing only nulls and arrays with all elements removed.
Please add tests for cases where input arrays contain only nulls, and where all elements are removed, to ensure these edge cases are handled correctly.
```suggestion
@Test
default void testBasic()
{
assertFunction("array_except(ARRAY[1, 5, 3], ARRAY[3])", new ArrayType(INTEGER), ImmutableList.of(1, 5));
assertFunction("array_except(ARRAY[CAST(1 as BIGINT), 5, 3], ARRAY[5])", new ArrayType(BIGINT), ImmutableList.of(1L, 3L));
assertFunction("array_except(ARRAY[CAST('x' as VARCHAR), 'y', 'z'], ARRAY['x'])", new ArrayType(VARCHAR), ImmutableList.of("y", "z"));
assertFunction("array_except(ARRAY[true, false, null], ARRAY[true])", new ArrayType(BOOLEAN), asList(false, null));
assertFunction("array_except(ARRAY[1.1E0, 5.4E0, 3.9E0], ARRAY[5, 5.4E0])", new ArrayType(DOUBLE), ImmutableList.of(1.1, 3.9));
// Edge case: input arrays containing only nulls
assertFunction("array_except(ARRAY[null, null], ARRAY[null])", new ArrayType(UNKNOWN), ImmutableList.of());
assertFunction("array_except(ARRAY[null], ARRAY[null])", new ArrayType(UNKNOWN), ImmutableList.of());
assertFunction("array_except(ARRAY[null, null], ARRAY[])", new ArrayType(UNKNOWN), asList((Object) null, null));
// Edge case: all elements removed
assertFunction("array_except(ARRAY[1, 2, 3], ARRAY[1, 2, 3])", new ArrayType(INTEGER), ImmutableList.of());
assertFunction("array_except(ARRAY['a', 'b'], ARRAY['a', 'b'])", new ArrayType(VARCHAR), ImmutableList.of());
assertFunction("array_except(ARRAY[true, false], ARRAY[true, false])", new ArrayType(BOOLEAN), ImmutableList.of());
}
```
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@aditi-pandit, could you help review this change? IpAddress tests will be added to |
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.
@pramodsatya : Thanks for this code. Had a high-level question. All these tests are on constant values... So is the reasoning for the rewrite to ensure these functions happen on the worker. Then I don't follow why we don't do that for all the tests and why some call the noRewrite function variation ?
Thanks @aditi-pandit; yes, the rewrite will ensure these function calls will run on the native workers when run in
|
@pramodsatya It defeats the purpose of the test if we are letting the function evaluate on the co-ordinator. Its better to fail with the errors in native engine. |
6ca0db9
to
48bc4db
Compare
Thanks @aditi-pandit, yes I agree it would be better to let unsupported queries fail on native workers and assert error messages, updated the tests accordingly. Could you PTAL? |
48bc4db
to
305e5c7
Compare
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.
Thanks @pramodsatya. This is looking much better. Just 2 more simple changes needed.
|
||
public interface TestFunctions | ||
{ | ||
void assertFunction(String projection, Type expectedType, Object expected); |
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.
@pramodsatya : Please add a comment about what these functions do.
...c/test/java/com/facebook/presto/nativetests/operator/scalar/AbstractTestNativeFunctions.java
Show resolved
Hide resolved
305e5c7
to
2de1c78
Compare
Thanks @aditi-pandit, updated accordingly. Could you PTAL? |
@pramodsatya : Please can you fix the checkstyle violations. |
2de1c78
to
aa257fb
Compare
int depth = 0; | ||
boolean inSingleQuote = false; | ||
int numArgs = 1; | ||
for (int i = 0; i < argsString.length(); 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.
This ensures that expressions at depth = 0 are not constant folded, but anything > depth = 0 is constant folded. So say f(5) is not constant folded, but f(g(5)) say is constant folded. That is alright, though you should document it. Or error here if there is such usage.
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.
Thanks for pointing this out, documented the limitation and the intent of rewrite here.
aa257fb
to
c0ed850
Compare
Description
Adds module
presto-main-tests
to refactor scalar function tests frompresto-main-base
, so they can be extended intopresto-native-tests
and run with the native worker.Rewrites queries from Presto java scalar function tests from
select array_sort(ARRAY [5, 20])
toselect array_sort(arg0) from (values (ARRAY [5, 20])) t(arg0)
. This ensures the query runs on C++ workers and is not constant folded on the coordinator.Motivation and Context
Extend existing function tests from Presto to run with native worker. Currently only
array_sort
andarray_except
tests are refactored. The remaining tests will be refactored in follow-up PRs.Impact
Improved function test coverage for Presto C++.
Test Plan
Added tests.