Skip to content

Commit

Permalink
*: let baseFuncDesc.typeInfer return error instead of panic (#10910)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu authored and qw4990 committed Jun 24, 2019
1 parent a0b4d0e commit c59028a
Show file tree
Hide file tree
Showing 19 changed files with 252 additions and 93 deletions.
6 changes: 2 additions & 4 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,8 @@ TableReader_7 10000.00 root data:TableScan_6
└─TableScan_6 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select distinct t1.a, t1.b from t1 left outer join t2 on t1.a = t2.a;
id count task operator info
StreamAgg_18 8000.00 root group by:col_2, col_3, funcs:firstrow(col_0), firstrow(col_1)
└─IndexReader_19 8000.00 root index:StreamAgg_10
└─StreamAgg_10 8000.00 cop group by:test.t1.a, test.t1.b, funcs:firstrow(test.t1.a), firstrow(test.t1.b)
└─IndexScan_17 10000.00 cop table:t1, index:a, b, range:[NULL,+inf], keep order:true, stats:pseudo
TableReader_9 10000.00 root data:TableScan_8
└─TableScan_8 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
drop table if exists t;
create table t(a int, nb int not null, nc int not null);
explain select ifnull(a, 0) from t;
Expand Down
9 changes: 6 additions & 3 deletions executor/aggfuncs/aggfunc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (s *testSuite) testMergePartialResult(c *C, p aggTest) {
if p.funcName == ast.AggFuncGroupConcat {
args = append(args, &expression.Constant{Value: types.NewStringDatum(" "), RetType: types.NewFieldType(mysql.TypeString)})
}
desc := aggregation.NewAggFuncDesc(s.ctx, p.funcName, args, false)
desc, err := aggregation.NewAggFuncDesc(s.ctx, p.funcName, args, false)
c.Assert(err, IsNil)
partialDesc, finalDesc := desc.Split([]int{0, 1})

// build partial func for partial phase.
Expand Down Expand Up @@ -183,7 +184,8 @@ func (s *testSuite) testAggFunc(c *C, p aggTest) {
if p.funcName == ast.AggFuncGroupConcat {
args = append(args, &expression.Constant{Value: types.NewStringDatum(" "), RetType: types.NewFieldType(mysql.TypeString)})
}
desc := aggregation.NewAggFuncDesc(s.ctx, p.funcName, args, false)
desc, err := aggregation.NewAggFuncDesc(s.ctx, p.funcName, args, false)
c.Assert(err, IsNil)
finalFunc := aggfuncs.Build(s.ctx, desc, 0)
finalPr := finalFunc.AllocPartialResult()
resultChk := chunk.NewChunkWithCapacity([]*types.FieldType{desc.RetTp}, 1)
Expand All @@ -208,7 +210,8 @@ func (s *testSuite) testAggFunc(c *C, p aggTest) {
c.Assert(result, Equals, 0)

// test the agg func with distinct
desc = aggregation.NewAggFuncDesc(s.ctx, p.funcName, args, true)
desc, err = aggregation.NewAggFuncDesc(s.ctx, p.funcName, args, true)
c.Assert(err, IsNil)
finalFunc = aggfuncs.Build(s.ctx, desc, 0)
finalPr = finalFunc.AllocPartialResult()

Expand Down
3 changes: 2 additions & 1 deletion executor/aggfuncs/window_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (s *testSuite) testWindowFunc(c *C, p windowTest) {
srcChk.AppendDatum(0, &dt)
}

desc := aggregation.NewAggFuncDesc(s.ctx, p.funcName, p.args, false)
desc, err := aggregation.NewAggFuncDesc(s.ctx, p.funcName, p.args, false)
c.Assert(err, IsNil)
finalFunc := aggfuncs.BuildWindowFunctions(s.ctx, desc, 0, p.orderByCols)
finalPr := finalFunc.AllocPartialResult()
resultChk := chunk.NewChunkWithCapacity([]*types.FieldType{desc.RetTp}, 1)
Expand Down
17 changes: 17 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package executor_test

import (
. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/parser/terror"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/util/testkit"
Expand Down Expand Up @@ -334,6 +335,22 @@ func (s *testSuite1) TestAggregation(c *C) {
tk.MustExec("insert into t value(0), (-0.9871), (-0.9871)")
tk.MustQuery("select 10 from t group by a").Check(testkit.Rows("10", "10"))
tk.MustQuery("select sum(a) from (select a from t union all select a from t) tmp").Check(testkit.Rows("-3.9484"))
_, err = tk.Exec("select std(a) from t")
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: std")
_, err = tk.Exec("select stddev(a) from t")
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: stddev")
_, err = tk.Exec("select stddev_pop(a) from t")
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: stddev_pop")
_, err = tk.Exec("select std_samp(a) from t")
// TODO: Fix this error message.
c.Assert(errors.Cause(err).Error(), Equals, "[expression:1305]FUNCTION std_samp does not exist")
_, err = tk.Exec("select variance(a) from t")
// TODO: Fix this error message.
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: var_pop")
_, err = tk.Exec("select var_pop(a) from t")
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: var_pop")
_, err = tk.Exec("select var_samp(a) from t")
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: var_samp")
}

func (s *testSuite1) TestStreamAggPushDown(c *C) {
Expand Down
5 changes: 4 additions & 1 deletion executor/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ func buildAggExecutor(b *testing.B, testCase *aggTestCase, child Executor) Execu
childCols := testCase.columns()
schema := expression.NewSchema(childCols...)
groupBy := []expression.Expression{childCols[1]}
aggFunc := aggregation.NewAggFuncDesc(testCase.ctx, testCase.aggFunc, []expression.Expression{childCols[0]}, testCase.hasDistinct)
aggFunc, err := aggregation.NewAggFuncDesc(testCase.ctx, testCase.aggFunc, []expression.Expression{childCols[0]}, testCase.hasDistinct)
if err != nil {
b.Fatal(err)
}
aggFuncs := []*aggregation.AggFuncDesc{aggFunc}

var aggExec Executor
Expand Down
6 changes: 5 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,11 @@ func (b *executorBuilder) buildWindow(v *plannercore.PhysicalWindow) *WindowExec
partialResults := make([]aggfuncs.PartialResult, 0, len(v.WindowFuncDescs))
resultColIdx := v.Schema().Len() - len(v.WindowFuncDescs)
for _, desc := range v.WindowFuncDescs {
aggDesc := aggregation.NewAggFuncDesc(b.ctx, desc.Name, desc.Args, false)
aggDesc, err := aggregation.NewAggFuncDesc(b.ctx, desc.Name, desc.Args, false)
if err != nil {
b.err = err
return nil
}
agg := aggfuncs.BuildWindowFunctions(b.ctx, aggDesc, resultColIdx, orderByCols)
windowFuncs = append(windowFuncs, agg)
partialResults = append(partialResults, agg.AllocPartialResult())
Expand Down
6 changes: 4 additions & 2 deletions executor/executor_required_rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ func (s *testExecSuite) TestStreamAggRequiredRows(c *C) {
childCols := ds.Schema().Columns
schema := expression.NewSchema(childCols...)
groupBy := []expression.Expression{childCols[1]}
aggFunc := aggregation.NewAggFuncDesc(sctx, testCase.aggFunc, []expression.Expression{childCols[0]}, true)
aggFunc, err := aggregation.NewAggFuncDesc(sctx, testCase.aggFunc, []expression.Expression{childCols[0]}, true)
c.Assert(err, IsNil)
aggFuncs := []*aggregation.AggFuncDesc{aggFunc}
exec := buildStreamAggExecutor(sctx, ds, schema, aggFuncs, groupBy)
c.Assert(exec.Open(ctx), IsNil)
Expand Down Expand Up @@ -718,7 +719,8 @@ func (s *testExecSuite) TestHashAggParallelRequiredRows(c *C) {
childCols := ds.Schema().Columns
schema := expression.NewSchema(childCols...)
groupBy := []expression.Expression{childCols[1]}
aggFunc := aggregation.NewAggFuncDesc(sctx, testCase.aggFunc, []expression.Expression{childCols[0]}, hasDistinct)
aggFunc, err := aggregation.NewAggFuncDesc(sctx, testCase.aggFunc, []expression.Expression{childCols[0]}, hasDistinct)
c.Assert(err, IsNil)
aggFuncs := []*aggregation.AggFuncDesc{aggFunc}
exec := buildHashAggExecutor(sctx, ds, schema, aggFuncs, groupBy)
c.Assert(exec.Open(ctx), IsNil)
Expand Down
6 changes: 4 additions & 2 deletions expression/aggregation/agg_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (s *testEvaluatorSuite) TestAggFunc2Pb(c *C) {
}
for _, funcName := range funcNames {
args := []expression.Expression{dg.genColumn(mysql.TypeDouble, 1)}
aggFunc := NewAggFuncDesc(s.ctx, funcName, args, true)
aggFunc, err := NewAggFuncDesc(s.ctx, funcName, args, true)
c.Assert(err, IsNil)
pbExpr := AggFuncToPBExpr(sc, client, aggFunc)
js, err := json.Marshal(pbExpr)
c.Assert(err, IsNil)
Expand All @@ -94,7 +95,8 @@ func (s *testEvaluatorSuite) TestAggFunc2Pb(c *C) {
}
for i, funcName := range funcNames {
args := []expression.Expression{dg.genColumn(mysql.TypeDouble, 1)}
aggFunc := NewAggFuncDesc(s.ctx, funcName, args, false)
aggFunc, err := NewAggFuncDesc(s.ctx, funcName, args, false)
c.Assert(err, IsNil)
aggFunc.RetTp = funcTypes[i]
pbExpr := AggFuncToPBExpr(sc, client, aggFunc)
js, err := json.Marshal(pbExpr)
Expand Down
77 changes: 53 additions & 24 deletions expression/aggregation/aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func (s *testAggFuncSuit) TestAvg(c *C) {
RetType: types.NewFieldType(mysql.TypeLonglong),
}
ctx := mock.NewContext()
avgFunc := NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{col}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{col}, false)
c.Assert(err, IsNil)
avgFunc := desc.GetAggFunc(ctx)
evalCtx := avgFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

result := avgFunc.GetResult(evalCtx)
Expand All @@ -71,12 +73,14 @@ func (s *testAggFuncSuit) TestAvg(c *C) {
result = avgFunc.GetResult(evalCtx)
needed := types.NewDecFromStringForTest("67.000000000000000000000000000000")
c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)
err := avgFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)
err = avgFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)
c.Assert(err, IsNil)
result = avgFunc.GetResult(evalCtx)
c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)

distinctAvgFunc := NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{col}, true).GetAggFunc(ctx)
desc, err = NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{col}, true)
c.Assert(err, IsNil)
distinctAvgFunc := desc.GetAggFunc(ctx)
evalCtx = distinctAvgFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)
for _, row := range s.rows {
err := distinctAvgFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
Expand Down Expand Up @@ -105,7 +109,8 @@ func (s *testAggFuncSuit) TestAvgFinalMode(c *C) {
Index: 1,
RetType: types.NewFieldType(mysql.TypeNewDecimal),
}
aggFunc := NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{cntCol, sumCol}, false)
aggFunc, err := NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{cntCol, sumCol}, false)
c.Assert(err, IsNil)
aggFunc.Mode = FinalMode
avgFunc := aggFunc.GetAggFunc(ctx)
evalCtx := avgFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)
Expand All @@ -125,7 +130,9 @@ func (s *testAggFuncSuit) TestSum(c *C) {
RetType: types.NewFieldType(mysql.TypeLonglong),
}
ctx := mock.NewContext()
sumFunc := NewAggFuncDesc(s.ctx, ast.AggFuncSum, []expression.Expression{col}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncSum, []expression.Expression{col}, false)
c.Assert(err, IsNil)
sumFunc := desc.GetAggFunc(ctx)
evalCtx := sumFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

result := sumFunc.GetResult(evalCtx)
Expand All @@ -138,14 +145,16 @@ func (s *testAggFuncSuit) TestSum(c *C) {
result = sumFunc.GetResult(evalCtx)
needed := types.NewDecFromStringForTest("338350")
c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)
err := sumFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)
err = sumFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)
c.Assert(err, IsNil)
result = sumFunc.GetResult(evalCtx)
c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)
partialResult := sumFunc.GetPartialResult(evalCtx)
c.Assert(partialResult[0].GetMysqlDecimal().Compare(needed) == 0, IsTrue)

