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

add filter clause support at AggregateFunctionBuilder. #208

Merged
merged 13 commits into from
Dec 15, 2022
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
34 changes: 34 additions & 0 deletions src/operation-node/aggregate-function-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { freeze } from '../util/object-utils.js'
import { OperationNode } from './operation-node.js'
import { OverNode } from './over-node.js'
import { SimpleReferenceExpressionNode } from './simple-reference-expression-node.js'
import { WhereNode } from './where-node.js'

type AggregateFunction = 'avg' | 'count' | 'max' | 'min' | 'sum'

Expand All @@ -10,6 +11,7 @@ export interface AggregateFunctionNode extends OperationNode {
readonly func: AggregateFunction
readonly column: SimpleReferenceExpressionNode
readonly distinct?: boolean
readonly filter?: WhereNode
readonly over?: OverNode
}

Expand Down Expand Up @@ -41,6 +43,38 @@ export const AggregateFunctionNode = freeze({
})
},

cloneWithFilter(
aggregateFunctionNode: AggregateFunctionNode,
filter: OperationNode
): AggregateFunctionNode {
return freeze({
...aggregateFunctionNode,
filter: aggregateFunctionNode.filter
? WhereNode.cloneWithOperation(
aggregateFunctionNode.filter,
'And',
filter
)
: WhereNode.create(filter),
})
},

cloneWithOrFilter(
aggregateFunctionNode: AggregateFunctionNode,
filter: OperationNode
): AggregateFunctionNode {
return freeze({
...aggregateFunctionNode,
filter: aggregateFunctionNode.filter
? WhereNode.cloneWithOperation(
aggregateFunctionNode.filter,
'Or',
filter
)
: WhereNode.create(filter),
})
},

cloneWithOver(
aggregateFunctionNode: AggregateFunctionNode,
over?: OverNode
Expand Down
1 change: 1 addition & 0 deletions src/operation-node/operation-node-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ export class OperationNodeTransformer {
kind: 'AggregateFunctionNode',
column: this.transformNode(node.column),
distinct: node.distinct,
filter: this.transformNode(node.filter),
func: node.func,
over: this.transformNode(node.over),
})
Expand Down
Loading