diff --git a/executor/pkg_test.go b/executor/pkg_test.go index c2e40dd3ba4ab..40d4c5670291e 100644 --- a/executor/pkg_test.go +++ b/executor/pkg_test.go @@ -22,7 +22,7 @@ type pkgTestSuite struct { type MockExec struct { baseExecutor - Rows []types.DatumRow + Rows []chunk.MutRow curRowIdx int } @@ -31,8 +31,8 @@ func (m *MockExec) Next(ctx context.Context, chk *chunk.Chunk) error { colTypes := m.retTypes() for ; m.curRowIdx < len(m.Rows) && chk.NumRows() < m.maxChunkSize; m.curRowIdx++ { curRow := m.Rows[m.curRowIdx] - for i := 0; i < len(curRow); i++ { - curDatum := curRow.GetDatum(i, colTypes[i]) + for i := 0; i < curRow.Len(); i++ { + curDatum := curRow.ToRow().GetDatum(i, colTypes[i]) chk.AppendDatum(i, &curDatum) } } @@ -58,24 +58,24 @@ func (s *pkgTestSuite) TestNestedLoopApply(c *C) { outerSchema := expression.NewSchema(col0) outerExec := &MockExec{ baseExecutor: newBaseExecutor(sctx, outerSchema, ""), - Rows: []types.DatumRow{ - types.MakeDatums(1), - types.MakeDatums(2), - types.MakeDatums(3), - types.MakeDatums(4), - types.MakeDatums(5), - types.MakeDatums(6), + Rows: []chunk.MutRow{ + chunk.MutRowFromDatums(types.MakeDatums(1)), + chunk.MutRowFromDatums(types.MakeDatums(2)), + chunk.MutRowFromDatums(types.MakeDatums(3)), + chunk.MutRowFromDatums(types.MakeDatums(4)), + chunk.MutRowFromDatums(types.MakeDatums(5)), + chunk.MutRowFromDatums(types.MakeDatums(6)), }} innerSchema := expression.NewSchema(col1) innerExec := &MockExec{ baseExecutor: newBaseExecutor(sctx, innerSchema, ""), - Rows: []types.DatumRow{ - types.MakeDatums(1), - types.MakeDatums(2), - types.MakeDatums(3), - types.MakeDatums(4), - types.MakeDatums(5), - types.MakeDatums(6), + Rows: []chunk.MutRow{ + chunk.MutRowFromDatums(types.MakeDatums(1)), + chunk.MutRowFromDatums(types.MakeDatums(2)), + chunk.MutRowFromDatums(types.MakeDatums(3)), + chunk.MutRowFromDatums(types.MakeDatums(4)), + chunk.MutRowFromDatums(types.MakeDatums(5)), + chunk.MutRowFromDatums(types.MakeDatums(6)), }} outerFilter := expression.NewFunctionInternal(sctx, ast.LT, types.NewFieldType(mysql.TypeTiny), col0, con) innerFilter := outerFilter.Clone() diff --git a/expression/aggregation/aggregation_test.go b/expression/aggregation/aggregation_test.go index 50334aedadc20..6352aff9d4dfc 100644 --- a/expression/aggregation/aggregation_test.go +++ b/expression/aggregation/aggregation_test.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" + "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/mock" ) @@ -29,15 +30,15 @@ var _ = Suite(&testAggFuncSuit{}) type testAggFuncSuit struct { ctx sessionctx.Context - rows []types.DatumRow - nullRow types.DatumRow + rows []chunk.Row + nullRow chunk.Row } -func generateRowData() []types.DatumRow { - rows := make([]types.DatumRow, 0, 5050) +func generateRowData() []chunk.Row { + rows := make([]chunk.Row, 0, 5050) for i := 1; i <= 100; i++ { for j := 0; j < i; j++ { - rows = append(rows, types.MakeDatums(i)) + rows = append(rows, chunk.MutRowFromDatums(types.MakeDatums(i)).ToRow()) } } return rows @@ -46,7 +47,7 @@ func generateRowData() []types.DatumRow { func (s *testAggFuncSuit) SetUpSuite(c *C) { s.ctx = mock.NewContext() s.rows = generateRowData() - s.nullRow = []types.Datum{{}} + s.nullRow = chunk.MutRowFromDatums([]types.Datum{{}}).ToRow() } func (s *testAggFuncSuit) TestAvg(c *C) { @@ -161,8 +162,8 @@ func (s *testAggFuncSuit) TestBitAnd(c *C) { result := bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(math.MaxUint64)) - row := types.MakeDatums(1) - err := bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow() + err := bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) @@ -172,20 +173,20 @@ func (s *testAggFuncSuit) TestBitAnd(c *C) { result = bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) - row = types.MakeDatums(1) - err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow() + err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) - row = types.MakeDatums(3) - err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(3)).ToRow() + err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) - row = types.MakeDatums(2) - err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(2)).ToRow() + err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(0)) @@ -202,24 +203,24 @@ func (s *testAggFuncSuit) TestBitAnd(c *C) { var dec types.MyDecimal err = dec.FromString([]byte("1.234")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) err = dec.FromString([]byte("3.012")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) err = dec.FromString([]byte("2.12345678")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitAndFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(0)) @@ -236,8 +237,8 @@ func (s *testAggFuncSuit) TestBitOr(c *C) { result := bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(0)) - row := types.MakeDatums(1) - err := bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow() + err := bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) @@ -247,20 +248,20 @@ func (s *testAggFuncSuit) TestBitOr(c *C) { result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) - row = types.MakeDatums(1) - err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow() + err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) - row = types.MakeDatums(3) - err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(3)).ToRow() + err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(3)) - row = types.MakeDatums(2) - err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(2)).ToRow() + err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(3)) @@ -277,32 +278,32 @@ func (s *testAggFuncSuit) TestBitOr(c *C) { var dec types.MyDecimal err = dec.FromString([]byte("12.234")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(12)) err = dec.FromString([]byte("1.012")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(13)) err = dec.FromString([]byte("15.12345678")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(15)) err = dec.FromString([]byte("16.00")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitOrFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(31)) @@ -319,8 +320,8 @@ func (s *testAggFuncSuit) TestBitXor(c *C) { result := bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(0)) - row := types.MakeDatums(1) - err := bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow() + err := bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) @@ -330,20 +331,20 @@ func (s *testAggFuncSuit) TestBitXor(c *C) { result = bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) - row = types.MakeDatums(1) - err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow() + err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(0)) - row = types.MakeDatums(3) - err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(3)).ToRow() + err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(3)) - row = types.MakeDatums(2) - err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(2)).ToRow() + err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) @@ -360,24 +361,24 @@ func (s *testAggFuncSuit) TestBitXor(c *C) { var dec types.MyDecimal err = dec.FromString([]byte("1.234")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) err = dec.FromString([]byte("1.012")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(0)) err = dec.FromString([]byte("2.12345678")) c.Assert(err, IsNil) - row = types.MakeDatums(&dec) - err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow() + err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = bitXorFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(2)) @@ -395,7 +396,7 @@ func (s *testAggFuncSuit) TestCount(c *C) { c.Assert(result.GetInt64(), Equals, int64(0)) for _, row := range s.rows { - err := countFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + err := countFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) } result = countFunc.GetResult(evalCtx) @@ -411,7 +412,7 @@ func (s *testAggFuncSuit) TestCount(c *C) { evalCtx = distinctCountFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx) for _, row := range s.rows { - err := distinctCountFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + err := distinctCountFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) } result = distinctCountFunc.GetResult(evalCtx) @@ -433,20 +434,20 @@ func (s *testAggFuncSuit) TestConcat(c *C) { result := concatFunc.GetResult(evalCtx) c.Assert(result.IsNull(), IsTrue) - row := types.MakeDatums(1, "x") - err := concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row := chunk.MutRowFromDatums(types.MakeDatums(1, "x")) + err := concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = concatFunc.GetResult(evalCtx) c.Assert(result.GetString(), Equals, "1") - row[0].SetInt64(2) - err = concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row.SetDatum(0, types.NewIntDatum(2)) + err = concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = concatFunc.GetResult(evalCtx) c.Assert(result.GetString(), Equals, "1x2") - row[0].SetNull() - err = concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row.SetDatum(0, types.NewDatum(nil)) + err = concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = concatFunc.GetResult(evalCtx) c.Assert(result.GetString(), Equals, "1x2") @@ -456,14 +457,14 @@ func (s *testAggFuncSuit) TestConcat(c *C) { distinctConcatFunc := NewAggFuncDesc(s.ctx, ast.AggFuncGroupConcat, []expression.Expression{col, sep}, true).GetAggFunc() evalCtx = distinctConcatFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx) - row[0].SetInt64(1) - err = distinctConcatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row.SetDatum(0, types.NewIntDatum(1)) + err = distinctConcatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = distinctConcatFunc.GetResult(evalCtx) c.Assert(result.GetString(), Equals, "1") - row[0].SetInt64(1) - err = distinctConcatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row.SetDatum(0, types.NewIntDatum(1)) + err = distinctConcatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = distinctConcatFunc.GetResult(evalCtx) c.Assert(result.GetString(), Equals, "1") @@ -478,14 +479,14 @@ func (s *testAggFuncSuit) TestFirstRow(c *C) { firstRowFunc := NewAggFuncDesc(s.ctx, ast.AggFuncFirstRow, []expression.Expression{col}, false).GetAggFunc() evalCtx := firstRowFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx) - row := types.MakeDatums(1) - err := firstRowFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow() + err := firstRowFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result := firstRowFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) - row = types.MakeDatums(2) - err = firstRowFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row = chunk.MutRowFromDatums(types.MakeDatums(2)).ToRow() + err = firstRowFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row) c.Assert(err, IsNil) result = firstRowFunc.GetResult(evalCtx) c.Assert(result.GetUint64(), Equals, uint64(1)) @@ -509,42 +510,42 @@ func (s *testAggFuncSuit) TestMaxMin(c *C) { result = minFunc.GetResult(minEvalCtx) c.Assert(result.IsNull(), IsTrue) - row := types.MakeDatums(2) - err := maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row := chunk.MutRowFromDatums(types.MakeDatums(2)) + 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)) - err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = minFunc.GetResult(minEvalCtx) c.Assert(result.GetInt64(), Equals, int64(2)) - row[0].SetInt64(3) - err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row.SetDatum(0, types.NewIntDatum(3)) + err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = maxFunc.GetResult(maxEvalCtx) c.Assert(result.GetInt64(), Equals, int64(3)) - err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = minFunc.GetResult(minEvalCtx) c.Assert(result.GetInt64(), Equals, int64(2)) - row[0].SetInt64(1) - err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row.SetDatum(0, types.NewIntDatum(1)) + err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = maxFunc.GetResult(maxEvalCtx) c.Assert(result.GetInt64(), Equals, int64(3)) - err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = minFunc.GetResult(minEvalCtx) c.Assert(result.GetInt64(), Equals, int64(1)) - row[0].SetNull() - err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + row.SetDatum(0, types.NewDatum(nil)) + err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = maxFunc.GetResult(maxEvalCtx) c.Assert(result.GetInt64(), Equals, int64(3)) - err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, types.DatumRow(row)) + err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow()) c.Assert(err, IsNil) result = minFunc.GetResult(minEvalCtx) c.Assert(result.GetInt64(), Equals, int64(1)) diff --git a/expression/builtin_cast_test.go b/expression/builtin_cast_test.go index 7d8c930d31329..fc6c00721923b 100644 --- a/expression/builtin_cast_test.go +++ b/expression/builtin_cast_test.go @@ -25,6 +25,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/charset" + "github.com/pingcap/tidb/util/chunk" ) func (s *testEvaluatorSuite) TestCast(c *C) { @@ -234,41 +235,43 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { }() var sig builtinFunc + durationColumn := &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0} + durationColumn.RetType.Decimal = types.DefaultFsp // Test cast as Decimal. castToDecCases := []struct { before *Column after *types.MyDecimal - row types.DatumRow + row chunk.MutRow }{ // cast int as decimal. { &Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0}, types.NewDecFromInt(1), - []types.Datum{types.NewIntDatum(1)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(1)}), }, // cast string as decimal. { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, types.NewDecFromInt(1), - []types.Datum{types.NewStringDatum("1")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("1")}), }, // cast real as decimal. { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, types.NewDecFromInt(1), - []types.Datum{types.NewFloat64Datum(1)}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(1)}), }, // cast Time as decimal. { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, types.NewDecFromInt(curTimeInt), - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), }, // cast Duration as decimal. { - &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, + durationColumn, types.NewDecFromInt(125959), - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), }, } for i, t := range castToDecCases { @@ -289,18 +292,19 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 5: sig = &builtinCastDecimalAsDecimalSig{decFunc} } - res, isNull, err := sig.evalDecimal(t.row) + res, isNull, err := sig.evalDecimal(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) c.Assert(res.Compare(t.after), Equals, 0) } + durationColumn.RetType.Decimal = 1 castToDecCases2 := []struct { before *Column flen int decimal int after *types.MyDecimal - row types.DatumRow + row chunk.MutRow }{ // cast int as decimal. { @@ -308,7 +312,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { 7, 3, types.NewDecFromStringForTest("1234.000"), - []types.Datum{types.NewIntDatum(1234)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(1234)}), }, // cast string as decimal. { @@ -316,7 +320,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { 7, 3, types.NewDecFromStringForTest("1234.000"), - []types.Datum{types.NewStringDatum("1234")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("1234")}), }, // cast real as decimal. { @@ -324,7 +328,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { 8, 4, types.NewDecFromStringForTest("1234.1230"), - []types.Datum{types.NewFloat64Datum(1234.123)}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(1234.123)}), }, // cast Time as decimal. { @@ -332,15 +336,15 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { 15, 1, types.NewDecFromStringForTest(strconv.FormatInt(curTimeInt, 10) + ".0"), - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), }, // cast Duration as decimal. { - &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, + durationColumn, 7, 1, types.NewDecFromStringForTest("125959.0"), - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), }, // cast decimal as decimal. { @@ -348,7 +352,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { 7, 3, types.NewDecFromStringForTest("1234.000"), - []types.Datum{types.NewDecimalDatum(types.NewDecFromStringForTest("1234"))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromStringForTest("1234"))}), }, } @@ -372,53 +376,54 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 5: sig = &builtinCastDecimalAsDecimalSig{decFunc} } - res, isNull, err := sig.evalDecimal(t.row) + res, isNull, err := sig.evalDecimal(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) c.Assert(res.ToString(), DeepEquals, t.after.ToString()) } + durationColumn.RetType.Decimal = 0 // Test cast as int. castToIntCases := []struct { before *Column after int64 - row types.DatumRow + row chunk.MutRow }{ // cast string as int. { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, 1, - []types.Datum{types.NewStringDatum("1")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("1")}), }, // cast decimal as int. { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, 1, - []types.Datum{types.NewDecimalDatum(types.NewDecFromInt(1))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromInt(1))}), }, // cast real as int. { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, 1, - []types.Datum{types.NewFloat64Datum(1)}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(1)}), }, // cast Time as int. { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, curTimeInt, - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), }, // cast Duration as int. { &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, 125959, - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), }, // cast JSON as int. { &Column{RetType: types.NewFieldType(mysql.TypeJSON), Index: 0}, 3, - []types.Datum{jsonInt}, + chunk.MutRowFromDatums([]types.Datum{jsonInt}), }, } for i, t := range castToIntCases { @@ -438,7 +443,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 5: sig = &builtinCastJSONAsIntSig{intFunc} } - res, isNull, err := sig.evalInt(t.row) + res, isNull, err := sig.evalInt(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) c.Assert(res, Equals, t.after) @@ -448,43 +453,43 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { castToRealCases := []struct { before *Column after float64 - row types.DatumRow + row chunk.MutRow }{ // cast string as real. { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, 1.1, - []types.Datum{types.NewStringDatum("1.1")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("1.1")}), }, // cast decimal as real. { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, 1.1, - []types.Datum{types.NewDecimalDatum(types.NewDecFromFloatForTest(1.1))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromFloatForTest(1.1))}), }, // cast int as real. { &Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0}, 1, - []types.Datum{types.NewIntDatum(1)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(1)}), }, // cast Time as real. { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, float64(curTimeInt), - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), }, // cast Duration as real. { - &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, + durationColumn, 125959, - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), }, // cast JSON as real. { &Column{RetType: types.NewFieldType(mysql.TypeJSON), Index: 0}, 3.0, - []types.Datum{jsonInt}, + chunk.MutRowFromDatums([]types.Datum{jsonInt}), }, } for i, t := range castToRealCases { @@ -504,7 +509,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 5: sig = &builtinCastJSONAsRealSig{realFunc} } - res, isNull, err := sig.evalReal(t.row) + res, isNull, err := sig.evalReal(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) c.Assert(res, Equals, t.after) @@ -514,49 +519,49 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { castToStringCases := []struct { before *Column after string - row types.DatumRow + row chunk.MutRow }{ // cast real as string. { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, "1", - []types.Datum{types.NewFloat64Datum(1)}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(1)}), }, // cast decimal as string. { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, "1", - []types.Datum{types.NewDecimalDatum(types.NewDecFromInt(1))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromInt(1))}), }, // cast int as string. { &Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0}, "1", - []types.Datum{types.NewIntDatum(1)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(1)}), }, // cast time as string. { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, curTimeString, - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), }, // cast duration as string. { &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, "12:59:59", - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), }, // cast JSON as string. { &Column{RetType: types.NewFieldType(mysql.TypeJSON), Index: 0}, "3", - []types.Datum{jsonInt}, + chunk.MutRowFromDatums([]types.Datum{jsonInt}), }, // cast string as string. { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, "1234", - []types.Datum{types.NewStringDatum("1234")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("1234")}), }, } for i, t := range castToStringCases { @@ -581,7 +586,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 6: sig = &builtinCastStringAsStringSig{stringFunc} } - res, isNull, err := sig.evalString(t.row) + res, isNull, err := sig.evalString(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) c.Assert(res, Equals, t.after) @@ -592,49 +597,49 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { before *Column after string flen int - row types.DatumRow + row chunk.MutRow }{ // cast real as string. { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, "123", 3, - []types.Datum{types.NewFloat64Datum(1234.123)}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(1234.123)}), }, // cast decimal as string. { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, "123", 3, - []types.Datum{types.NewDecimalDatum(types.NewDecFromStringForTest("1234.123"))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromStringForTest("1234.123"))}), }, // cast int as string. { &Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0}, "123", 3, - []types.Datum{types.NewIntDatum(1234)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(1234)}), }, // cast time as string. { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, curTimeString[:3], 3, - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), }, // cast duration as string. { &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, "12:", 3, - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), }, // cast string as string. { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, "你好w", 3, - []types.Datum{types.NewStringDatum("你好world")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("你好world")}), }, } for i, t := range castToStringCases2 { @@ -658,7 +663,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { stringFunc.tp.Charset = charset.CharsetUTF8 sig = &builtinCastStringAsStringSig{stringFunc} } - res, isNull, err := sig.evalString(t.row) + res, isNull, err := sig.evalString(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) c.Assert(res, Equals, t.after) @@ -667,49 +672,49 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { castToTimeCases := []struct { before *Column after types.Time - row types.DatumRow + row chunk.MutRow }{ // cast real as Time. { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, tm, - []types.Datum{types.NewFloat64Datum(float64(curTimeInt))}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(float64(curTimeInt))}), }, // cast decimal as Time. { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, tm, - []types.Datum{types.NewDecimalDatum(types.NewDecFromInt(curTimeInt))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromInt(curTimeInt))}), }, // cast int as Time. { &Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0}, tm, - []types.Datum{types.NewIntDatum(curTimeInt)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(curTimeInt)}), }, // cast string as Time. { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, tm, - []types.Datum{types.NewStringDatum(curTimeString)}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum(curTimeString)}), }, // cast Duration as Time. { &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, tm, - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), }, // cast JSON as Time. { &Column{RetType: types.NewFieldType(mysql.TypeJSON), Index: 0}, tm, - []types.Datum{jsonTime}, + chunk.MutRowFromDatums([]types.Datum{jsonTime}), }, // cast Time as Time. { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, tm, - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), }, } for i, t := range castToTimeCases { @@ -734,7 +739,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 6: sig = &builtinCastTimeAsTimeSig{timeFunc} } - res, isNull, err := sig.evalTime(t.row) + res, isNull, err := sig.evalTime(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) c.Assert(res.String(), Equals, t.after.String()) @@ -743,7 +748,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { castToTimeCases2 := []struct { before *Column after types.Time - row types.DatumRow + row chunk.MutRow fsp int tp byte }{ @@ -751,7 +756,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, dt, - []types.Datum{types.NewFloat64Datum(float64(curTimeInt))}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(float64(curTimeInt))}), types.DefaultFsp, mysql.TypeDate, }, @@ -759,7 +764,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, dt, - []types.Datum{types.NewDecimalDatum(types.NewDecFromInt(curTimeInt))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromInt(curTimeInt))}), types.DefaultFsp, mysql.TypeDate, }, @@ -767,7 +772,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { { &Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0}, tm, - []types.Datum{types.NewIntDatum(curTimeInt)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(curTimeInt)}), types.MaxFsp, mysql.TypeDatetime, }, @@ -775,7 +780,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, tm, - []types.Datum{types.NewStringDatum(curTimeString)}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum(curTimeString)}), types.MaxFsp, mysql.TypeDatetime, }, @@ -783,7 +788,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { { &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, dt, - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), types.DefaultFsp, mysql.TypeDate, }, @@ -791,7 +796,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, dt, - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), types.DefaultFsp, mysql.TypeDate, }, @@ -816,7 +821,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 5: sig = &builtinCastTimeAsTimeSig{timeFunc} } - res, isNull, err := sig.evalTime(t.row) + res, isNull, err := sig.evalTime(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) resAfter := t.after.String() @@ -832,49 +837,49 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { castToDurationCases := []struct { before *Column after types.Duration - row types.DatumRow + row chunk.MutRow }{ // cast real as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, duration, - []types.Datum{types.NewFloat64Datum(125959)}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(125959)}), }, // cast decimal as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, duration, - []types.Datum{types.NewDecimalDatum(types.NewDecFromInt(125959))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromInt(125959))}), }, // cast int as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0}, duration, - []types.Datum{types.NewIntDatum(125959)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(125959)}), }, // cast string as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, duration, - []types.Datum{types.NewStringDatum("12:59:59")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("12:59:59")}), }, // cast Time as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, duration, - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), }, // cast JSON as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeJSON), Index: 0}, duration, - []types.Datum{jsonDuration}, + chunk.MutRowFromDatums([]types.Datum{jsonDuration}), }, // cast Duration as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, duration, - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), }, } for i, t := range castToDurationCases { @@ -899,7 +904,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 6: sig = &builtinCastDurationAsDurationSig{durationFunc} } - res, isNull, err := sig.evalDuration(t.row) + res, isNull, err := sig.evalDuration(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) c.Assert(res.String(), Equals, t.after.String()) @@ -908,49 +913,49 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { castToDurationCases2 := []struct { before *Column after types.Duration - row types.DatumRow + row chunk.MutRow fsp int }{ // cast real as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, duration, - []types.Datum{types.NewFloat64Datum(125959)}, + chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(125959)}), 1, }, // cast decimal as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, duration, - []types.Datum{types.NewDecimalDatum(types.NewDecFromInt(125959))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromInt(125959))}), 2, }, // cast int as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0}, duration, - []types.Datum{types.NewIntDatum(125959)}, + chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(125959)}), 3, }, // cast string as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0}, duration, - []types.Datum{types.NewStringDatum("12:59:59")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("12:59:59")}), 4, }, // cast Time as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, duration, - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), 5, }, // cast Duration as Duration. { &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, duration, - []types.Datum{durationDatum}, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), 6, }, } @@ -974,7 +979,7 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { case 5: sig = &builtinCastDurationAsDurationSig{durationFunc} } - res, isNull, err := sig.evalDuration(t.row) + res, isNull, err := sig.evalDuration(t.row.ToRow()) c.Assert(isNull, Equals, false) c.Assert(err, IsNil) resAfter := t.after.String() @@ -989,11 +994,11 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { // null case args := []Expression{&Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}} - row := types.DatumRow{types.NewDatum(nil)} + row := chunk.MutRowFromDatums([]types.Datum{types.NewDatum(nil)}) bf := newBaseBuiltinFunc(ctx, args) bf.tp = types.NewFieldType(mysql.TypeVarString) sig = &builtinCastRealAsStringSig{bf} - sRes, isNull, err := sig.evalString(row) + sRes, isNull, err := sig.evalString(row.ToRow()) c.Assert(sRes, Equals, "") c.Assert(isNull, Equals, true) c.Assert(err, IsNil) @@ -1011,9 +1016,13 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) { func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { ctx := s.ctx + durationColumn0 := &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0} + durationColumn0.RetType.Decimal = types.DefaultFsp + durationColumn3 := &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0} + durationColumn3.RetType.Decimal = 3 cases := []struct { expr Expression - row types.DatumRow + row chunk.MutRow intRes int64 realRes float64 decRes *types.MyDecimal @@ -1021,62 +1030,62 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { }{ { &Column{RetType: types.NewFieldType(mysql.TypeLong), Index: 0}, - []types.Datum{types.NewDatum(123)}, + chunk.MutRowFromDatums([]types.Datum{types.NewDatum(123)}), 123, 123, types.NewDecFromInt(123), "123", }, { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, - []types.Datum{types.NewDatum(123.555)}, + chunk.MutRowFromDatums([]types.Datum{types.NewDatum(123.555)}), 124, 123.555, types.NewDecFromFloatForTest(123.555), "123.555", }, { &Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0}, - []types.Datum{types.NewDatum(123.123)}, + chunk.MutRowFromDatums([]types.Datum{types.NewDatum(123.123)}), 123, 123.123, types.NewDecFromFloatForTest(123.123), "123.123", }, { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, - []types.Datum{types.NewDecimalDatum(types.NewDecFromStringForTest("123.123"))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromStringForTest("123.123"))}), 123, 123.123, types.NewDecFromFloatForTest(123.123), "123.123", }, { &Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0}, - []types.Datum{types.NewDecimalDatum(types.NewDecFromStringForTest("123.555"))}, + chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromStringForTest("123.555"))}), 124, 123.555, types.NewDecFromFloatForTest(123.555), "123.555", }, { &Column{RetType: types.NewFieldType(mysql.TypeVarString), Index: 0}, - []types.Datum{types.NewStringDatum("123.123")}, + chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("123.123")}), 123, 123.123, types.NewDecFromStringForTest("123.123"), "123.123", }, { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, - []types.Datum{timeDatum}, + chunk.MutRowFromDatums([]types.Datum{timeDatum}), curTimeInt, float64(curTimeInt), types.NewDecFromInt(curTimeInt), curTimeString, }, { &Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0}, - []types.Datum{timeWithFspDatum}, + chunk.MutRowFromDatums([]types.Datum{timeWithFspDatum}), int64(curDateInt*1000000 + 130000), curTimeWithFspReal, types.NewDecFromFloatForTest(curTimeWithFspReal), curTimeWithFspString, }, { - &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, - []types.Datum{durationDatum}, + durationColumn0, + chunk.MutRowFromDatums([]types.Datum{durationDatum}), 125959, 125959, types.NewDecFromFloatForTest(125959), "12:59:59", }, { - &Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0}, - []types.Datum{durationWithFspDatum}, + durationColumn3, + chunk.MutRowFromDatums([]types.Datum{durationWithFspDatum}), 130000, 125959.555, types.NewDecFromFloatForTest(125959.555), "12:59:59.555", }, { &Column{RetType: types.NewFieldType(mysql.TypeEnum), Index: 0}, - []types.Datum{types.NewDatum(types.Enum{Name: "a", Value: 123})}, + chunk.MutRowFromDatums([]types.Datum{types.NewDatum(types.Enum{Name: "a", Value: 123})}), 123, 123, types.NewDecFromStringForTest("123"), "a", }, { &Constant{RetType: types.NewFieldType(mysql.TypeVarString), Value: types.NewBinaryLiteralDatum(types.NewBinaryLiteralFromUint(0x61, -1))}, - nil, + chunk.MutRowFromDatums([]types.Datum{types.NewDatum(nil)}), 97, 97, types.NewDecFromInt(0x61), "a", }, } @@ -1084,7 +1093,7 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { // Test wrapping with CastAsInt. intExpr := WrapWithCastAsInt(ctx, t.expr) c.Assert(intExpr.GetType().EvalType(), Equals, types.ETInt) - intRes, isNull, err := intExpr.EvalInt(ctx, t.row) + intRes, isNull, err := intExpr.EvalInt(ctx, t.row.ToRow()) c.Assert(err, IsNil, Commentf("cast[%v]: %#v", i, t)) c.Assert(isNull, Equals, false) c.Assert(intRes, Equals, t.intRes) @@ -1092,7 +1101,7 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { // Test wrapping with CastAsReal. realExpr := WrapWithCastAsReal(ctx, t.expr) c.Assert(realExpr.GetType().EvalType(), Equals, types.ETReal) - realRes, isNull, err := realExpr.EvalReal(ctx, t.row) + realRes, isNull, err := realExpr.EvalReal(ctx, t.row.ToRow()) c.Assert(err, IsNil) c.Assert(isNull, Equals, false) c.Assert(realRes, Equals, t.realRes, Commentf("cast[%v]: %#v", i, t)) @@ -1100,7 +1109,7 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { // Test wrapping with CastAsDecimal. decExpr := WrapWithCastAsDecimal(ctx, t.expr) c.Assert(decExpr.GetType().EvalType(), Equals, types.ETDecimal) - decRes, isNull, err := decExpr.EvalDecimal(ctx, t.row) + decRes, isNull, err := decExpr.EvalDecimal(ctx, t.row.ToRow()) c.Assert(err, IsNil, Commentf("case[%v]: %#v\n", i, t)) c.Assert(isNull, Equals, false) c.Assert(decRes.Compare(t.decRes), Equals, 0, Commentf("case[%v]: %#v\n", i, t)) @@ -1108,7 +1117,7 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { // Test wrapping with CastAsString. strExpr := WrapWithCastAsString(ctx, t.expr) c.Assert(strExpr.GetType().EvalType().IsStringKind(), IsTrue) - strRes, isNull, err := strExpr.EvalString(ctx, t.row) + strRes, isNull, err := strExpr.EvalString(ctx, t.row.ToRow()) c.Assert(err, IsNil) c.Assert(isNull, Equals, false) c.Assert(strRes, Equals, t.stringRes) @@ -1119,12 +1128,12 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { // test cast unsigned int as string. strExpr := WrapWithCastAsString(ctx, unsignedIntExpr) c.Assert(strExpr.GetType().EvalType().IsStringKind(), IsTrue) - strRes, isNull, err := strExpr.EvalString(ctx, types.DatumRow{types.NewUintDatum(math.MaxUint64)}) + strRes, isNull, err := strExpr.EvalString(ctx, chunk.MutRowFromDatums([]types.Datum{types.NewUintDatum(math.MaxUint64)}).ToRow()) c.Assert(err, IsNil) c.Assert(strRes, Equals, strconv.FormatUint(math.MaxUint64, 10)) c.Assert(isNull, Equals, false) - strRes, isNull, err = strExpr.EvalString(ctx, types.DatumRow{types.NewUintDatum(1234)}) + strRes, isNull, err = strExpr.EvalString(ctx, chunk.MutRowFromDatums([]types.Datum{types.NewUintDatum(1234)}).ToRow()) c.Assert(err, IsNil) c.Assert(isNull, Equals, false) c.Assert(strRes, Equals, strconv.FormatUint(uint64(1234), 10)) @@ -1132,7 +1141,7 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { // test cast unsigned int as decimal. decExpr := WrapWithCastAsDecimal(ctx, unsignedIntExpr) c.Assert(decExpr.GetType().EvalType(), Equals, types.ETDecimal) - decRes, isNull, err := decExpr.EvalDecimal(ctx, types.DatumRow{types.NewUintDatum(uint64(1234))}) + decRes, isNull, err := decExpr.EvalDecimal(ctx, chunk.MutRowFromDatums([]types.Datum{types.NewUintDatum(uint64(1234))}).ToRow()) c.Assert(err, IsNil) c.Assert(isNull, Equals, false) c.Assert(decRes.Compare(types.NewDecFromUint(uint64(1234))), Equals, 0) @@ -1140,7 +1149,7 @@ func (s *testEvaluatorSuite) TestWrapWithCastAsTypesClasses(c *C) { // test cast unsigned int as Time. timeExpr := WrapWithCastAsTime(ctx, unsignedIntExpr, types.NewFieldType(mysql.TypeDatetime)) c.Assert(timeExpr.GetType().Tp, Equals, mysql.TypeDatetime) - timeRes, isNull, err := timeExpr.EvalTime(ctx, types.DatumRow{types.NewUintDatum(uint64(curTimeInt))}) + timeRes, isNull, err := timeExpr.EvalTime(ctx, chunk.MutRowFromDatums([]types.Datum{types.NewUintDatum(uint64(curTimeInt))}).ToRow()) c.Assert(err, IsNil) c.Assert(isNull, Equals, false) c.Assert(timeRes.Compare(tm), Equals, 0) diff --git a/expression/builtin_info_test.go b/expression/builtin_info_test.go index bfdd6327a926f..670d2a9b36765 100644 --- a/expression/builtin_info_test.go +++ b/expression/builtin_info_test.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/auth" "github.com/pingcap/tidb/util/charset" + "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/printer" "github.com/pingcap/tidb/util/testleak" @@ -46,7 +47,7 @@ func (s *testEvaluatorSuite) TestDatabase(c *C) { c.Assert(fc, NotNil) f, err = fc.getFunction(ctx, nil) c.Assert(err, IsNil) - d, err = evalBuiltinFunc(f, types.DatumRow(types.MakeDatums())) + d, err = evalBuiltinFunc(f, chunk.MutRowFromDatums(types.MakeDatums()).ToRow()) c.Assert(err, IsNil) c.Assert(d.GetString(), Equals, "test") } diff --git a/expression/builtin_other_test.go b/expression/builtin_other_test.go index 8bb26c89cbbd6..c92136203ce48 100644 --- a/expression/builtin_other_test.go +++ b/expression/builtin_other_test.go @@ -24,6 +24,7 @@ import ( "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" + "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/hack" "github.com/pingcap/tidb/util/testleak" ) @@ -123,7 +124,7 @@ func (s *testEvaluatorSuite) TestInFunc(c *C) { for _, tc := range testCases { fn, err := fc.getFunction(s.ctx, s.datumsToConstants(types.MakeDatums(tc.args...))) c.Assert(err, IsNil) - d, err := evalBuiltinFunc(fn, types.DatumRow(types.MakeDatums(tc.args...))) + d, err := evalBuiltinFunc(fn, chunk.MutRowFromDatums(types.MakeDatums(tc.args...)).ToRow()) c.Assert(err, IsNil) c.Assert(d.GetValue(), Equals, tc.res, Commentf("%v", types.MakeDatums(tc.args))) } @@ -152,7 +153,7 @@ func (s *testEvaluatorSuite) TestSetVar(c *C) { for _, tc := range testCases { fn, err := fc.getFunction(s.ctx, s.datumsToConstants(types.MakeDatums(tc.args...))) c.Assert(err, IsNil) - d, err := evalBuiltinFunc(fn, types.DatumRow(types.MakeDatums(tc.args...))) + d, err := evalBuiltinFunc(fn, chunk.MutRowFromDatums(types.MakeDatums(tc.args...)).ToRow()) c.Assert(err, IsNil) c.Assert(d.GetString(), Equals, tc.res) if tc.args[1] != nil { @@ -193,7 +194,7 @@ func (s *testEvaluatorSuite) TestGetVar(c *C) { for _, tc := range testCases { fn, err := fc.getFunction(s.ctx, s.datumsToConstants(types.MakeDatums(tc.args...))) c.Assert(err, IsNil) - d, err := evalBuiltinFunc(fn, types.DatumRow(types.MakeDatums(tc.args...))) + d, err := evalBuiltinFunc(fn, chunk.MutRowFromDatums(types.MakeDatums(tc.args...)).ToRow()) c.Assert(err, IsNil) c.Assert(d.GetString(), Equals, tc.res) } @@ -208,11 +209,11 @@ func (s *testEvaluatorSuite) TestValues(c *C) { c.Assert(err, IsNil) _, err = evalBuiltinFunc(sig, nil) c.Assert(err.Error(), Equals, "Session current insert values is nil") - s.ctx.GetSessionVars().CurrInsertValues = types.DatumRow(types.MakeDatums("1")) + s.ctx.GetSessionVars().CurrInsertValues = chunk.MutRowFromDatums(types.MakeDatums("1")).ToRow() _, err = evalBuiltinFunc(sig, nil) c.Assert(err.Error(), Equals, fmt.Sprintf("Session current insert values len %d and column's offset %v don't match", 1, 1)) currInsertValues := types.MakeDatums("1", "2") - s.ctx.GetSessionVars().CurrInsertValues = types.DatumRow(currInsertValues) + s.ctx.GetSessionVars().CurrInsertValues = chunk.MutRowFromDatums(currInsertValues).ToRow() ret, err := evalBuiltinFunc(sig, nil) c.Assert(err, IsNil) cmp, err := ret.CompareDatum(nil, &currInsertValues[1]) diff --git a/expression/distsql_builtin_test.go b/expression/distsql_builtin_test.go index c917a477a6975..ee0a65001a1d5 100644 --- a/expression/distsql_builtin_test.go +++ b/expression/distsql_builtin_test.go @@ -20,6 +20,7 @@ import ( "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" + "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tipb/go-tipb" log "github.com/sirupsen/logrus" @@ -32,9 +33,9 @@ type testEvalSuite struct{} // TestEval test expr.Eval(). // TODO: add more tests. func (s *testEvalSuite) TestEval(c *C) { - row := types.DatumRow{types.NewDatum(100)} + row := chunk.MutRowFromDatums([]types.Datum{types.NewDatum(100)}).ToRow() fieldTps := make([]*types.FieldType, 1) - fieldTps[0] = types.NewFieldType(mysql.TypeDouble) + fieldTps[0] = types.NewFieldType(mysql.TypeLonglong) tests := []struct { expr *tipb.Expr result types.Datum diff --git a/server/util_test.go b/server/util_test.go index dd3d18399589d..655b13837ead6 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/types" + "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/testleak" ) @@ -86,45 +87,45 @@ func (s *testUtilSuite) TestDumpTextValue(c *C) { Type: mysql.TypeLonglong, Decimal: mysql.NotFixedDec, }} - bs, err := dumpTextRow(nil, columns, types.DatumRow{types.NewIntDatum(10)}) + bs, err := dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(10)}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "10") - bs, err = dumpTextRow(nil, columns, types.DatumRow{types.NewUintDatum(11)}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{types.NewUintDatum(11)}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "11") columns[0].Type = mysql.TypeFloat columns[0].Decimal = 1 f32 := types.NewFloat32Datum(1.2) - bs, err = dumpTextRow(nil, columns, types.DatumRow{f32}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{f32}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "1.2") columns[0].Decimal = 2 - bs, err = dumpTextRow(nil, columns, types.DatumRow{f32}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{f32}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "1.20") f64 := types.NewFloat64Datum(2.2) columns[0].Type = mysql.TypeDouble columns[0].Decimal = 1 - bs, err = dumpTextRow(nil, columns, types.DatumRow{f64}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{f64}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "2.2") columns[0].Decimal = 2 - bs, err = dumpTextRow(nil, columns, types.DatumRow{f64}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{f64}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "2.20") columns[0].Type = mysql.TypeBlob - bs, err = dumpTextRow(nil, columns, types.DatumRow{types.NewBytesDatum([]byte("foo"))}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{types.NewBytesDatum([]byte("foo"))}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "foo") columns[0].Type = mysql.TypeVarchar - bs, err = dumpTextRow(nil, columns, types.DatumRow{types.NewStringDatum("bar")}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum("bar")}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "bar") @@ -134,7 +135,7 @@ func (s *testUtilSuite) TestDumpTextValue(c *C) { c.Assert(err, IsNil) d.SetMysqlTime(time) columns[0].Type = mysql.TypeDatetime - bs, err = dumpTextRow(nil, columns, types.DatumRow{d}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{d}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "2017-01-06 00:00:00") @@ -142,13 +143,14 @@ func (s *testUtilSuite) TestDumpTextValue(c *C) { c.Assert(err, IsNil) d.SetMysqlDuration(duration) columns[0].Type = mysql.TypeDuration - bs, err = dumpTextRow(nil, columns, types.DatumRow{d}) + columns[0].Decimal = 0 + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{d}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "11:30:45") d.SetMysqlDecimal(types.NewDecFromStringForTest("1.23")) columns[0].Type = mysql.TypeNewDecimal - bs, err = dumpTextRow(nil, columns, types.DatumRow{d}) + bs, err = dumpTextRow(nil, columns, chunk.MutRowFromDatums([]types.Datum{d}).ToRow()) c.Assert(err, IsNil) c.Assert(mustDecodeStr(c, bs), Equals, "1.23") }