distinctSumFunc := NewAggFuncDesc(s.ctx, ast.AggFuncSum, []expression.Expression{col}, true).GetAggFunc(ctx)
desc, err = NewAggFuncDesc(s.ctx, ast.AggFuncSum, []expression.Expression{col}, true)
c.Assert(err, IsNil)
distinctSumFunc := desc.GetAggFunc(ctx)
evalCtx = distinctSumFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)
for _, row := range s.rows {
err := distinctSumFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
Expand All @@ -162,14 +171,16 @@ func (s *testAggFuncSuit) TestBitAnd(c *C) {
RetType: types.NewFieldType(mysql.TypeLonglong),
}
ctx := mock.NewContext()
bitAndFunc := NewAggFuncDesc(s.ctx, ast.AggFuncBitAnd, []expression.Expression{col}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncBitAnd, []expression.Expression{col}, false)
c.Assert(err, IsNil)
bitAndFunc := desc.GetAggFunc(ctx)
evalCtx := bitAndFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

result := bitAndFunc.GetResult(evalCtx)
c.Assert(result.GetUint64(), Equals, uint64(math.MaxUint64))

row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()
err := bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
c.Assert(err, IsNil)
result = bitAndFunc.GetResult(evalCtx)
c.Assert(result.GetUint64(), Equals, uint64(1))
Expand Down Expand Up @@ -238,14 +249,16 @@ func (s *testAggFuncSuit) TestBitOr(c *C) {
RetType: types.NewFieldType(mysql.TypeLonglong),
}
ctx := mock.NewContext()
bitOrFunc := NewAggFuncDesc(s.ctx, ast.AggFuncBitOr, []expression.Expression{col}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncBitOr, []expression.Expression{col}, false)
c.Assert(err, IsNil)
bitOrFunc := desc.GetAggFunc(ctx)
evalCtx := bitOrFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

result := bitOrFunc.GetResult(evalCtx)
c.Assert(result.GetUint64(), Equals, uint64(0))

row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()
err := bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
c.Assert(err, IsNil)
result = bitOrFunc.GetResult(evalCtx)
c.Assert(result.GetUint64(), Equals, uint64(1))
Expand Down Expand Up @@ -322,14 +335,16 @@ func (s *testAggFuncSuit) TestBitXor(c *C) {
RetType: types.NewFieldType(mysql.TypeLonglong),
}
ctx := mock.NewContext()
bitXorFunc := NewAggFuncDesc(s.ctx, ast.AggFuncBitXor, []expression.Expression{col}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncBitXor, []expression.Expression{col}, false)
c.Assert(err, IsNil)
bitXorFunc := desc.GetAggFunc(ctx)
evalCtx := bitXorFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

result := bitXorFunc.GetResult(evalCtx)
c.Assert(result.GetUint64(), Equals, uint64(0))

row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()
err := bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
c.Assert(err, IsNil)
result = bitXorFunc.GetResult(evalCtx)
c.Assert(result.GetUint64(), Equals, uint64(1))
Expand Down Expand Up @@ -398,7 +413,9 @@ func (s *testAggFuncSuit) TestCount(c *C) {
RetType: types.NewFieldType(mysql.TypeLonglong),
}
ctx := mock.NewContext()
countFunc := NewAggFuncDesc(s.ctx, ast.AggFuncCount, []expression.Expression{col}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncCount, []expression.Expression{col}, false)
c.Assert(err, IsNil)
countFunc := desc.GetAggFunc(ctx)
evalCtx := countFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

result := countFunc.GetResult(evalCtx)
Expand All @@ -410,14 +427,16 @@ func (s *testAggFuncSuit) TestCount(c *C) {
}
result = countFunc.GetResult(evalCtx)
c.Assert(result.GetInt64(), Equals, int64(5050))
err := countFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)
err = countFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)
c.Assert(err, IsNil)
result = countFunc.GetResult(evalCtx)
c.Assert(result.GetInt64(), Equals, int64(5050))
partialResult := countFunc.GetPartialResult(evalCtx)
c.Assert(partialResult[0].GetInt64(), Equals, int64(5050))

