Skip to content

Commit

Permalink
expression: remove mockKVClient (pingcap#6299)
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored and XuHuaiyu committed Apr 17, 2018
1 parent c6258e3 commit 860e808
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 190 deletions.
68 changes: 7 additions & 61 deletions expression/aggregation/agg_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/mock"
tipb "github.com/pingcap/tipb/go-tipb"
"golang.org/x/net/context"
)

var _ = Suite(&testEvaluatorSuite{})
Expand All @@ -38,57 +35,6 @@ func TestT(t *testing.T) {
TestingT(t)
}

// mockKvClient is mocked from tikv.CopClient to avoid circular dependency.
type mockKvClient struct {
}

// IsRequestTypeSupported implements the kv.Client interface..
func (c *mockKvClient) IsRequestTypeSupported(reqType, subType int64) bool {
switch reqType {
case kv.ReqTypeSelect, kv.ReqTypeIndex:
switch subType {
case kv.ReqSubTypeGroupBy, kv.ReqSubTypeBasic, kv.ReqSubTypeTopN:
return true
default:
return c.supportExpr(tipb.ExprType(subType))
}
}
return false
}

// Send implements the kv.Client interface..
func (c *mockKvClient) Send(ctx context.Context, req *kv.Request) kv.Response {
return nil
}

func (c *mockKvClient) supportExpr(exprType tipb.ExprType) bool {
switch exprType {
case tipb.ExprType_Null, tipb.ExprType_Int64, tipb.ExprType_Uint64, tipb.ExprType_String, tipb.ExprType_Bytes,
tipb.ExprType_MysqlDuration, tipb.ExprType_MysqlTime, tipb.ExprType_MysqlDecimal,
tipb.ExprType_ColumnRef,
tipb.ExprType_And, tipb.ExprType_Or,
tipb.ExprType_LT, tipb.ExprType_LE, tipb.ExprType_EQ, tipb.ExprType_NE,
tipb.ExprType_GE, tipb.ExprType_GT, tipb.ExprType_NullEQ,
tipb.ExprType_In, tipb.ExprType_ValueList,
tipb.ExprType_Like, tipb.ExprType_Not:
return true
case tipb.ExprType_Plus, tipb.ExprType_Div:
return true
case tipb.ExprType_Case, tipb.ExprType_If:
return true
case tipb.ExprType_Count, tipb.ExprType_First, tipb.ExprType_Max, tipb.ExprType_Min, tipb.ExprType_Sum, tipb.ExprType_Avg:
return true
case tipb.ExprType_JsonType, tipb.ExprType_JsonExtract, tipb.ExprType_JsonUnquote, tipb.ExprType_JsonValid,
tipb.ExprType_JsonObject, tipb.ExprType_JsonArray, tipb.ExprType_JsonMerge, tipb.ExprType_JsonSet,
tipb.ExprType_JsonInsert, tipb.ExprType_JsonReplace, tipb.ExprType_JsonRemove, tipb.ExprType_JsonContains:
return false
case kv.ReqSubTypeDesc:
return true
default:
return false
}
}

type dataGen4Expr2PbTest struct {
}

Expand All @@ -115,7 +61,7 @@ func (s *testEvaluatorSuite) TearDownSuite(c *C) {

func (s *testEvaluatorSuite) TestAggFunc2Pb(c *C) {
sc := new(stmtctx.StatementContext)
client := new(mockKvClient)
client := new(mock.Client)
dg := new(dataGen4Expr2PbTest)

funcNames := []string{ast.AggFuncSum, ast.AggFuncCount, ast.AggFuncAvg, ast.AggFuncGroupConcat, ast.AggFuncMax, ast.AggFuncMin, ast.AggFuncFirstRow}
Expand All @@ -132,13 +78,13 @@ func (s *testEvaluatorSuite) TestAggFunc2Pb(c *C) {
}

jsons := []string{
"{\"tp\":3002,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0}],\"sig\":0}",
"{\"tp\":3001,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0}],\"sig\":0}",
"{\"tp\":3003,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0}],\"sig\":0}",
"{\"tp\":3002,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":0}",
"{\"tp\":3001,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":0}",
"{\"tp\":3003,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":0}",
"null",
"{\"tp\":3005,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0}],\"sig\":0}",
"{\"tp\":3004,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0}],\"sig\":0}",
"{\"tp\":3006,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0}],\"sig\":0}",
"{\"tp\":3005,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":0}",
"{\"tp\":3004,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":0}",
"{\"tp\":3006,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":5,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":83,\"charset\":\"\"}}],\"sig\":0}",
}
for i, funcName := range funcNames {
aggFunc := &AggFuncDesc{
Expand Down
Loading

0 comments on commit 860e808

Please sign in to comment.