@@ -605,20 +605,30 @@ func (s *testEvaluatorSuite) TestImplicitParameters(c *C) {
605605
606606 pc := PbConverter {client : client , sc : sc }
607607
608- // None flag
608+ // InUnion flag is false in `BuildCastFunction` when `ScalarFuncSig_CastStringAsInt`
609609 cast := BuildCastFunction (mock .NewContext (), dg .genColumn (mysql .TypeString , 1 ), types .NewFieldType (mysql .TypeLonglong ))
610- c .Assert (cast .(* ScalarFunction ).Function .implicitParameters (), IsNil )
610+ c .Assert (cast .(* ScalarFunction ).Function .implicitParameters (), DeepEquals , []types. Datum { types . NewIntDatum ( 0 )} )
611611 expr := pc .ExprToPB (sc , cast )
612612 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 .implicitParameters (), IsNil )
621+ expr = pc .ExprToPB (sc , castInUnion )
622+ c .Assert (expr .Sig , Equals , tipb .ScalarFuncSig_CastIntAsString )
613623 c .Assert (len (expr .Val ), Equals , 0 )
614624
615- // InUnion flag
616- castInUnion : = BuildCastFunction4Union (mock .NewContext (), dg .genColumn (mysql .TypeString , 1 ), types .NewFieldType (mysql .TypeLonglong ))
625+ // InUnion flag is true in `BuildCastFunction4Union` when `ScalarFuncSig_CastStringAsInt`
626+ castInUnion = BuildCastFunction4Union (mock .NewContext (), dg .genColumn (mysql .TypeString , 1 ), types .NewFieldType (mysql .TypeLonglong ))
617627 c .Assert (castInUnion .(* ScalarFunction ).Function .implicitParameters (), DeepEquals , []types.Datum {types .NewIntDatum (1 )})
618628 expr = pc .ExprToPB (sc , castInUnion )
619629 c .Assert (expr .Sig , Equals , tipb .ScalarFuncSig_CastStringAsInt )
620630 c .Assert (len (expr .Val ), Greater , 0 )
621- datums , err : = codec .Decode (expr .Val , 1 )
631+ datums , err = codec .Decode (expr .Val , 1 )
622632 c .Assert (err , IsNil )
623633 c .Assert (datums , DeepEquals , []types.Datum {types .NewIntDatum (1 )})
624634}
0 commit comments