distinctCountFunc := NewAggFuncDesc(s.ctx, ast.AggFuncCount, []expression.Expression{col}, true).GetAggFunc(ctx)
desc, err = NewAggFuncDesc(s.ctx, ast.AggFuncCount, []expression.Expression{col}, true)
c.Assert(err, IsNil)
distinctCountFunc := desc.GetAggFunc(ctx)
evalCtx = distinctCountFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

for _, row := range s.rows {
Expand All @@ -438,14 +457,16 @@ func (s *testAggFuncSuit) TestConcat(c *C) {
RetType: types.NewFieldType(mysql.TypeVarchar),
}
ctx := mock.NewContext()
concatFunc := NewAggFuncDesc(s.ctx, ast.AggFuncGroupConcat, []expression.Expression{col, sep}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncGroupConcat, []expression.Expression{col, sep}, false)
c.Assert(err, IsNil)
concatFunc := desc.GetAggFunc(ctx)
evalCtx := concatFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

result := concatFunc.GetResult(evalCtx)
c.Assert(result.IsNull(), IsTrue)

row := chunk.MutRowFromDatums(types.MakeDatums(1, "x"))
err := concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())
err = concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())
c.Assert(err, IsNil)
result = concatFunc.GetResult(evalCtx)
c.Assert(result.GetString(), Equals, "1")
Expand All @@ -464,7 +485,9 @@ func (s *testAggFuncSuit) TestConcat(c *C) {
partialResult := concatFunc.GetPartialResult(evalCtx)
c.Assert(partialResult[0].GetString(), Equals, "1x2")

distinctConcatFunc := NewAggFuncDesc(s.ctx, ast.AggFuncGroupConcat, []expression.Expression{col, sep}, true).GetAggFunc(ctx)
desc, err = NewAggFuncDesc(s.ctx, ast.AggFuncGroupConcat, []expression.Expression{col, sep}, true)
c.Assert(err, IsNil)
distinctConcatFunc := desc.GetAggFunc(ctx)
evalCtx = distinctConcatFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

row.SetDatum(0, types.NewIntDatum(1))
Expand All @@ -487,11 +510,13 @@ func (s *testAggFuncSuit) TestFirstRow(c *C) {
}

ctx := mock.NewContext()
firstRowFunc := NewAggFuncDesc(s.ctx, ast.AggFuncFirstRow, []expression.Expression{col}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncFirstRow, []expression.Expression{col}, false)
c.Assert(err, IsNil)
firstRowFunc := desc.GetAggFunc(ctx)
evalCtx := firstRowFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()
err := firstRowFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
err = firstRowFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)
c.Assert(err, IsNil)
result := firstRowFunc.GetResult(evalCtx)
c.Assert(result.GetUint64(), Equals, uint64(1))
Expand All @@ -512,8 +537,12 @@ func (s *testAggFuncSuit) TestMaxMin(c *C) {
}

