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

aggfuncs: implement Count with new aggregation framework #7009

Merged
merged 5 commits into from
Jul 12, 2018
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
10 changes: 10 additions & 0 deletions executor/aggfuncs/aggfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import (
// All the AggFunc implementations are listed here for navigation.
var (
// All the AggFunc implementations for "COUNT" are listed here.
_ AggFunc = (*countPartial)(nil)
_ AggFunc = (*countOriginal4Int)(nil)
_ AggFunc = (*countOriginal4Real)(nil)
_ AggFunc = (*countOriginal4Decimal)(nil)
_ AggFunc = (*countOriginal4Time)(nil)
_ AggFunc = (*countOriginal4Duration)(nil)
_ AggFunc = (*countOriginal4JSON)(nil)
_ AggFunc = (*countOriginal4String)(nil)
_ AggFunc = (*countOriginalWithDistinct)(nil)

// All the AggFunc implementations for "SUM" are listed here.
// All the AggFunc implementations for "FIRSTROW" are listed here.
// All the AggFunc implementations for "MAX"/"MIN" are listed here.
Expand Down
39 changes: 39 additions & 0 deletions executor/aggfuncs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,45 @@ func Build(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {

// buildCount builds the AggFunc implementation for function "COUNT".
func buildCount(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
// If mode is DedupMode, we return nil for not implemented.
if aggFuncDesc.Mode == aggregation.DedupMode {
return nil // not implemented yet.
}

base := baseAggFunc{
args: aggFuncDesc.Args,
ordinal: ordinal,
}

// If HasDistinct and mode is CompleteMode or Partial1Mode, we should
// use countOriginalWithDistinct.
if aggFuncDesc.HasDistinct &&
(aggFuncDesc.Mode == aggregation.CompleteMode || aggFuncDesc.Mode == aggregation.Partial1Mode) {
return &countOriginalWithDistinct{baseCount{base}}
}

switch aggFuncDesc.Mode {
case aggregation.CompleteMode, aggregation.Partial1Mode:
switch aggFuncDesc.Args[0].GetType().EvalType() {
case types.ETInt:
return &countOriginal4Int{baseCount{base}}
case types.ETReal:
return &countOriginal4Real{baseCount{base}}
case types.ETDecimal:
return &countOriginal4Decimal{baseCount{base}}
case types.ETTimestamp, types.ETDatetime:
return &countOriginal4Time{baseCount{base}}
case types.ETDuration:
return &countOriginal4Duration{baseCount{base}}
case types.ETJson:
return &countOriginal4JSON{baseCount{base}}
case types.ETString:
return &countOriginal4String{baseCount{base}}
}
case aggregation.Partial2Mode, aggregation.FinalMode:
return &countPartial{baseCount{base}}
}

return nil
}

Expand Down
Loading