Skip to content

Commit

Permalink
Merge pull request #50 from adangel/soql-grouping
Browse files Browse the repository at this point in the history
Support GROUPING function in SOQL queries
  • Loading branch information
pwrightcertinia authored Sep 2, 2024
2 parents fee3a16 + 3ae515f commit 8522020
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions antlr/ApexLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ CUSTOM : 'custom';
STANDARD : 'standard';
DISTANCE : 'distance';
GEOLOCATION : 'geolocation';
GROUPING : 'grouping';

// SOQL Date functions
CALENDAR_MONTH : 'calendar_month';
Expand Down
3 changes: 3 additions & 0 deletions antlr/ApexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ soqlFunction
| WEEK_IN_YEAR LPAREN dateFieldName RPAREN
| FIELDS LPAREN soqlFieldsParameter RPAREN
| DISTANCE LPAREN locationValue COMMA locationValue COMMA StringLiteral RPAREN
| GROUPING LPAREN fieldName RPAREN
;

dateFieldName
Expand Down Expand Up @@ -962,6 +963,7 @@ id
| CUSTOM
| DISTANCE
| GEOLOCATION
| GROUPING
// SOQL date functions
| CALENDAR_MONTH
| CALENDAR_QUARTER
Expand Down Expand Up @@ -1160,6 +1162,7 @@ anyId
| CUSTOM
| DISTANCE
| GEOLOCATION
| GROUPING
// SOQL date functions
| CALENDAR_MONTH
| CALENDAR_QUARTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,23 @@ void testSubQuery() {
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void testGroupingFunction() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser(
"SELECT\n" +
" OBJ1__c O1,\n" +
" OBJ2__c O2,\n" +
" OBJ3__c O3,\n" +
" SUM(OBJ4__c) O4,\n" +
" GROUPING(OBJ1__c) O1Group,\n" +
" GROUPING(OBJ2__c) O2Group,\n" +
" GROUPING(OBJ3__c) O3Group\n" +
"FROM OBJ4__c\n" +
"GROUP BY ROLLUP(OBJ1__c, OBJ2__c, OBJ3__c)"
);
ApexParser.QueryContext context = parserAndCounter.getKey().query();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}
}
20 changes: 20 additions & 0 deletions npm/src/__tests__/SOQLParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,23 @@ test("SubQuery", () => {
expect(context).toBeInstanceOf(QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});

test("Grouping function", () => {
const [parser, errorCounter] = createParser(
`SELECT
OBJ1__c O1,
OBJ2__c O2,
OBJ3__c O3,
SUM(OBJ4__c) O4,
GROUPING(OBJ1__c) O1Group,
GROUPING(OBJ2__c) O2Group,
GROUPING(OBJ3__c) O3Group
FROM OBJ4__c
GROUP BY ROLLUP(OBJ1__c, OBJ2__c, OBJ3__c)`
);

const context = parser.query();

expect(context).toBeInstanceOf(QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});

0 comments on commit 8522020

Please sign in to comment.