Skip to content

Allow DESC ordering in window expressions#15195

Merged
rohangarg merged 6 commits into
apache:masterfrom
kgyrtkirk:windowing-desc-2
Oct 20, 2023
Merged

Allow DESC ordering in window expressions#15195
rohangarg merged 6 commits into
apache:masterfrom
kgyrtkirk:windowing-desc-2

Conversation

@kgyrtkirk

Copy link
Copy Markdown
Member
  • allow DESC ordering in window expressions
  • allow and accept NULLS FIRST / NULLS LAST options if they align with the actual ordering mode ; and report if they are unsupported
  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.

* allow DESC ordering in window expressions
* allow and accept NULLS FIRST / NULLS LAST options if they align with the actual ordering mode ; and report if they are unsupported
@kgyrtkirk
kgyrtkirk marked this pull request as ready for review October 18, 2023 14:49

@imply-cheddar imply-cheddar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the comment about ensuring there's enough context to make sense of the error message, it generally looks good. So, going to go ahead and approve it, but do please make sure that there's context in the error message (fwiw, if you go the ValidationException route, you can validate that the locations exist as they will be on the context of the DruidException and you can validate using expectContext on the DruidExceptionMatcher.

if (call.getKind() == SqlKind.NULLS_FIRST) {
SqlNode op0 = call.getOperandList().get(0);
if (op0.getKind() == SqlKind.DESCENDING) {
throw InvalidSqlInput.exception("DESCENDING ordering with NULLS FIRST is not supported!");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had experiences with really large SQL queries where a message like this tells me what's wrong, but doesn't always inform me of where I made the mistake. When we convert a ValidationException from Calcite into an InvalidSqlInput exception, it comes with the location of the SQL issue, which is helpful context. I wonder if either

a) We can add more context here to the error message to help identify which part of a potentially huge, sprawling SQL statement has an issue, OR
b) Maybe in the validateCall() method it's correct to throw a ValidationException to get the Calcite system to add the context of where it happened and then rely on the normal conversion of that to the InvalidSqlInput exception on the way out?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initially I've used use validationError....but then I've seen a lot of place where InvalidSqlInput was used in similar situations like here in the DruidSqlParserUtils; and I was just "following the current practices"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would probably make more sense to leave it like this for now - and instead of just fixing this one instance - replace all possible InvalidSqlInput -s with an alternate (which could pinpoint the sql location) and use that everywhere.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are some places where InvalidSqlInput can't really point to a sql location. I agree with the fact that we can take that up as a whole, but I agree with Eric that we should provide some context info in the error message. If we are to go with the InvalidSqlInput way, we would add context to it like https://github.com/apache/druid/blob/master/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java#L421
What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah; I guessed there will be some which can't be changed - however at a lot of callsites we do have an SqlNode ; I had in mind to target those

Comment thread sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java Outdated
T_ALLTYPES_ISSUES(AssertionError.class, "(t_alltype|allTypsUniq|fewRowsAllData).parquet.*Verifier.verify"),
RESULT_MISMATCH(AssertionError.class, "assertResultsEquals");
RESULT_MISMATCH(AssertionError.class, "assertResultsEquals"),
UNSUPPORTED_NULL_ORDERING(DruidException.class, "(A|DE)SCENDING ordering with NULLS (LAST|FIRST)");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream of consciousness: Looking at these definitions and thinking about the comment above about the DruidExceptionMatcher. I wonder if this enum shouldn't take a Matcher<? extends Throwable> instead of the class and message regex.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be extended - but I don't really see the reason to do that right now: as so far the exception message matching was enough - it at some point it will need to optionally access some other things ; this can be extended/changed/etc

note that I don't want to give better access to these things from the annotation @NotYetSupported either ; so that these enum entries are more-or-less mandatory - so that they could also act as natural magnets for similar issues :)

@abhishekagarwal87 abhishekagarwal87 added this to the 28.0 milestone Oct 19, 2023

@rohangarg rohangarg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % comment

@rohangarg
rohangarg merged commit fbbb9c7 into apache:master Oct 20, 2023
@rohangarg

Copy link
Copy Markdown
Member

Thanks a lot for the changes @kgyrtkirk 👍

kgyrtkirk added a commit to kgyrtkirk/druid that referenced this pull request Oct 20, 2023
@kgyrtkirk

Copy link
Copy Markdown
Member Author

Thank you @imply-cheddar and @rohangarg for reviewing and merging the changes!

LakshSingla pushed a commit that referenced this pull request Oct 20, 2023
CaseyPan pushed a commit to CaseyPan/druid that referenced this pull request Nov 17, 2023
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants