Skip to content

Commit

Permalink
align Soql grammar to JPQL
Browse files Browse the repository at this point in the history
  • Loading branch information
luxbe committed Dec 19, 2024
1 parent 85b7cb1 commit 6ffa953
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
24 changes: 12 additions & 12 deletions jopa-impl/src/main/antlr4/cz/cvut/kbss/jopa/query/soql/Soql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ querySentence: selectStatement ;

selectStatement: selectClause fromClause whereClause? groupByClause? orderByClause? ;

objectPathExpression: simplePath DOT objectField ;
singleValuedObjectPathExpression: simpleSubpath DOT singleValuedObjectField ;

simplePath: objectField (DOT simplePath)* ;
simpleSubpath: singleValuedObjectField (DOT simpleSubpath)* ;

objectField: IDENTIFICATION_VARIABLE ;
singleValuedObjectField: IDENTIFICATION_VARIABLE ;

selectClause: SELECT (DISTINCT)? selectItem (',' selectItem)* ;

selectItem: selectExpression;

selectExpression: simplePath | aggregateExpression ;
selectExpression: simpleSubpath | aggregateExpression ;

aggregateExpression: COUNT '(' (DISTINCT)? simplePath ')';
aggregateExpression: COUNT '(' (DISTINCT)? simpleSubpath ')';

fromClause: FROM entityName IDENTIFICATION_VARIABLE;

Expand Down Expand Up @@ -48,7 +48,7 @@ simpleConditionalExpression
;

inExpression
: simplePath (NOT)? IN '('? (inItem (',' inItem)*) ')'?
: simpleSubpath (NOT)? IN '('? (inItem (',' inItem)*) ')'?
;

inItem
Expand All @@ -69,7 +69,7 @@ likeExpression
;

memberOfExpression
: inItem (NOT)? MEMBER OF simplePath
: inItem (NOT)? MEMBER OF simpleSubpath
;

entityExpression
Expand All @@ -84,7 +84,7 @@ comparisonExpression
;

stringExpression
: simplePath
: simpleSubpath
| STRING_LITERAL
| inputParameter
| functionsReturningStrings
Expand All @@ -95,7 +95,7 @@ functionsReturningStrings
| 'SUBSTRING' '(' stringExpression ',' simpleArithmeticExpression ',' simpleArithmeticExpression ')'
| 'LOWER' '(' stringExpression ')'
| 'UPPER' '(' stringExpression ')'
| 'LANG' '(' simplePath ')'
| 'LANG' '(' simpleSubpath ')'
;

simpleArithmeticExpression
Expand All @@ -111,7 +111,7 @@ arithmeticFactor
;

arithmeticPrimary
: simplePath
: simpleSubpath
| literal
| '(' simpleArithmeticExpression ')'
| inputParameter
Expand All @@ -128,11 +128,11 @@ functionsReturningNumerics

orderByClause: ORDER BY orderByItem (',' orderByItem)* ;

orderByItem: objectPathExpression (ASC | DESC) ;
orderByItem: singleValuedObjectPathExpression (ASC | DESC) ;

groupByClause: GROUP BY groupByItem (',' groupByItem)* ;

groupByItem: objectPathExpression ;
groupByItem: singleValuedObjectPathExpression ;

inputParameter: COLON IDENTIFICATION_VARIABLE ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ public void exitSelectStatement(SoqlParser.SelectStatementContext ctx) {
}

@Override
public void enterObjectPathExpression(SoqlParser.ObjectPathExpressionContext ctx) {
public void enterSingleValuedObjectPathExpression(SoqlParser.SingleValuedObjectPathExpressionContext ctx) {

}

@Override
public void exitObjectPathExpression(SoqlParser.ObjectPathExpressionContext ctx) {
public void exitSingleValuedObjectPathExpression(SoqlParser.SingleValuedObjectPathExpressionContext ctx) {

}

@Override
public void enterSimplePath(SoqlParser.SimplePathContext ctx) {
if(ctx.simplePath() == null) {
public void enterSimpleSubpath(SoqlParser.SimpleSubpathContext ctx) {
if(ctx.simpleSubpath() == null) {
return;
}

Expand All @@ -140,11 +140,11 @@ public void enterSimplePath(SoqlParser.SimplePathContext ctx) {
}

// node was already processed by parent
if(ctx.getParent() instanceof SoqlParser.SimplePathContext) {
if(ctx.getParent() instanceof SoqlParser.SimpleSubpathContext) {
return;
}

SoqlNode owner = linkSimplePath(ctx);
SoqlNode owner = linkSimpleSubpath(ctx);

// don't add top level references multiple times
if(!owner.hasChild() && objectTypes.containsKey(owner.getValue())) {
Expand All @@ -165,7 +165,7 @@ public void enterSimplePath(SoqlParser.SimplePathContext ctx) {
}
}

private SoqlNode linkSimplePath(ParserRuleContext ctx) {
private SoqlNode linkSimpleSubpath(ParserRuleContext ctx) {
AttributeNode firstNode = new AttributeNode(getOwnerFromParam(ctx));
AttributeNode currentNode = firstNode;

Expand All @@ -186,17 +186,18 @@ private SoqlNode linkSimplePath(ParserRuleContext ctx) {
}

@Override
public void exitSimplePath(SoqlParser.SimplePathContext ctx) {
public void exitSimpleSubpath(SoqlParser.SimpleSubpathContext ctx) {

}

@Override
public void enterObjectField(SoqlParser.ObjectFieldContext ctx) {
public void enterSingleValuedObjectField(SoqlParser.SingleValuedObjectFieldContext ctx) {

}

@Override
public void exitObjectField(SoqlParser.ObjectFieldContext ctx) {
public void exitSingleValuedObjectField(SoqlParser.SingleValuedObjectFieldContext ctx) {

}

@Override
Expand Down Expand Up @@ -252,8 +253,8 @@ public void enterAggregateExpression(SoqlParser.AggregateExpressionContext ctx)
isSelectedParamDistinct = true;
}

if(ctx.simplePath() != null) {
this.projectedVariable = ctx.simplePath().getText();
if(ctx.simpleSubpath() != null) {
this.projectedVariable = ctx.simpleSubpath().getText();
}
}
}
Expand Down

0 comments on commit 6ffa953

Please sign in to comment.