Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PAGINATION : P A G E;
AS : A S;
GROUP_BY : G R O U P ' ' B Y;
HAVING : H A V I N G;
WHERE : W H E R E;

// Comparison operators
NEQ : '!=';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ parser grammar QueryParser;
options { tokenVocab=QueryLexer; }

// Main query structure
query : DISTINCT? (selectClause)? (condition)? (groupByClause)? (havingClause)? (SORT sortFields)? (PAGINATION paginationParams)? ;
query : DISTINCT? (selectClause)? (whereCondition)? (groupByClause)? (havingClause)? (SORT sortFields)? (PAGINATION paginationParams)? ;

whereCondition : WHERE? condition ;

// Select clause with support for expressions and optional aliases
selectClause : SELECT selectFields ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class QueryVisitor extends QueryParserBaseVisitor<Object> {
public QueryDefinition visitQuery(QueryParser.QueryContext ctx) {
boolean distinct = ctx.DISTINCT() != null;
Select select = ctx.selectClause() != null ? (Select) visit(ctx.selectClause()) : null;
Condition filter = ctx.condition() != null ? (Condition) visit(ctx.condition()) : null;
Condition filter = ctx.whereCondition() != null ? (Condition) visit(ctx.whereCondition()) : null;
GroupBy groupBy = ctx.groupByClause() != null ? (GroupBy) visit(ctx.groupByClause()) : null;
Condition having = ctx.havingClause() != null ? (Condition) visit(ctx.havingClause()) : null;
Sort[] sorts = ctx.SORT() != null ? (Sort[]) visit(ctx.sortFields()) : new Sort[0];
Expand Down Expand Up @@ -41,6 +41,11 @@ public QueryDefinition visitQuery(QueryParser.QueryContext ctx) {
.build();
}

@Override
public Object visitWhereCondition(QueryParser.WhereConditionContext ctx) {
return visit(ctx.condition());
}

@Override
public Object visitSelectClause(QueryParser.SelectClauseContext ctx) {
return visit(ctx.selectFields());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static Stream<Arguments> provideSimpleQueryArguments() {
Arguments.of("", Querity.query().build()),
Arguments.of("lastName=\"Skywalker\"",
Querity.query().filter(filterBy("lastName", "Skywalker")).build()),
Arguments.of("where lastName=\"Skywalker\"",
Querity.query().filter(filterBy("lastName", "Skywalker")).build()),
Arguments.of("lastName!=\"Skywalker\"",
Querity.query().filter(filterBy("lastName", NOT_EQUALS, "Skywalker")).build()),
Arguments.of("lastName starts with \"Sky\"",
Expand Down Expand Up @@ -142,6 +144,8 @@ public static Stream<Arguments> provideAdvancedQueryArguments() {
Querity.advancedQuery().selectBy("id").build()),
Arguments.of("select id, name lastName=\"Skywalker\"",
Querity.advancedQuery().selectBy("id", "name").filter(filterBy("lastName", "Skywalker")).build()),
Arguments.of("select id, name where lastName=\"Skywalker\"",
Querity.advancedQuery().selectBy("id", "name").filter(filterBy("lastName", "Skywalker")).build()),
Arguments.of("select id, name lastName=\"Skywalker\" sort by name asc",
Querity.advancedQuery().selectBy("id", "name").filter(filterBy("lastName", "Skywalker")).sort(sortBy("name", ASC)).build()),
Arguments.of("select id, name lastName=\"Skywalker\" sort by name asc page 1,10",
Expand Down
Loading