Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Inline select_query into select_statement, simplify set_function resolution.
Align JPQL and EQL grammars.
Adopt Hibernate version guards in tests.

Original Pull Request: #3695
  • Loading branch information
mp911de committed Jan 14, 2025
1 parent b1dea0a commit 65c5be0
Show file tree
Hide file tree
Showing 15 changed files with 749 additions and 435 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ql_statement
;

select_statement
: select_clause from_clause (where_clause)? (groupby_clause)? (having_clause)? (orderby_clause)? (setOperator select_statement)*
: select_clause from_clause (where_clause)? (groupby_clause)? (having_clause)? (orderby_clause)? (set_fuction)?
;

setOperator
Expand All @@ -52,6 +52,10 @@ setOperator
| EXCEPT ALL?
;

set_fuction
: setOperator select_statement
;

update_statement
: update_clause (where_clause)?
;
Expand Down Expand Up @@ -659,6 +663,7 @@ constructor_name

literal
: STRINGLITERAL
| JAVASTRINGLITERAL
| INTLITERAL
| FLOATLITERAL
| LONGLITERAL
Expand Down Expand Up @@ -827,9 +832,9 @@ reserved_word
|OR
|ORDER
|OUTER
|POWER
|REPLACE
|RIGHT
|POWER
|ROUND
|SELECT
|SET
Expand Down Expand Up @@ -997,6 +1002,7 @@ NOT_EQUAL : '<>' | '!=' ;

CHARACTER : '\'' (~ ('\'' | '\\')) '\'' ;
IDENTIFICATION_VARIABLE : ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '$' | '_') ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '0' .. '9' | '$' | '_')* ;
JAVASTRINGLITERAL : '"' ( ('\\' [btnfr"']) | ~('"'))* '"';
STRINGLITERAL : '\'' (~ ('\'' | '\\')|'\\')* '\'' ;
FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
INTLITERAL : ('0' .. '9')+ ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ ql_statement
;

select_statement
: select_query
;

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

Expand All @@ -57,11 +53,7 @@ setOperator
;

set_fuction
: setOperator set_function_select
;

set_function_select
: select_query
: setOperator select_statement
;

update_statement
Expand Down Expand Up @@ -95,7 +87,7 @@ join
;

fetch_join
: join_spec FETCH join_association_path_expression
: join_spec FETCH join_association_path_expression AS? identification_variable? join_condition?
;

join_spec
Expand Down Expand Up @@ -315,7 +307,7 @@ scalar_expression
| datetime_expression
| boolean_expression
| case_expression
| cast_expression
| cast_function
| entity_type_expression
;

Expand Down Expand Up @@ -441,6 +433,7 @@ arithmetic_primary
| functions_returning_numerics
| aggregate_expression
| case_expression
| cast_function
| function_invocation
| '(' subquery ')'
;
Expand All @@ -453,7 +446,6 @@ string_expression
| aggregate_expression
| case_expression
| function_invocation
| string_expression op='||' string_expression
| '(' subquery ')'
| string_expression '||' string_expression
;
Expand Down Expand Up @@ -539,8 +531,8 @@ functions_returning_strings
| SUBSTRING '(' string_expression ',' arithmetic_expression (',' arithmetic_expression)? ')'
| TRIM '(' ((trim_specification)? (trim_character)? FROM)? string_expression ')'
| LOWER '(' string_expression ')'
| REPLACE '(' string_expression ',' string_expression ',' string_expression ')'
| UPPER '(' string_expression ')'
| REPLACE '(' string_expression ',' string_expression ',' string_expression ')'
| LEFT '(' string_expression ',' arithmetic_expression ')'
| RIGHT '(' string_expression ',' arithmetic_expression ')'
;
Expand All @@ -551,6 +543,9 @@ trim_specification
| BOTH
;

cast_function
: CAST '(' single_valued_path_expression (identification_variable)? identification_variable ('(' numeric_literal (',' numeric_literal)* ')')? ')'
;

function_invocation
: FUNCTION '(' function_name (',' function_arg)* ')'
Expand Down Expand Up @@ -615,9 +610,6 @@ nullif_expression
: NULLIF '(' scalar_expression ',' scalar_expression ')'
;

cast_expression
: CAST '(' string_expression AS type_literal ')'
;

/*******************
Gaps in the spec.
Expand All @@ -631,6 +623,7 @@ trim_character
identification_variable
: IDENTIFICATION_VARIABLE
| f=(COUNT
| AS
| DATE
| FROM
| INNER
Expand All @@ -646,6 +639,7 @@ identification_variable
| TIME
| TYPE
| VALUE)
| type_literal
;

constructor_name
Expand Down Expand Up @@ -673,6 +667,9 @@ pattern_value

date_time_timestamp_literal
: STRINGLITERAL
| DATELITERAL
| TIMELITERAL
| TIMESTAMPLITERAL
;

entity_type_literal
Expand Down Expand Up @@ -965,9 +962,10 @@ ON : O N;
OR : O R;
ORDER : O R D E R;
OUTER : O U T E R;
POWER : P O W E R;
REGEXP : R E G E X P;
REPLACE : R E P L A C E;
RIGHT : R I G H T;
POWER : P O W E R;
ROUND : R O U N D;
SELECT : S E L E C T;
SET : S E T;
Expand Down Expand Up @@ -997,8 +995,11 @@ NOT_EQUAL : '<>' | '!=' ;

CHARACTER : '\'' (~ ('\'' | '\\')) '\'' ;
IDENTIFICATION_VARIABLE : ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '$' | '_') ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '0' .. '9' | '$' | '_')* ;
STRINGLITERAL : '\'' (~ ('\'' | '\\'))* '\'' ;
STRINGLITERAL : '\'' (~ ('\'' | '\\')|'\\')* '\'' ;
JAVASTRINGLITERAL : '"' ( ('\\' [btnfr"']) | ~('"'))* '"';
FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
INTLITERAL : ('0' .. '9')+ ;
LONGLITERAL : ('0' .. '9')+L ;
LONGLITERAL : ('0' .. '9')+ L;
DATELITERAL : '{' D STRINGLITERAL '}';
TIMELITERAL : '{' T STRINGLITERAL '}';
TIMESTAMPLITERAL : '{' T S STRINGLITERAL '}';
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EqlCountQueryTransformer extends EqlQueryRenderer {
}

@Override
public QueryRendererBuilder visitSelect_statement(EqlParser.Select_statementContext ctx) {
public QueryTokenStream visitSelect_statement(EqlParser.Select_statementContext ctx) {

QueryRendererBuilder builder = QueryRenderer.builder();

Expand Down Expand Up @@ -92,7 +92,7 @@ public QueryTokenStream visitSelect_clause(EqlParser.Select_clauseContext ctx) {
return builder;
}

private QueryRendererBuilder getDistinctCountSelection(QueryTokenStream selectionListbuilder) {
private QueryTokenStream getDistinctCountSelection(QueryTokenStream selectionListbuilder) {

QueryRendererBuilder nested = new QueryRendererBuilder();
CountSelectionTokenStream countSelection = CountSelectionTokenStream.create(selectionListbuilder);
Expand Down
Loading

0 comments on commit 65c5be0

Please sign in to comment.