Add warning for IGNORE NULL with Window agggregates#23325
Add warning for IGNORE NULL with Window agggregates#23325auden-woolfson merged 1 commit intoprestodb:masterfrom
Conversation
The committers listed above are authorized under a signed CLA. |
|
Easy CLA should be resolved once I make/push more changes. Had to set local git config |
tdcmeehan
left a comment
There was a problem hiding this comment.
Great work! Some suggestions.
| } | ||
|
|
||
| if (node.isIgnoreNulls()) { | ||
| ImmutableList<String> allowedIgnoreNullFunctionNames = ImmutableList.of("lead", "lag", "first_value", "last_value"); |
There was a problem hiding this comment.
Let's not hardcode this. Instead, let's create a new method in FunctionResolution that identifies a window value function. I think it will be OK to hardcode it, but inside there, make it a constant. Also, I think you're missing one, Nth value. Double check this list by looking at all subclasses of ValueWindowFunction.
There was a problem hiding this comment.
Thanks for the feedback. Made all the updates you suggested. I added the list of window value functions to FunctionResolution. Is this the right place for it to live?
There was a problem hiding this comment.
Yes that's good. Next let's look for a place to put some tests. We should be able to construct some simple queries that show a warning is emitted for functions which are not window value functions, and no warning is emitted for window value functions.
| if (node.isIgnoreNulls()) { | ||
| ImmutableList<String> allowedIgnoreNullFunctionNames = ImmutableList.of("lead", "lag", "first_value", "last_value"); | ||
| if (!allowedIgnoreNullFunctionNames.contains(node.getName().toString())) { | ||
| warningCollector.add(new PrestoWarning(SEMANTIC_WARNING, "IGNORE NULLS does not work for aggregate and ranking window functions")); |
There was a problem hiding this comment.
Also mention that it will start failing in the future.
| implements StandardFunctionResolution | ||
| { | ||
| private final FunctionAndTypeResolver functionAndTypeResolver; | ||
| private final ImmutableList<QualifiedObjectName> windowValueFunctions = ImmutableList.of( |
There was a problem hiding this comment.
| private final ImmutableList<QualifiedObjectName> windowValueFunctions = ImmutableList.of( | |
| private final List<QualifiedObjectName> windowValueFunctions = ImmutableList.of( |
| } | ||
|
|
||
| if (node.isIgnoreNulls()) { | ||
| FunctionResolution functionResolution = new FunctionResolution(functionAndTypeResolver); |
There was a problem hiding this comment.
Let's make the resolution a member variable of the class
| "(ORDER BY b)\n FROM (VALUES (1, 1, 3), (1, 2, null), (1, 4, 2)) AS t(a, b, c)")); | ||
| } | ||
|
|
||
| assertHasWarning( |
There was a problem hiding this comment.
Please add more tests with various aggregate functions and those in this list https://prestodb.io/docs/current/functions/window.html#ranking-functions
| } | ||
| } | ||
|
|
||
| if (node.isIgnoreNulls()) { |
There was a problem hiding this comment.
Most of the window function semantic checks happen here https://github.com/prestodb/presto/blob/master/presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java#L981. Any particular reason we didn't add this check after the frame validation in that block ?
There was a problem hiding this comment.
There wasn't any reason before that I had placed it on that exact line, but it needs to be after the function variable has been initialized. I moved it back to line 1122.
|
@auden-woolfson : Thanks for working on this issue. Please can you merge all your commits into a single one. |
5f2c078 to
9772262
Compare
|
|
||
| if (node.isIgnoreNulls()) { | ||
| if (!functionResolution.isWindowValueFunction(function)) { | ||
| String warningMessage = createWarningMessage(node, "IGNORE NULLS does not work for aggregate and ranking window functions, this will cause queries to fail in future versions"); |
There was a problem hiding this comment.
| String warningMessage = createWarningMessage(node, "IGNORE NULLS does not work for aggregate and ranking window functions, this will cause queries to fail in future versions"); | |
| String warningMessage = createWarningMessage(node, "IGNORE NULLS is not used for aggregate and ranking window functions. This will cause queries to fail in future versions."); |
| } | ||
|
|
||
| @Test | ||
| void testIgnoreNullWarning() |
There was a problem hiding this comment.
| void testIgnoreNullWarning() | |
| public void testIgnoreNullWarning() |
6a6e26b to
ae8e08e
Compare
|
Code looks good. Let's reword the commit, something like
|
jaystarshot
left a comment
There was a problem hiding this comment.
Is this code path executed only once? Can there be multiple warnings for a single query
I just tested this with the following query....
I did get two errors, it will error out for each individual "invalid" ignore null. |
presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java
Outdated
Show resolved
Hide resolved
0a3c63f to
98a5970
Compare
796bf82 to
a7f070a
Compare
aditi-pandit
left a comment
There was a problem hiding this comment.
Thanks @auden-woolfson
tdcmeehan
left a comment
There was a problem hiding this comment.
Please add an issue to follow up and convert this warning into a failure after the next release has been cut.
|
@auden-woolfson please add a release note. See other PRs and our contributing guide for examples. |
steveburnett
left a comment
There was a problem hiding this comment.
Reviewed text of warning, looks good to me!
|
For information on writing and formatting a release note entry, see the Release Notes Guidelines. As a starting point, maybe something like this following draft: |
a7f070a to
0906b5f
Compare
0906b5f to
64cb28b
Compare
Description
Added a warning when an IGNORE NULL clause is used on any non lag, lead, first or last value function. Presto will not throw an error in other cases, but it also will not ignore null values. See issue #21304
== RELEASE NOTES ==
General Changes
23325