Skip to content

Commit 7f41956

Browse files
committed
Ensure date functions are flagged as isAggregateFn
Date functions are considered as aggregate functions from salesforce, so this fixes a bug to ensure we match behavior. resolves #228
1 parent 75ebca1 commit 7f41956

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# Changelog
22

3+
## 4.8.0
4+
5+
April 9, 2023
6+
7+
- Fix `isAggregateFn` (#228)
8+
- Date functions, such as `HOUR_IN_DAY(CreatedDate)` did not properly have the `isAggregateFn` property set to true for the field.
9+
- As a result, `getFlattenedFields` would produce incorrect results for these fields if they were not aliased.
10+
311
## 4.7.1
412

13+
January 23rd, 2023
14+
515
The repository was moved from `paustint` to `jetstreamapp`. No code changes.
616

717
## 4.7.0

src/parser/visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ class SOQLVisitor extends BaseSoqlVisitor {
592592
}
593593

594594
dateFunction(ctx: FieldFunctionContext, options: { includeType: boolean } = { includeType: true }) {
595-
return this.helpers.$_getFieldFunction(ctx, false, options.includeType);
595+
return this.helpers.$_getFieldFunction(ctx, true, options.includeType);
596596
}
597597

598598
aggregateFunction(ctx: FieldFunctionContext, options: { includeType: boolean } = { includeType: true }) {

test/public-utils-test-data.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,4 +692,37 @@ export const testCases: FlattenedObjTestCase[] = [
692692
SBQQ__Quote__c: 'a116g000007R9yVAAS',
693693
},
694694
},
695+
{
696+
testCase: 20,
697+
expectedFields: ['expr0'],
698+
query: {
699+
fields: [
700+
{
701+
type: 'FieldFunctionExpression',
702+
functionName: 'CALENDAR_MONTH',
703+
parameters: ['CreatedDate'],
704+
isAggregateFn: true,
705+
rawValue: 'CALENDAR_MONTH(CreatedDate)',
706+
},
707+
],
708+
sObject: 'Account',
709+
groupBy: [
710+
{
711+
fn: { functionName: 'CALENDAR_MONTH', parameters: ['CreatedDate'], rawValue: 'CALENDAR_MONTH(CreatedDate)' },
712+
},
713+
],
714+
having: {
715+
left: {
716+
fn: { functionName: 'CALENDAR_MONTH', parameters: ['CreatedDate'], rawValue: 'CALENDAR_MONTH(CreatedDate)' },
717+
operator: '!=',
718+
value: '2',
719+
literalType: 'INTEGER',
720+
},
721+
},
722+
},
723+
sfdcObj: {
724+
attributes: { type: 'AggregateResult' },
725+
expr0: 3,
726+
},
727+
},
695728
];

test/test-cases.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ export const testCases: TestCase[] = [
11711171
type: 'FieldFunctionExpression',
11721172
functionName: 'CALENDAR_YEAR',
11731173
parameters: ['CreatedDate'],
1174+
isAggregateFn: true,
11741175
rawValue: 'CALENDAR_YEAR(CreatedDate)',
11751176
alias: 'calYear',
11761177
},
@@ -1204,6 +1205,7 @@ export const testCases: TestCase[] = [
12041205
rawValue: 'convertTimezone(CreatedDate)',
12051206
},
12061207
],
1208+
isAggregateFn: true,
12071209
rawValue: 'CALENDAR_YEAR(convertTimezone(CreatedDate))',
12081210
alias: 'calYear',
12091211
},
@@ -1428,6 +1430,7 @@ export const testCases: TestCase[] = [
14281430
rawValue: 'convertTimezone(CreatedDate)',
14291431
},
14301432
],
1433+
isAggregateFn: true,
14311434
rawValue: 'HOUR_IN_DAY(convertTimezone(CreatedDate))',
14321435
},
14331436
{
@@ -2046,6 +2049,7 @@ export const testCases: TestCase[] = [
20462049
type: 'FieldFunctionExpression',
20472050
functionName: 'WEEK_IN_YEAR',
20482051
parameters: ['CloseDate'],
2052+
isAggregateFn: true,
20492053
rawValue: 'WEEK_IN_YEAR(CloseDate)',
20502054
},
20512055
{
@@ -2086,6 +2090,7 @@ export const testCases: TestCase[] = [
20862090
type: 'FieldFunctionExpression',
20872091
functionName: 'WEEK_IN_YEAR',
20882092
parameters: ['CloseDate'],
2093+
isAggregateFn: true,
20892094
rawValue: 'WEEK_IN_YEAR(CloseDate)',
20902095
},
20912096
{
@@ -2128,6 +2133,7 @@ export const testCases: TestCase[] = [
21282133
type: 'FieldFunctionExpression',
21292134
functionName: 'WEEK_IN_YEAR',
21302135
parameters: ['CloseDate'],
2136+
isAggregateFn: true,
21312137
rawValue: 'WEEK_IN_YEAR(CloseDate)',
21322138
},
21332139
{
@@ -2242,6 +2248,7 @@ export const testCases: TestCase[] = [
22422248
{
22432249
type: 'FieldFunctionExpression',
22442250
functionName: 'CALENDAR_MONTH',
2251+
isAggregateFn: true,
22452252
rawValue: 'CALENDAR_MONTH(LoginTime)',
22462253
parameters: ['LoginTime'],
22472254
alias: 'month',

0 commit comments

Comments
 (0)