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

Support GROUPING function in SOQL queries #50

Merged
merged 1 commit into from
Sep 2, 2024
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
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);
});
Loading