ctx := mock.NewContext()
maxFunc := NewAggFuncDesc(s.ctx, ast.AggFuncMax, []expression.Expression{col}, false).GetAggFunc(ctx)
minFunc := NewAggFuncDesc(s.ctx, ast.AggFuncMin, []expression.Expression{col}, false).GetAggFunc(ctx)
desc, err := NewAggFuncDesc(s.ctx, ast.AggFuncMax, []expression.Expression{col}, false)
c.Assert(err, IsNil)
maxFunc := desc.GetAggFunc(ctx)
desc, err = NewAggFuncDesc(s.ctx, ast.AggFuncMin, []expression.Expression{col}, false)
c.Assert(err, IsNil)
minFunc := desc.GetAggFunc(ctx)
maxEvalCtx := maxFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)
minEvalCtx := minFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)

Expand All @@ -523,7 +552,7 @@ func (s *testAggFuncSuit) TestMaxMin(c *C) {
c.Assert(result.IsNull(), IsTrue)

row := chunk.MutRowFromDatums(types.MakeDatums(2))
err := maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())
err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())
c.Assert(err, IsNil)
result = maxFunc.GetResult(maxEvalCtx)
c.Assert(result.GetInt64(), Equals, int64(2))
Expand Down
Loading

0 comments on commit c59028a

Please sign in to comment.