Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu committed Jul 11, 2018
1 parent 208e283 commit 4f2e0a4
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions executor/aggfuncs/func_max_min.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ type baseMaxMinAggFunc struct {
baseAggFunc

isMax bool
// executed is used to indicates whether the partial result
// is the initialization value which should not be compared
// during evaluation.
// executed is used to indicates:
// 1. whether the partial result is the initialization value which should not be compared during evaluation;
// 2. whether all the values of arg are all null, if so, we should return null as the default value for MAX/MIN.
executed bool
}

Expand All @@ -55,6 +55,10 @@ func (e *maxMin4Int) ResetPartialResult(pr PartialResult) {
}

func (e *maxMin4Int) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
if !e.executed {
chk.AppendNull(e.ordinal)
return nil
}
chk.AppendInt64(e.ordinal, *(*partialResult4MaxMinInt)(pr))
return nil
}
Expand Down Expand Up @@ -94,6 +98,10 @@ func (e *maxMin4Uint) ResetPartialResult(pr PartialResult) {
}

func (e *maxMin4Uint) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
if !e.executed {
chk.AppendNull(e.ordinal)
return nil
}
chk.AppendUint64(e.ordinal, *(*partialResult4MaxMinUint)(pr))
return nil
}
Expand Down Expand Up @@ -135,6 +143,10 @@ func (e *maxMin4Float32) ResetPartialResult(pr PartialResult) {
}

func (e *maxMin4Float32) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
if !e.executed {
chk.AppendNull(e.ordinal)
return nil
}
chk.AppendFloat32(e.ordinal, *(*partialResult4MaxMinFloat32)(pr))
return nil
}
Expand Down Expand Up @@ -175,6 +187,10 @@ func (e *maxMin4Float64) ResetPartialResult(pr PartialResult) {
}

func (e *maxMin4Float64) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
if !e.executed {
chk.AppendNull(e.ordinal)
return nil
}
chk.AppendFloat64(e.ordinal, *(*partialResult4MaxMinFloat64)(pr))
return nil
}
Expand Down Expand Up @@ -214,6 +230,10 @@ func (e *maxMin4Decimal) ResetPartialResult(pr PartialResult) {
}

func (e *maxMin4Decimal) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
if !e.executed {
chk.AppendNull(e.ordinal)
return nil
}
chk.AppendMyDecimal(e.ordinal, *(*partialResult4MaxMinDecimal)(pr))
return nil
}
Expand Down

0 comments on commit 4f2e0a4

Please sign in to comment.