Skip to content

Commit

Permalink
executor: support MAX/MIN in new evaluation framework partially (#6971)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu committed Jul 12, 2018
1 parent 4616636 commit 0ef52ac
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 22 deletions.
16 changes: 10 additions & 6 deletions executor/aggfuncs/aggfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import (
var (
// All the AggFunc implementations for "COUNT" are listed here.
// 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.
_ AggFunc = (*maxMin4Int)(nil)
_ AggFunc = (*maxMin4Float32)(nil)
_ AggFunc = (*maxMin4Float64)(nil)
_ AggFunc = (*maxMin4Decimal)(nil)

// All the AggFunc implementations for "AVG" are listed here.
_ AggFunc = (*avgOriginal4Decimal)(nil)
_ AggFunc = (*avgOriginal4DistinctDecimal)(nil)
Expand All @@ -34,15 +41,12 @@ var (
_ AggFunc = (*avgPartial4Float64)(nil)
_ AggFunc = (*avgOriginal4DistinctFloat64)(nil)

// All the AggFunc implementations for "FIRSTROW" are listed here.
// All the AggFunc implementations for "MAX" are listed here.
// All the AggFunc implementations for "MIN" are listed here.
// All the AggFunc implementations for "GROUP_CONCAT" are listed here.
// All the AggFunc implementations for "BIT_OR" are listed here.
// All the AggFunc implementations for "BIT_XOR" are listed here.
// All the AggFunc implementations for "BIT_AND" are listed here.
// All the AggFunc implementations for "BIT_OR" are listed here.
_ AggFunc = (*bitOrUint64)(nil)

// All the AggFunc implementations for "BIT_XOR" are listed here.
// All the AggFunc implementations for "BIT_AND" are listed here.
)

// PartialResult represents data structure to store the partial result for the
Expand Down
54 changes: 39 additions & 15 deletions executor/aggfuncs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func Build(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
case ast.AggFuncFirstRow:
return buildFirstRow(aggFuncDesc, ordinal)
case ast.AggFuncMax:
return buildMax(aggFuncDesc, ordinal)
return buildMaxMin(aggFuncDesc, ordinal, true)
case ast.AggFuncMin:
return buildMin(aggFuncDesc, ordinal)
return buildMaxMin(aggFuncDesc, ordinal, false)
case ast.AggFuncGroupConcat:
return buildGroupConcat(aggFuncDesc, ordinal)
case ast.AggFuncBitOr:
Expand All @@ -53,12 +53,12 @@ func buildCount(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}

// buildCount builds the AggFunc implementation for function "SUM".
// buildSum builds the AggFunc implementation for function "SUM".
func buildSum(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}

// buildCount builds the AggFunc implementation for function "AVG".
// buildAvg builds the AggFunc implementation for function "AVG".
func buildAvg(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
base := baseAggFunc{
args: aggFuncDesc.Args,
Expand Down Expand Up @@ -99,27 +99,51 @@ func buildAvg(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}

// buildCount builds the AggFunc implementation for function "FIRST_ROW".
// buildFirstRow builds the AggFunc implementation for function "FIRST_ROW".
func buildFirstRow(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}

// buildCount builds the AggFunc implementation for function "MAX".
func buildMax(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}
// buildMaxMin builds the AggFunc implementation for function "MAX" and "MIN".
func buildMaxMin(aggFuncDesc *aggregation.AggFuncDesc, ordinal int, isMax bool) AggFunc {
base := baseMaxMinAggFunc{
baseAggFunc: baseAggFunc{
args: aggFuncDesc.Args,
ordinal: ordinal,
},
isMax: isMax,
}

// buildCount builds the AggFunc implementation for function "MIN".
func buildMin(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
evalType, fieldType := aggFuncDesc.RetTp.EvalType(), aggFuncDesc.RetTp
switch aggFuncDesc.Mode {
case aggregation.DedupMode:
default:
switch evalType {
case types.ETInt:
if mysql.HasUnsignedFlag(fieldType.Flag) {
return &maxMin4Uint{base}
}
return &maxMin4Int{base}
case types.ETReal:
switch fieldType.Tp {
case mysql.TypeFloat:
return &maxMin4Float32{base}
case mysql.TypeDouble:
return &maxMin4Float64{base}
}
case types.ETDecimal:
return &maxMin4Decimal{base}
}
}
return nil
}

// buildCount builds the AggFunc implementation for function "GROUP_CONCAT".
// buildGroupConcat builds the AggFunc implementation for function "GROUP_CONCAT".
func buildGroupConcat(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}

// buildCount builds the AggFunc implementation for function "BIT_OR".
// buildBitOr builds the AggFunc implementation for function "BIT_OR".
func buildBitOr(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
// BIT_OR doesn't need to handle the distinct property.
switch aggFuncDesc.Args[0].GetType().EvalType() {
Expand All @@ -133,12 +157,12 @@ func buildBitOr(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}

// buildCount builds the AggFunc implementation for function "BIT_XOR".
// buildBitXor builds the AggFunc implementation for function "BIT_XOR".
func buildBitXor(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}

// buildCount builds the AggFunc implementation for function "BIT_AND".
// buildBitAnd builds the AggFunc implementation for function "BIT_AND".
func buildBitAnd(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
return nil
}
Loading

0 comments on commit 0ef52ac

Please sign in to comment.