@@ -270,14 +270,15 @@ func (c *castAsDecimalFunctionClass) getFunction(ctx BuildContext, args []Expres
270
270
type castAsStringFunctionClass struct {
271
271
baseFunctionClass
272
272
273
- tp * types.FieldType
273
+ tp * types.FieldType
274
+ isExplicitCharset bool
274
275
}
275
276
276
277
func (c * castAsStringFunctionClass ) getFunction (ctx BuildContext , args []Expression ) (sig builtinFunc , err error ) {
277
278
if err := c .verifyArgs (args ); err != nil {
278
279
return nil , err
279
280
}
280
- bf , err := newBaseBuiltinFunc (ctx , c .funcName , args , c .tp )
281
+ bf , err := newBaseBuiltinCastFunc4String (ctx , c .funcName , args , c .tp , c . isExplicitCharset )
281
282
if err != nil {
282
283
return nil , err
283
284
}
@@ -2057,7 +2058,9 @@ func BuildCastFunction4Union(ctx BuildContext, expr Expression, tp *types.FieldT
2057
2058
defer func () {
2058
2059
ctx .SetValue (inUnionCastContext , nil )
2059
2060
}()
2060
- return BuildCastFunction (ctx , expr , tp )
2061
+ res , err := BuildCastFunctionWithCheck (ctx , expr , tp , false )
2062
+ terror .Log (err )
2063
+ return
2061
2064
}
2062
2065
2063
2066
// BuildCastCollationFunction builds a ScalarFunction which casts the collation.
@@ -2092,13 +2095,13 @@ func BuildCastCollationFunction(ctx BuildContext, expr Expression, ec *ExprColla
2092
2095
2093
2096
// BuildCastFunction builds a CAST ScalarFunction from the Expression.
2094
2097
func BuildCastFunction (ctx BuildContext , expr Expression , tp * types.FieldType ) (res Expression ) {
2095
- res , err := BuildCastFunctionWithCheck (ctx , expr , tp )
2098
+ res , err := BuildCastFunctionWithCheck (ctx , expr , tp , false )
2096
2099
terror .Log (err )
2097
2100
return
2098
2101
}
2099
2102
2100
2103
// BuildCastFunctionWithCheck builds a CAST ScalarFunction from the Expression and return error if any.
2101
- func BuildCastFunctionWithCheck (ctx BuildContext , expr Expression , tp * types.FieldType ) (res Expression , err error ) {
2104
+ func BuildCastFunctionWithCheck (ctx BuildContext , expr Expression , tp * types.FieldType , isExplicitCharset bool ) (res Expression , err error ) {
2102
2105
argType := expr .GetType ()
2103
2106
// If source argument's nullable, then target type should be nullable
2104
2107
if ! mysql .HasNotNullFlag (argType .GetFlag ()) {
@@ -2124,7 +2127,7 @@ func BuildCastFunctionWithCheck(ctx BuildContext, expr Expression, tp *types.Fie
2124
2127
fc = & castAsJSONFunctionClass {baseFunctionClass {ast .Cast , 1 , 1 }, tp }
2125
2128
}
2126
2129
case types .ETString :
2127
- fc = & castAsStringFunctionClass {baseFunctionClass {ast .Cast , 1 , 1 }, tp }
2130
+ fc = & castAsStringFunctionClass {baseFunctionClass {ast .Cast , 1 , 1 }, tp , isExplicitCharset }
2128
2131
if expr .GetType ().GetType () == mysql .TypeBit {
2129
2132
tp .SetFlen ((expr .GetType ().GetFlen () + 7 ) / 8 )
2130
2133
}
0 commit comments