@@ -25,6 +25,7 @@ import (
2525 "github.com/pingcap/parser/mysql"
2626 "github.com/pingcap/tidb/sessionctx/stmtctx"
2727 "github.com/pingcap/tidb/types"
28+ "github.com/pingcap/tidb/util/codec"
2829 "github.com/pingcap/tidb/util/mock"
2930 "github.com/pingcap/tipb/go-tipb"
3031)
@@ -593,3 +594,41 @@ func (s *testEvaluatorSuite) TestSortByItem2Pb(c *C) {
593594 c .Assert (err , IsNil )
594595 c .Assert (string (js ), Equals , "{\" expr\" :{\" tp\" :201,\" val\" :\" gAAAAAAAAAE=\" ,\" sig\" :0,\" field_type\" :{\" tp\" :5,\" flag\" :0,\" flen\" :-1,\" decimal\" :-1,\" collate\" :46,\" charset\" :\" \" }},\" desc\" :true}" )
595596}
597+
598+ func (s * testEvaluatorSuite ) TestImplicitArgs (c * C ) {
599+ sc := new (stmtctx.StatementContext )
600+ client := new (mock.Client )
601+ dg := new (dataGen4Expr2PbTest )
602+
603+ c .Assert (failpoint .Enable ("github.com/pingcap/tidb/expression/PushDownTestSwitcher" , `return("all")` ), IsNil )
604+ defer func () { c .Assert (failpoint .Disable ("github.com/pingcap/tidb/expression/PushDownTestSwitcher" ), IsNil ) }()
605+
606+ pc := PbConverter {client : client , sc : sc }
607+
608+ // InUnion flag is false in `BuildCastFunction` when `ScalarFuncSig_CastStringAsInt`
609+ cast := BuildCastFunction (mock .NewContext (), dg .genColumn (mysql .TypeString , 1 ), types .NewFieldType (mysql .TypeLonglong ))
610+ c .Assert (cast .(* ScalarFunction ).Function .implicitArgs (), DeepEquals , []types.Datum {types .NewIntDatum (0 )})
611+ expr := pc .ExprToPB (cast )
612+ c .Assert (expr .Sig , Equals , tipb .ScalarFuncSig_CastStringAsInt )
613+ c .Assert (len (expr .Val ), Greater , 0 )
614+ datums , err := codec .Decode (expr .Val , 1 )
615+ c .Assert (err , IsNil )
616+ c .Assert (datums , DeepEquals , []types.Datum {types .NewIntDatum (0 )})
617+
618+ // InUnion flag is nil in `BuildCastFunction4Union` when `ScalarFuncSig_CastIntAsString`
619+ castInUnion := BuildCastFunction4Union (mock .NewContext (), dg .genColumn (mysql .TypeLonglong , 1 ), types .NewFieldType (mysql .TypeString ))
620+ c .Assert (castInUnion .(* ScalarFunction ).Function .implicitArgs (), IsNil )
621+ expr = pc .ExprToPB (castInUnion )
622+ c .Assert (expr .Sig , Equals , tipb .ScalarFuncSig_CastIntAsString )
623+ c .Assert (len (expr .Val ), Equals , 0 )
624+
625+ // InUnion flag is true in `BuildCastFunction4Union` when `ScalarFuncSig_CastStringAsInt`
626+ castInUnion = BuildCastFunction4Union (mock .NewContext (), dg .genColumn (mysql .TypeString , 1 ), types .NewFieldType (mysql .TypeLonglong ))
627+ c .Assert (castInUnion .(* ScalarFunction ).Function .implicitArgs (), DeepEquals , []types.Datum {types .NewIntDatum (1 )})
628+ expr = pc .ExprToPB (castInUnion )
629+ c .Assert (expr .Sig , Equals , tipb .ScalarFuncSig_CastStringAsInt )
630+ c .Assert (len (expr .Val ), Greater , 0 )
631+ datums , err = codec .Decode (expr .Val , 1 )
632+ c .Assert (err , IsNil )
633+ c .Assert (datums , DeepEquals , []types.Datum {types .NewIntDatum (1 )})
634+ }
0 commit comments