Skip to content
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

Update query parsers with newly introduced JPA 3.2 keywords #3526

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

christophstrobl
Copy link
Member

@christophstrobl christophstrobl commented Jun 27, 2024

This PR updates the query parsers to deal with new keywords/functions in JPQL available via JPA 3.2.

  • union
  • intersect
  • except
  • cast
  • left
  • right
  • replace
  • ||

NULL precedence (#1280) for result ordering is not part of the changes and needs to be done in another PR.

Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

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

I commented on a couple of places where some refactoring could improve the code. But there is no severe concern from my side.

@@ -543,7 +548,7 @@ trim_specification
;

cast_function
: CAST '(' single_valued_path_expression identification_variable ('(' numeric_literal (',' numeric_literal)* ')')? ')'
: CAST '(' single_valued_path_expression (identification_variable)? identification_variable ('(' numeric_literal (',' numeric_literal)* ')')? ')'
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks weird, meaning: I don't understand what it is doing, and I also couldn't find any reference documentation or similar describing it.

Assuming it is correct, it would be nice to reference the source of this.

@@ -621,6 +634,7 @@ trim_character
identification_variable
: IDENTIFICATION_VARIABLE
| f=(COUNT
| AS
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, this is not so much about the change, but the whole construct.

I'm kind of surprised to find tokens like AS and DATE in the same collection of options and have no idea what a identification_variable is supposed to be.
I would appreciate a comment explaining this a little.

I also don't understand the f=( ... construct, so with the goal of personal learning I'd appreciate a quick explanation or a link.

| EXCEPT ALL?
;

set_fuction
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a k missing in that name. Or an n.

@@ -1926,6 +1934,32 @@ public QueryTokenStream visitFunctions_returning_strings(EqlParser.Functions_ret
builder.append(TOKEN_OPEN_PAREN);
builder.appendInline(visit(ctx.string_expression(0)));
builder.append(TOKEN_CLOSE_PAREN);
} else if (ctx.LEFT() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should extract a method here like

`renderFunctionCall(String function, String ... args) {...}

select_query
: select_clause from_clause (where_clause)? (groupby_clause)? (having_clause)? (orderby_clause)? (set_fuction)?
;

select_statement
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why we need to separate select_query and select_statement

@@ -1745,6 +1791,29 @@ public QueryTokenStream visitFunctions_returning_strings(JpqlParser.Functions_re
builder.append(TOKEN_OPEN_PAREN);
builder.append(visit(ctx.string_expression(0)));
builder.append(TOKEN_CLOSE_PAREN);
} else if (ctx.LEFT() != null) {
builder.append(QueryTokens.token(ctx.LEFT()));
Copy link
Contributor

Choose a reason for hiding this comment

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

This as well would benefit from the extraction of a renderFunction method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update JPQL and HQL parsers with newly introduced JPA 3.2 keywords
2 participants