github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/operator/cast2_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package operator
    16  
    17  import (
    18  	"fmt"
    19  	"github.com/matrixorigin/matrixone/pkg/container/types"
    20  	"github.com/matrixorigin/matrixone/pkg/testutil"
    21  	"github.com/stretchr/testify/require"
    22  	"testing"
    23  	"time"
    24  )
    25  
    26  type tcTemp struct {
    27  	info   string
    28  	inputs []testutil.FunctionTestInput
    29  	expect testutil.FunctionTestResult
    30  }
    31  
    32  func initCastTestCase() []tcTemp {
    33  	var testCases []tcTemp
    34  
    35  	// used on case.
    36  	f1251ToDec128, _ := types.Decimal128FromFloat64(125.1, 64, 10)
    37  	s01date, _ := types.ParseDateCast("2004-04-03")
    38  	s02date, _ := types.ParseDateCast("2021-10-03")
    39  	s01ts, _ := types.ParseTimestamp(time.Local, "2020-08-23 11:52:21", 6)
    40  
    41  	castToSameTypeCases := []tcTemp{
    42  		// cast to same type.
    43  		{
    44  			info: "int8 to int8",
    45  			inputs: []testutil.FunctionTestInput{
    46  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
    47  					[]int8{-23}, []bool{false}),
    48  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
    49  			},
    50  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
    51  				[]int8{-23}, []bool{false}),
    52  		},
    53  		{
    54  			info: "int16 to int16",
    55  			inputs: []testutil.FunctionTestInput{
    56  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
    57  					[]int16{-23}, []bool{false}),
    58  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
    59  			},
    60  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
    61  				[]int16{-23}, []bool{false}),
    62  		},
    63  		{
    64  			info: "int32 to int32",
    65  			inputs: []testutil.FunctionTestInput{
    66  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
    67  					[]int32{-23}, []bool{false}),
    68  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
    69  			},
    70  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
    71  				[]int32{-23}, []bool{false}),
    72  		},
    73  		{
    74  			info: "int64 to int64",
    75  			inputs: []testutil.FunctionTestInput{
    76  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
    77  					[]int64{-23}, []bool{false}),
    78  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
    79  			},
    80  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
    81  				[]int64{-23}, []bool{false}),
    82  		},
    83  		{
    84  			info: "uint8 to uint8",
    85  			inputs: []testutil.FunctionTestInput{
    86  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
    87  					[]uint8{23}, []bool{false}),
    88  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
    89  			},
    90  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
    91  				[]uint8{23}, []bool{false}),
    92  		},
    93  		{
    94  			info: "uint16 to uint16",
    95  			inputs: []testutil.FunctionTestInput{
    96  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
    97  					[]uint16{23}, []bool{false}),
    98  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
    99  			},
   100  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
   101  				[]uint16{23}, []bool{false}),
   102  		},
   103  		{
   104  			info: "uint32 to uint32",
   105  			inputs: []testutil.FunctionTestInput{
   106  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   107  					[]uint32{23}, []bool{false}),
   108  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
   109  			},
   110  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
   111  				[]uint32{23}, []bool{false}),
   112  		},
   113  		{
   114  			info: "uint64 to uint64",
   115  			inputs: []testutil.FunctionTestInput{
   116  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   117  					[]uint64{23}, []bool{false}),
   118  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
   119  			},
   120  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
   121  				[]uint64{23}, []bool{false}),
   122  		},
   123  		{
   124  			info: "float32 to float32",
   125  			inputs: []testutil.FunctionTestInput{
   126  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
   127  					[]float32{23.5}, []bool{false}),
   128  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   129  			},
   130  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   131  				[]float32{23.5}, []bool{false}),
   132  		},
   133  		{
   134  			info: "float64 to float64",
   135  			inputs: []testutil.FunctionTestInput{
   136  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
   137  					[]float64{23.5}, []bool{false}),
   138  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
   139  			},
   140  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
   141  				[]float64{23.5}, []bool{false}),
   142  		},
   143  		{
   144  			info: "date to date",
   145  			inputs: []testutil.FunctionTestInput{
   146  				testutil.NewFunctionTestInput(types.T_date.ToType(),
   147  					[]types.Date{729848}, []bool{false}),
   148  				testutil.NewFunctionTestInput(types.T_date.ToType(), []types.Date{}, []bool{}),
   149  			},
   150  			expect: testutil.NewFunctionTestResult(types.T_date.ToType(), false,
   151  				[]types.Date{729848}, []bool{false}),
   152  		},
   153  		{
   154  			info: "datetime to datetime",
   155  			inputs: []testutil.FunctionTestInput{
   156  				testutil.NewFunctionTestInput(types.T_datetime.ToType(),
   157  					[]types.Datetime{66122056321728512}, []bool{false}),
   158  				testutil.NewFunctionTestInput(types.T_datetime.ToType(), []types.Datetime{}, []bool{}),
   159  			},
   160  			expect: testutil.NewFunctionTestResult(types.T_datetime.ToType(), false,
   161  				[]types.Datetime{66122056321728512}, []bool{false}),
   162  		},
   163  		{
   164  			info: "timestamp to timestamp",
   165  			inputs: []testutil.FunctionTestInput{
   166  				testutil.NewFunctionTestInput(types.T_timestamp.ToType(),
   167  					[]types.Timestamp{66122026122739712}, []bool{false}),
   168  				testutil.NewFunctionTestInput(types.T_timestamp.ToType(), []types.Timestamp{}, []bool{}),
   169  			},
   170  			expect: testutil.NewFunctionTestResult(types.T_timestamp.ToType(), false,
   171  				[]types.Timestamp{66122026122739712}, []bool{false}),
   172  		},
   173  		{
   174  			info: "time to time",
   175  			inputs: []testutil.FunctionTestInput{
   176  				testutil.NewFunctionTestInput(types.T_time.ToType(),
   177  					[]types.Time{661220261227}, []bool{false}),
   178  				testutil.NewFunctionTestInput(types.T_time.ToType(), []types.Time{}, []bool{}),
   179  			},
   180  			expect: testutil.NewFunctionTestResult(types.T_time.ToType(), false,
   181  				[]types.Time{661220261227}, []bool{false}),
   182  		},
   183  	}
   184  	castInt8ToOthers := []tcTemp{
   185  		// test cast int8 to others.
   186  		{
   187  			info: "int8 to int16",
   188  			inputs: []testutil.FunctionTestInput{
   189  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   190  					[]int8{125, 126, 0}, []bool{false, false, true}),
   191  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
   192  			},
   193  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
   194  				[]int16{125, 126, 0}, []bool{false, false, true}),
   195  		},
   196  		{
   197  			info: "int8 to int32",
   198  			inputs: []testutil.FunctionTestInput{
   199  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   200  					[]int8{125, 126, 0}, []bool{false, false, true}),
   201  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
   202  			},
   203  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
   204  				[]int32{125, 126, 0}, []bool{false, false, true}),
   205  		},
   206  		{
   207  			info: "int8 to int64",
   208  			inputs: []testutil.FunctionTestInput{
   209  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   210  					[]int8{125, 126, 0}, []bool{false, false, true}),
   211  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
   212  			},
   213  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
   214  				[]int64{125, 126, 0}, []bool{false, false, true}),
   215  		},
   216  		{
   217  			info: "int8 to uint8",
   218  			inputs: []testutil.FunctionTestInput{
   219  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   220  					[]int8{125, 126, 0}, []bool{false, false, true}),
   221  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
   222  			},
   223  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
   224  				[]uint8{125, 126, 0}, []bool{false, false, true}),
   225  		},
   226  		{
   227  			info: "int8 to uint16",
   228  			inputs: []testutil.FunctionTestInput{
   229  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   230  					[]int8{125, 126, 0}, []bool{false, false, true}),
   231  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
   232  			},
   233  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
   234  				[]uint16{125, 126, 0}, []bool{false, false, true}),
   235  		},
   236  		{
   237  			info: "int8 to uint32",
   238  			inputs: []testutil.FunctionTestInput{
   239  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   240  					[]int8{125, 126, 0}, []bool{false, false, true}),
   241  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
   242  			},
   243  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
   244  				[]uint32{125, 126, 0}, []bool{false, false, true}),
   245  		},
   246  		{
   247  			info: "int8 to uint64",
   248  			inputs: []testutil.FunctionTestInput{
   249  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   250  					[]int8{125, 126, 0}, []bool{false, false, true}),
   251  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
   252  			},
   253  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
   254  				[]uint64{125, 126, 0}, []bool{false, false, true}),
   255  		},
   256  		{
   257  			info: "int8 to float32",
   258  			inputs: []testutil.FunctionTestInput{
   259  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   260  					[]int8{125, 126, 0}, []bool{false, false, true}),
   261  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   262  			},
   263  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   264  				[]float32{125, 126, 0}, []bool{false, false, true}),
   265  		},
   266  		{
   267  			info: "int8 to float64",
   268  			inputs: []testutil.FunctionTestInput{
   269  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   270  					[]int8{125, 126, 0}, []bool{false, false, true}),
   271  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
   272  			},
   273  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
   274  				[]float64{125, 126, 0}, []bool{false, false, true}),
   275  		},
   276  		{
   277  			info: "int8 to decimal128",
   278  			inputs: []testutil.FunctionTestInput{
   279  				testutil.NewFunctionTestInput(types.T_int8.ToType(),
   280  					[]int8{125, 0}, []bool{false, true}),
   281  				testutil.NewFunctionTestInput(types.T_decimal128.ToType(), []types.Decimal128{}, []bool{}),
   282  			},
   283  			expect: testutil.NewFunctionTestResult(types.T_decimal128.ToType(), false,
   284  				[]types.Decimal128{types.Decimal128FromInt32(125), [16]byte{}},
   285  				[]bool{false, true}),
   286  		},
   287  	}
   288  	castInt16ToOthers := []tcTemp{
   289  		// test cast int16 to others.
   290  		{
   291  			info: "int16 to int8",
   292  			inputs: []testutil.FunctionTestInput{
   293  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   294  					[]int16{125, 126, 0}, []bool{false, false, true}),
   295  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
   296  			},
   297  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
   298  				[]int8{125, 126, 0}, []bool{false, false, true}),
   299  		},
   300  		{
   301  			info: "int16 to int32",
   302  			inputs: []testutil.FunctionTestInput{
   303  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   304  					[]int16{125, 126, 0}, []bool{false, false, true}),
   305  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
   306  			},
   307  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
   308  				[]int32{125, 126, 0}, []bool{false, false, true}),
   309  		},
   310  		{
   311  			info: "int16 to int64",
   312  			inputs: []testutil.FunctionTestInput{
   313  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   314  					[]int16{125, 126, 0}, []bool{false, false, true}),
   315  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
   316  			},
   317  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
   318  				[]int64{125, 126, 0}, []bool{false, false, true}),
   319  		},
   320  		{
   321  			info: "int16 to uint8",
   322  			inputs: []testutil.FunctionTestInput{
   323  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   324  					[]int16{125, 126, 0}, []bool{false, false, true}),
   325  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
   326  			},
   327  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
   328  				[]uint8{125, 126, 0}, []bool{false, false, true}),
   329  		},
   330  		{
   331  			info: "int16 to uint16",
   332  			inputs: []testutil.FunctionTestInput{
   333  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   334  					[]int16{125, 126, 0}, []bool{false, false, true}),
   335  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
   336  			},
   337  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
   338  				[]uint16{125, 126, 0}, []bool{false, false, true}),
   339  		},
   340  		{
   341  			info: "int16 to uint32",
   342  			inputs: []testutil.FunctionTestInput{
   343  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   344  					[]int16{125, 126, 0}, []bool{false, false, true}),
   345  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
   346  			},
   347  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
   348  				[]uint32{125, 126, 0}, []bool{false, false, true}),
   349  		},
   350  		{
   351  			info: "int16 to uint64",
   352  			inputs: []testutil.FunctionTestInput{
   353  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   354  					[]int16{125, 126, 0}, []bool{false, false, true}),
   355  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
   356  			},
   357  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
   358  				[]uint64{125, 126, 0}, []bool{false, false, true}),
   359  		},
   360  		{
   361  			info: "int16 to float32",
   362  			inputs: []testutil.FunctionTestInput{
   363  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   364  					[]int16{125, 126, 0}, []bool{false, false, true}),
   365  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   366  			},
   367  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   368  				[]float32{125, 126, 0}, []bool{false, false, true}),
   369  		},
   370  		{
   371  			info: "int16 to float64",
   372  			inputs: []testutil.FunctionTestInput{
   373  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   374  					[]int16{125, 126, 0}, []bool{false, false, true}),
   375  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
   376  			},
   377  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
   378  				[]float64{125, 126, 0}, []bool{false, false, true}),
   379  		},
   380  		{
   381  			info: "int16 to decimal128",
   382  			inputs: []testutil.FunctionTestInput{
   383  				testutil.NewFunctionTestInput(types.T_int16.ToType(),
   384  					[]int16{125, 0}, []bool{false, true}),
   385  				testutil.NewFunctionTestInput(types.T_decimal128.ToType(), []types.Decimal128{}, []bool{}),
   386  			},
   387  			expect: testutil.NewFunctionTestResult(types.T_decimal128.ToType(), false,
   388  				[]types.Decimal128{types.Decimal128FromInt32(125), [16]byte{}},
   389  				[]bool{false, true}),
   390  		},
   391  	}
   392  	castInt32ToOthers := []tcTemp{
   393  		// test cast int32 to others.
   394  		{
   395  			info: "int32 to int16",
   396  			inputs: []testutil.FunctionTestInput{
   397  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   398  					[]int32{125, 126, 0}, []bool{false, false, true}),
   399  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
   400  			},
   401  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
   402  				[]int16{125, 126, 0}, []bool{false, false, true}),
   403  		},
   404  		{
   405  			info: "int32 to int8",
   406  			inputs: []testutil.FunctionTestInput{
   407  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   408  					[]int32{125, 126, 0}, []bool{false, false, true}),
   409  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
   410  			},
   411  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
   412  				[]int8{125, 126, 0}, []bool{false, false, true}),
   413  		},
   414  		{
   415  			info: "int32 to int64",
   416  			inputs: []testutil.FunctionTestInput{
   417  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   418  					[]int32{125, 126, 0}, []bool{false, false, true}),
   419  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
   420  			},
   421  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
   422  				[]int64{125, 126, 0}, []bool{false, false, true}),
   423  		},
   424  		{
   425  			info: "int32 to uint8",
   426  			inputs: []testutil.FunctionTestInput{
   427  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   428  					[]int32{125, 126, 0}, []bool{false, false, true}),
   429  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
   430  			},
   431  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
   432  				[]uint8{125, 126, 0}, []bool{false, false, true}),
   433  		},
   434  		{
   435  			info: "int32 to uint16",
   436  			inputs: []testutil.FunctionTestInput{
   437  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   438  					[]int32{125, 126, 0}, []bool{false, false, true}),
   439  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
   440  			},
   441  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
   442  				[]uint16{125, 126, 0}, []bool{false, false, true}),
   443  		},
   444  		{
   445  			info: "int32 to uint32",
   446  			inputs: []testutil.FunctionTestInput{
   447  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   448  					[]int32{125, 126, 0}, []bool{false, false, true}),
   449  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
   450  			},
   451  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
   452  				[]uint32{125, 126, 0}, []bool{false, false, true}),
   453  		},
   454  		{
   455  			info: "int32 to uint64",
   456  			inputs: []testutil.FunctionTestInput{
   457  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   458  					[]int32{125, 126, 0}, []bool{false, false, true}),
   459  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
   460  			},
   461  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
   462  				[]uint64{125, 126, 0}, []bool{false, false, true}),
   463  		},
   464  		{
   465  			info: "int32 to float32",
   466  			inputs: []testutil.FunctionTestInput{
   467  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   468  					[]int32{125, 126, 0}, []bool{false, false, true}),
   469  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   470  			},
   471  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   472  				[]float32{125, 126, 0}, []bool{false, false, true}),
   473  		},
   474  		{
   475  			info: "int32 to float64",
   476  			inputs: []testutil.FunctionTestInput{
   477  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   478  					[]int32{125, 126, 0}, []bool{false, false, true}),
   479  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
   480  			},
   481  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
   482  				[]float64{125, 126, 0}, []bool{false, false, true}),
   483  		},
   484  		{
   485  			info: "int32 to decimal128",
   486  			inputs: []testutil.FunctionTestInput{
   487  				testutil.NewFunctionTestInput(types.T_int32.ToType(),
   488  					[]int32{125, 0}, []bool{false, true}),
   489  				testutil.NewFunctionTestInput(types.T_decimal128.ToType(), []types.Decimal128{}, []bool{}),
   490  			},
   491  			expect: testutil.NewFunctionTestResult(types.T_decimal128.ToType(), false,
   492  				[]types.Decimal128{types.Decimal128FromInt32(125), [16]byte{}},
   493  				[]bool{false, true}),
   494  		},
   495  	}
   496  	castInt64ToOthers := []tcTemp{
   497  		// test cast int64 to others.
   498  		{
   499  			info: "int64 to int8",
   500  			inputs: []testutil.FunctionTestInput{
   501  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   502  					[]int64{125, 126, 0}, []bool{false, false, true}),
   503  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
   504  			},
   505  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
   506  				[]int8{125, 126, 0}, []bool{false, false, true}),
   507  		},
   508  		{
   509  			info: "int64 to int16",
   510  			inputs: []testutil.FunctionTestInput{
   511  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   512  					[]int64{125, 126, 0}, []bool{false, false, true}),
   513  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
   514  			},
   515  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
   516  				[]int16{125, 126, 0}, []bool{false, false, true}),
   517  		},
   518  		{
   519  			info: "int64 to int32",
   520  			inputs: []testutil.FunctionTestInput{
   521  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   522  					[]int64{125, 126, 0}, []bool{false, false, true}),
   523  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
   524  			},
   525  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
   526  				[]int32{125, 126, 0}, []bool{false, false, true}),
   527  		},
   528  		{
   529  			info: "int64 to uint8",
   530  			inputs: []testutil.FunctionTestInput{
   531  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   532  					[]int64{125, 126, 0}, []bool{false, false, true}),
   533  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
   534  			},
   535  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
   536  				[]uint8{125, 126, 0}, []bool{false, false, true}),
   537  		},
   538  		{
   539  			info: "int64 to uint16",
   540  			inputs: []testutil.FunctionTestInput{
   541  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   542  					[]int64{125, 126, 0}, []bool{false, false, true}),
   543  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
   544  			},
   545  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
   546  				[]uint16{125, 126, 0}, []bool{false, false, true}),
   547  		},
   548  		{
   549  			info: "int64 to uint32",
   550  			inputs: []testutil.FunctionTestInput{
   551  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   552  					[]int64{125, 126, 0}, []bool{false, false, true}),
   553  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
   554  			},
   555  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
   556  				[]uint32{125, 126, 0}, []bool{false, false, true}),
   557  		},
   558  		{
   559  			info: "int64 to uint64",
   560  			inputs: []testutil.FunctionTestInput{
   561  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   562  					[]int64{125, 126, 0}, []bool{false, false, true}),
   563  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
   564  			},
   565  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
   566  				[]uint64{125, 126, 0}, []bool{false, false, true}),
   567  		},
   568  		{
   569  			info: "int64 to float32",
   570  			inputs: []testutil.FunctionTestInput{
   571  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   572  					[]int64{125, 126, 0}, []bool{false, false, true}),
   573  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   574  			},
   575  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   576  				[]float32{125, 126, 0}, []bool{false, false, true}),
   577  		},
   578  		{
   579  			info: "int64 to float64",
   580  			inputs: []testutil.FunctionTestInput{
   581  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   582  					[]int64{125, 126, 0}, []bool{false, false, true}),
   583  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
   584  			},
   585  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
   586  				[]float64{125, 126, 0}, []bool{false, false, true}),
   587  		},
   588  		{
   589  			info: "int64 to decimal128",
   590  			inputs: []testutil.FunctionTestInput{
   591  				testutil.NewFunctionTestInput(types.T_int64.ToType(),
   592  					[]int64{125, 0}, []bool{false, true}),
   593  				testutil.NewFunctionTestInput(types.T_decimal128.ToType(), []types.Decimal128{}, []bool{}),
   594  			},
   595  			expect: testutil.NewFunctionTestResult(types.T_decimal128.ToType(), false,
   596  				[]types.Decimal128{types.Decimal128FromInt32(125), [16]byte{}},
   597  				[]bool{false, true}),
   598  		},
   599  	}
   600  	castUint8ToOthers := []tcTemp{
   601  		// test cast uint8 to others.
   602  		{
   603  			info: "uint8 to int16",
   604  			inputs: []testutil.FunctionTestInput{
   605  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   606  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   607  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
   608  			},
   609  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
   610  				[]int16{125, 126, 0}, []bool{false, false, true}),
   611  		},
   612  		{
   613  			info: "uint8 to int32",
   614  			inputs: []testutil.FunctionTestInput{
   615  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   616  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   617  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
   618  			},
   619  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
   620  				[]int32{125, 126, 0}, []bool{false, false, true}),
   621  		},
   622  		{
   623  			info: "uint8 to int64",
   624  			inputs: []testutil.FunctionTestInput{
   625  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   626  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   627  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
   628  			},
   629  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
   630  				[]int64{125, 126, 0}, []bool{false, false, true}),
   631  		},
   632  		{
   633  			info: "uint8 to int8",
   634  			inputs: []testutil.FunctionTestInput{
   635  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   636  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   637  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
   638  			},
   639  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
   640  				[]int8{125, 126, 0}, []bool{false, false, true}),
   641  		},
   642  		{
   643  			info: "uint8 to uint16",
   644  			inputs: []testutil.FunctionTestInput{
   645  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   646  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   647  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
   648  			},
   649  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
   650  				[]uint16{125, 126, 0}, []bool{false, false, true}),
   651  		},
   652  		{
   653  			info: "uint8 to uint32",
   654  			inputs: []testutil.FunctionTestInput{
   655  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   656  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   657  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
   658  			},
   659  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
   660  				[]uint32{125, 126, 0}, []bool{false, false, true}),
   661  		},
   662  		{
   663  			info: "uint8 to uint64",
   664  			inputs: []testutil.FunctionTestInput{
   665  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   666  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   667  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
   668  			},
   669  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
   670  				[]uint64{125, 126, 0}, []bool{false, false, true}),
   671  		},
   672  		{
   673  			info: "uint8 to float32",
   674  			inputs: []testutil.FunctionTestInput{
   675  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   676  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   677  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   678  			},
   679  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   680  				[]float32{125, 126, 0}, []bool{false, false, true}),
   681  		},
   682  		{
   683  			info: "uint8 to float64",
   684  			inputs: []testutil.FunctionTestInput{
   685  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   686  					[]uint8{125, 126, 0}, []bool{false, false, true}),
   687  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
   688  			},
   689  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
   690  				[]float64{125, 126, 0}, []bool{false, false, true}),
   691  		},
   692  		{
   693  			info: "uint8 to decimal128",
   694  			inputs: []testutil.FunctionTestInput{
   695  				testutil.NewFunctionTestInput(types.T_uint8.ToType(),
   696  					[]uint8{125, 0}, []bool{false, true}),
   697  				testutil.NewFunctionTestInput(types.T_decimal128.ToType(), []types.Decimal128{}, []bool{}),
   698  			},
   699  			expect: testutil.NewFunctionTestResult(types.T_decimal128.ToType(), false,
   700  				[]types.Decimal128{types.Decimal128FromInt32(125), [16]byte{}},
   701  				[]bool{false, true}),
   702  		},
   703  	}
   704  	castUint16ToOthers := []tcTemp{
   705  		// test cast uint16 to others.
   706  		{
   707  			info: "uint16 to int8",
   708  			inputs: []testutil.FunctionTestInput{
   709  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   710  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   711  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
   712  			},
   713  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
   714  				[]int8{125, 126, 0}, []bool{false, false, true}),
   715  		},
   716  		{
   717  			info: "uint16 to int32",
   718  			inputs: []testutil.FunctionTestInput{
   719  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   720  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   721  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
   722  			},
   723  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
   724  				[]int32{125, 126, 0}, []bool{false, false, true}),
   725  		},
   726  		{
   727  			info: "uint16 to int64",
   728  			inputs: []testutil.FunctionTestInput{
   729  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   730  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   731  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
   732  			},
   733  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
   734  				[]int64{125, 126, 0}, []bool{false, false, true}),
   735  		},
   736  		{
   737  			info: "uint16 to uint8",
   738  			inputs: []testutil.FunctionTestInput{
   739  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   740  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   741  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
   742  			},
   743  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
   744  				[]uint8{125, 126, 0}, []bool{false, false, true}),
   745  		},
   746  		{
   747  			info: "uint16 to int16",
   748  			inputs: []testutil.FunctionTestInput{
   749  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   750  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   751  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
   752  			},
   753  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
   754  				[]int16{125, 126, 0}, []bool{false, false, true}),
   755  		},
   756  		{
   757  			info: "uint16 to uint32",
   758  			inputs: []testutil.FunctionTestInput{
   759  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   760  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   761  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
   762  			},
   763  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
   764  				[]uint32{125, 126, 0}, []bool{false, false, true}),
   765  		},
   766  		{
   767  			info: "uint16 to uint64",
   768  			inputs: []testutil.FunctionTestInput{
   769  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   770  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   771  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
   772  			},
   773  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
   774  				[]uint64{125, 126, 0}, []bool{false, false, true}),
   775  		},
   776  		{
   777  			info: "uint16 to float32",
   778  			inputs: []testutil.FunctionTestInput{
   779  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   780  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   781  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   782  			},
   783  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   784  				[]float32{125, 126, 0}, []bool{false, false, true}),
   785  		},
   786  		{
   787  			info: "uint16 to float64",
   788  			inputs: []testutil.FunctionTestInput{
   789  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   790  					[]uint16{125, 126, 0}, []bool{false, false, true}),
   791  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
   792  			},
   793  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
   794  				[]float64{125, 126, 0}, []bool{false, false, true}),
   795  		},
   796  		{
   797  			info: "uint16 to decimal128",
   798  			inputs: []testutil.FunctionTestInput{
   799  				testutil.NewFunctionTestInput(types.T_uint16.ToType(),
   800  					[]uint16{125, 0}, []bool{false, true}),
   801  				testutil.NewFunctionTestInput(types.T_decimal128.ToType(), []types.Decimal128{}, []bool{}),
   802  			},
   803  			expect: testutil.NewFunctionTestResult(types.T_decimal128.ToType(), false,
   804  				[]types.Decimal128{types.Decimal128FromInt32(125), [16]byte{}},
   805  				[]bool{false, true}),
   806  		},
   807  	}
   808  	castUint32ToOthers := []tcTemp{
   809  		// test cast uint32 to others.
   810  		{
   811  			info: "uint32 to int16",
   812  			inputs: []testutil.FunctionTestInput{
   813  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   814  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   815  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
   816  			},
   817  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
   818  				[]int16{125, 126, 0}, []bool{false, false, true}),
   819  		},
   820  		{
   821  			info: "uint32 to int8",
   822  			inputs: []testutil.FunctionTestInput{
   823  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   824  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   825  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
   826  			},
   827  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
   828  				[]int8{125, 126, 0}, []bool{false, false, true}),
   829  		},
   830  		{
   831  			info: "uint32 to int64",
   832  			inputs: []testutil.FunctionTestInput{
   833  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   834  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   835  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
   836  			},
   837  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
   838  				[]int64{125, 126, 0}, []bool{false, false, true}),
   839  		},
   840  		{
   841  			info: "uint32 to uint8",
   842  			inputs: []testutil.FunctionTestInput{
   843  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   844  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   845  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
   846  			},
   847  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
   848  				[]uint8{125, 126, 0}, []bool{false, false, true}),
   849  		},
   850  		{
   851  			info: "uint32 to uint16",
   852  			inputs: []testutil.FunctionTestInput{
   853  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   854  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   855  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
   856  			},
   857  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
   858  				[]uint16{125, 126, 0}, []bool{false, false, true}),
   859  		},
   860  		{
   861  			info: "uint32 to int32",
   862  			inputs: []testutil.FunctionTestInput{
   863  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   864  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   865  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
   866  			},
   867  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
   868  				[]int32{125, 126, 0}, []bool{false, false, true}),
   869  		},
   870  		{
   871  			info: "uint32 to uint64",
   872  			inputs: []testutil.FunctionTestInput{
   873  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   874  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   875  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
   876  			},
   877  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
   878  				[]uint64{125, 126, 0}, []bool{false, false, true}),
   879  		},
   880  		{
   881  			info: "uint32 to float32",
   882  			inputs: []testutil.FunctionTestInput{
   883  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   884  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   885  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   886  			},
   887  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   888  				[]float32{125, 126, 0}, []bool{false, false, true}),
   889  		},
   890  		{
   891  			info: "uint32 to float64",
   892  			inputs: []testutil.FunctionTestInput{
   893  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   894  					[]uint32{125, 126, 0}, []bool{false, false, true}),
   895  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
   896  			},
   897  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
   898  				[]float64{125, 126, 0}, []bool{false, false, true}),
   899  		},
   900  		{
   901  			info: "uint32 to decimal128",
   902  			inputs: []testutil.FunctionTestInput{
   903  				testutil.NewFunctionTestInput(types.T_uint32.ToType(),
   904  					[]uint32{125, 0}, []bool{false, true}),
   905  				testutil.NewFunctionTestInput(types.T_decimal128.ToType(), []types.Decimal128{}, []bool{}),
   906  			},
   907  			expect: testutil.NewFunctionTestResult(types.T_decimal128.ToType(), false,
   908  				[]types.Decimal128{types.Decimal128FromInt32(125), [16]byte{}},
   909  				[]bool{false, true}),
   910  		},
   911  	}
   912  	castUint64ToOthers := []tcTemp{
   913  		// test cast uint64 to others.
   914  		{
   915  			info: "uint64 to int8",
   916  			inputs: []testutil.FunctionTestInput{
   917  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   918  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   919  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
   920  			},
   921  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
   922  				[]int8{125, 126, 0}, []bool{false, false, true}),
   923  		},
   924  		{
   925  			info: "uint64 to int16",
   926  			inputs: []testutil.FunctionTestInput{
   927  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   928  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   929  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
   930  			},
   931  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
   932  				[]int16{125, 126, 0}, []bool{false, false, true}),
   933  		},
   934  		{
   935  			info: "uint64 to int32",
   936  			inputs: []testutil.FunctionTestInput{
   937  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   938  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   939  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
   940  			},
   941  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
   942  				[]int32{125, 126, 0}, []bool{false, false, true}),
   943  		},
   944  		{
   945  			info: "uint64 to uint8",
   946  			inputs: []testutil.FunctionTestInput{
   947  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   948  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   949  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
   950  			},
   951  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
   952  				[]uint8{125, 126, 0}, []bool{false, false, true}),
   953  		},
   954  		{
   955  			info: "uint64 to uint16",
   956  			inputs: []testutil.FunctionTestInput{
   957  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   958  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   959  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
   960  			},
   961  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
   962  				[]uint16{125, 126, 0}, []bool{false, false, true}),
   963  		},
   964  		{
   965  			info: "uint64 to uint32",
   966  			inputs: []testutil.FunctionTestInput{
   967  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   968  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   969  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
   970  			},
   971  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
   972  				[]uint32{125, 126, 0}, []bool{false, false, true}),
   973  		},
   974  		{
   975  			info: "uint64 to int64",
   976  			inputs: []testutil.FunctionTestInput{
   977  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   978  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   979  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
   980  			},
   981  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
   982  				[]int64{125, 126, 0}, []bool{false, false, true}),
   983  		},
   984  		{
   985  			info: "uint64 to float32",
   986  			inputs: []testutil.FunctionTestInput{
   987  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   988  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   989  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
   990  			},
   991  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
   992  				[]float32{125, 126, 0}, []bool{false, false, true}),
   993  		},
   994  		{
   995  			info: "uint64 to float64",
   996  			inputs: []testutil.FunctionTestInput{
   997  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
   998  					[]uint64{125, 126, 0}, []bool{false, false, true}),
   999  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
  1000  			},
  1001  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
  1002  				[]float64{125, 126, 0}, []bool{false, false, true}),
  1003  		},
  1004  		{
  1005  			info: "uint64 to decimal128",
  1006  			inputs: []testutil.FunctionTestInput{
  1007  				testutil.NewFunctionTestInput(types.T_uint64.ToType(),
  1008  					[]uint64{125, 0}, []bool{false, true}),
  1009  				testutil.NewFunctionTestInput(types.T_decimal128.ToType(), []types.Decimal128{}, []bool{}),
  1010  			},
  1011  			expect: testutil.NewFunctionTestResult(types.T_decimal128.ToType(), false,
  1012  				[]types.Decimal128{types.Decimal128FromInt32(125), [16]byte{}},
  1013  				[]bool{false, true}),
  1014  		},
  1015  	}
  1016  	castFloat32ToOthers := []tcTemp{
  1017  		// test cast float32 to others.
  1018  		{
  1019  			info: "float32 to int8",
  1020  			inputs: []testutil.FunctionTestInput{
  1021  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1022  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1023  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
  1024  			},
  1025  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
  1026  				[]int8{125, 126, 0}, []bool{false, false, true}),
  1027  		},
  1028  		{
  1029  			info: "float32 to int16",
  1030  			inputs: []testutil.FunctionTestInput{
  1031  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1032  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1033  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
  1034  			},
  1035  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
  1036  				[]int16{125, 126, 0}, []bool{false, false, true}),
  1037  		},
  1038  		{
  1039  			info: "float32 to int32",
  1040  			inputs: []testutil.FunctionTestInput{
  1041  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1042  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1043  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
  1044  			},
  1045  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
  1046  				[]int32{125, 126, 0}, []bool{false, false, true}),
  1047  		},
  1048  		{
  1049  			info: "float32 to uint8",
  1050  			inputs: []testutil.FunctionTestInput{
  1051  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1052  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1053  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
  1054  			},
  1055  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
  1056  				[]uint8{125, 126, 0}, []bool{false, false, true}),
  1057  		},
  1058  		{
  1059  			info: "float32 to uint16",
  1060  			inputs: []testutil.FunctionTestInput{
  1061  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1062  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1063  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
  1064  			},
  1065  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
  1066  				[]uint16{125, 126, 0}, []bool{false, false, true}),
  1067  		},
  1068  		{
  1069  			info: "float32 to uint32",
  1070  			inputs: []testutil.FunctionTestInput{
  1071  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1072  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1073  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
  1074  			},
  1075  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
  1076  				[]uint32{125, 126, 0}, []bool{false, false, true}),
  1077  		},
  1078  		{
  1079  			info: "float32 to int64",
  1080  			inputs: []testutil.FunctionTestInput{
  1081  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1082  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1083  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
  1084  			},
  1085  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
  1086  				[]int64{125, 126, 0}, []bool{false, false, true}),
  1087  		},
  1088  		{
  1089  			info: "float32 to float64",
  1090  			inputs: []testutil.FunctionTestInput{
  1091  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1092  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1093  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
  1094  			},
  1095  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
  1096  				[]float64{125, 126, 0}, []bool{false, false, true}),
  1097  		},
  1098  		{
  1099  			info: "float32 to uint64",
  1100  			inputs: []testutil.FunctionTestInput{
  1101  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1102  					[]float32{125, 126, 0}, []bool{false, false, true}),
  1103  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
  1104  			},
  1105  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
  1106  				[]uint64{125, 126, 0}, []bool{false, false, true}),
  1107  		},
  1108  		{
  1109  			info: "float32 to str type",
  1110  			inputs: []testutil.FunctionTestInput{
  1111  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1112  					[]float32{23.56, 126, 0}, []bool{false, false, true}),
  1113  				testutil.NewFunctionTestInput(types.T_char.ToType(), []string{}, []bool{}),
  1114  			},
  1115  			expect: testutil.NewFunctionTestResult(types.T_char.ToType(), false,
  1116  				[]string{"23.56", "126", "0"}, []bool{false, false, true}),
  1117  		},
  1118  		{
  1119  			info: "float32 to decimal128",
  1120  			inputs: []testutil.FunctionTestInput{
  1121  				testutil.NewFunctionTestInput(types.T_float32.ToType(),
  1122  					[]float32{125.1, 0}, []bool{false, true}),
  1123  				testutil.NewFunctionTestInput(types.Type{
  1124  					Oid: types.T_decimal128, Width: 8, Scale: 2,
  1125  				}, []types.Decimal128{}, []bool{}),
  1126  			},
  1127  			expect: testutil.NewFunctionTestResult(types.Type{
  1128  				Oid: types.T_decimal128, Width: 8, Scale: 2,
  1129  			}, false,
  1130  				[]types.Decimal128{f1251ToDec128, [16]byte{}},
  1131  				[]bool{false, true}),
  1132  		},
  1133  	}
  1134  	castFloat64ToOthers := []tcTemp{
  1135  		// test cast float64 to others.
  1136  		{
  1137  			info: "float64 to int8",
  1138  			inputs: []testutil.FunctionTestInput{
  1139  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1140  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1141  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
  1142  			},
  1143  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
  1144  				[]int8{125, 126, 0}, []bool{false, false, true}),
  1145  		},
  1146  		{
  1147  			info: "float64 to int16",
  1148  			inputs: []testutil.FunctionTestInput{
  1149  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1150  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1151  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
  1152  			},
  1153  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
  1154  				[]int16{125, 126, 0}, []bool{false, false, true}),
  1155  		},
  1156  		{
  1157  			info: "float64 to int32",
  1158  			inputs: []testutil.FunctionTestInput{
  1159  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1160  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1161  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
  1162  			},
  1163  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
  1164  				[]int32{125, 126, 0}, []bool{false, false, true}),
  1165  		},
  1166  		{
  1167  			info: "float64 to uint8",
  1168  			inputs: []testutil.FunctionTestInput{
  1169  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1170  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1171  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
  1172  			},
  1173  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
  1174  				[]uint8{125, 126, 0}, []bool{false, false, true}),
  1175  		},
  1176  		{
  1177  			info: "float64 to uint16",
  1178  			inputs: []testutil.FunctionTestInput{
  1179  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1180  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1181  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
  1182  			},
  1183  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
  1184  				[]uint16{125, 126, 0}, []bool{false, false, true}),
  1185  		},
  1186  		{
  1187  			info: "float64 to uint32",
  1188  			inputs: []testutil.FunctionTestInput{
  1189  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1190  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1191  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
  1192  			},
  1193  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
  1194  				[]uint32{125, 126, 0}, []bool{false, false, true}),
  1195  		},
  1196  		{
  1197  			info: "float64 to int64",
  1198  			inputs: []testutil.FunctionTestInput{
  1199  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1200  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1201  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
  1202  			},
  1203  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
  1204  				[]int64{125, 126, 0}, []bool{false, false, true}),
  1205  		},
  1206  		{
  1207  			info: "float64 to float32",
  1208  			inputs: []testutil.FunctionTestInput{
  1209  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1210  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1211  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
  1212  			},
  1213  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
  1214  				[]float32{125, 126, 0}, []bool{false, false, true}),
  1215  		},
  1216  		{
  1217  			info: "float64 to uint64",
  1218  			inputs: []testutil.FunctionTestInput{
  1219  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1220  					[]float64{125, 126, 0}, []bool{false, false, true}),
  1221  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
  1222  			},
  1223  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
  1224  				[]uint64{125, 126, 0}, []bool{false, false, true}),
  1225  		},
  1226  		{
  1227  			info: "float64 to str type",
  1228  			inputs: []testutil.FunctionTestInput{
  1229  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1230  					[]float64{23.56, 126, 0}, []bool{false, false, true}),
  1231  				testutil.NewFunctionTestInput(types.T_char.ToType(), []string{}, []bool{}),
  1232  			},
  1233  			expect: testutil.NewFunctionTestResult(types.T_char.ToType(), false,
  1234  				[]string{"23.56", "126", "0"}, []bool{false, false, true}),
  1235  		},
  1236  		{
  1237  			info: "float64 to decimal128",
  1238  			inputs: []testutil.FunctionTestInput{
  1239  				testutil.NewFunctionTestInput(types.T_float64.ToType(),
  1240  					[]float64{125.1, 0}, []bool{false, true}),
  1241  				testutil.NewFunctionTestInput(types.Type{
  1242  					Oid: types.T_decimal128, Width: 8, Scale: 2,
  1243  				}, []types.Decimal128{}, []bool{}),
  1244  			},
  1245  			expect: testutil.NewFunctionTestResult(types.Type{
  1246  				Oid: types.T_decimal128, Width: 8, Scale: 2,
  1247  			}, false,
  1248  				[]types.Decimal128{f1251ToDec128, [16]byte{}},
  1249  				[]bool{false, true}),
  1250  		},
  1251  	}
  1252  	castStrToOthers := []tcTemp{
  1253  		{
  1254  			info: "str type to int8",
  1255  			inputs: []testutil.FunctionTestInput{
  1256  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1257  					[]string{"15", "16"}, nil),
  1258  				testutil.NewFunctionTestInput(types.T_int8.ToType(), []int8{}, []bool{}),
  1259  			},
  1260  			expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false,
  1261  				[]int8{15, 16}, []bool{false, false}),
  1262  		},
  1263  		{
  1264  			info: "str type to int16",
  1265  			inputs: []testutil.FunctionTestInput{
  1266  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1267  					[]string{"15", "16"}, nil),
  1268  				testutil.NewFunctionTestInput(types.T_int16.ToType(), []int16{}, []bool{}),
  1269  			},
  1270  			expect: testutil.NewFunctionTestResult(types.T_int16.ToType(), false,
  1271  				[]int16{15, 16}, []bool{false, false}),
  1272  		},
  1273  		{
  1274  			info: "str type to int32",
  1275  			inputs: []testutil.FunctionTestInput{
  1276  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1277  					[]string{"15", "16"}, nil),
  1278  				testutil.NewFunctionTestInput(types.T_int32.ToType(), []int32{}, []bool{}),
  1279  			},
  1280  			expect: testutil.NewFunctionTestResult(types.T_int32.ToType(), false,
  1281  				[]int32{15, 16}, []bool{false, false}),
  1282  		},
  1283  		{
  1284  			info: "str type to int64",
  1285  			inputs: []testutil.FunctionTestInput{
  1286  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1287  					[]string{"1501", "16", ""}, []bool{false, false, true}),
  1288  				testutil.NewFunctionTestInput(types.T_int64.ToType(), []int64{}, []bool{}),
  1289  			},
  1290  			expect: testutil.NewFunctionTestResult(types.T_int64.ToType(), false,
  1291  				[]int64{1501, 16, 0}, []bool{false, false, true}),
  1292  		},
  1293  		{
  1294  			info: "str type to uint8",
  1295  			inputs: []testutil.FunctionTestInput{
  1296  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1297  					[]string{"15", "16"}, nil),
  1298  				testutil.NewFunctionTestInput(types.T_uint8.ToType(), []uint8{}, []bool{}),
  1299  			},
  1300  			expect: testutil.NewFunctionTestResult(types.T_uint8.ToType(), false,
  1301  				[]uint8{15, 16}, []bool{false, false}),
  1302  		},
  1303  		{
  1304  			info: "str type to uint16",
  1305  			inputs: []testutil.FunctionTestInput{
  1306  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1307  					[]string{"15", "16"}, nil),
  1308  				testutil.NewFunctionTestInput(types.T_uint16.ToType(), []uint16{}, []bool{}),
  1309  			},
  1310  			expect: testutil.NewFunctionTestResult(types.T_uint16.ToType(), false,
  1311  				[]uint16{15, 16}, []bool{false, false}),
  1312  		},
  1313  		{
  1314  			info: "str type to uint32",
  1315  			inputs: []testutil.FunctionTestInput{
  1316  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1317  					[]string{"15", "16"}, nil),
  1318  				testutil.NewFunctionTestInput(types.T_uint32.ToType(), []uint32{}, []bool{}),
  1319  			},
  1320  			expect: testutil.NewFunctionTestResult(types.T_uint32.ToType(), false,
  1321  				[]uint32{15, 16}, []bool{false, false}),
  1322  		},
  1323  		{
  1324  			info: "str type to uint64",
  1325  			inputs: []testutil.FunctionTestInput{
  1326  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1327  					[]string{"1501", "16", ""}, []bool{false, false, true}),
  1328  				testutil.NewFunctionTestInput(types.T_uint64.ToType(), []uint64{}, []bool{}),
  1329  			},
  1330  			expect: testutil.NewFunctionTestResult(types.T_uint64.ToType(), false,
  1331  				[]uint64{1501, 16, 0}, []bool{false, false, true}),
  1332  		},
  1333  		{
  1334  			info: "str type to float32",
  1335  			inputs: []testutil.FunctionTestInput{
  1336  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1337  					[]string{"15", "16"}, nil),
  1338  				testutil.NewFunctionTestInput(types.T_float32.ToType(), []float32{}, []bool{}),
  1339  			},
  1340  			expect: testutil.NewFunctionTestResult(types.T_float32.ToType(), false,
  1341  				[]float32{15, 16}, []bool{false, false}),
  1342  		},
  1343  		{
  1344  			info: "str type to float64",
  1345  			inputs: []testutil.FunctionTestInput{
  1346  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1347  					[]string{"1501.12", "16", ""}, []bool{false, false, true}),
  1348  				testutil.NewFunctionTestInput(types.T_float64.ToType(), []float64{}, []bool{}),
  1349  			},
  1350  			expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false,
  1351  				[]float64{1501.12, 16, 0}, []bool{false, false, true}),
  1352  		},
  1353  		{
  1354  			info: "str type to str type",
  1355  			inputs: []testutil.FunctionTestInput{
  1356  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1357  					[]string{"1501.12", "16", ""}, []bool{false, false, true}),
  1358  				testutil.NewFunctionTestInput(types.T_text.ToType(), []string{}, []bool{}),
  1359  			},
  1360  			expect: testutil.NewFunctionTestResult(types.T_text.ToType(), false,
  1361  				[]string{"1501.12", "16", ""}, []bool{false, false, true}),
  1362  		},
  1363  		{
  1364  			info: "str type to date",
  1365  			inputs: []testutil.FunctionTestInput{
  1366  				testutil.NewFunctionTestInput(types.T_varchar.ToType(),
  1367  					[]string{"2004-04-03", "2004-04-03", "2021-10-03"},
  1368  					[]bool{false, false, false}),
  1369  				testutil.NewFunctionTestInput(types.T_date.ToType(), []types.Date{}, []bool{}),
  1370  			},
  1371  			expect: testutil.NewFunctionTestResult(
  1372  				types.T_date.ToType(), false,
  1373  				[]types.Date{
  1374  					s01date, s01date, s02date,
  1375  				},
  1376  				[]bool{false, false, false}),
  1377  		},
  1378  	}
  1379  	castDecToOthers := []tcTemp{
  1380  		{
  1381  			info: "decimal64 to decimal128",
  1382  			inputs: []testutil.FunctionTestInput{
  1383  				testutil.NewFunctionTestInput(
  1384  					types.Type{Oid: types.T_decimal64, Size: 8, Width: 10, Scale: 5},
  1385  					[]types.Decimal64{types.Decimal64FromInt32(333333000)}, nil),
  1386  				testutil.NewFunctionTestInput(
  1387  					types.Type{Oid: types.T_decimal128, Size: 16, Width: 20, Scale: 5},
  1388  					[]types.Decimal128{}, nil),
  1389  			},
  1390  			expect: testutil.NewFunctionTestResult(
  1391  				types.Type{Oid: types.T_decimal128, Size: 16, Width: 20, Scale: 5}, false,
  1392  				[]types.Decimal128{types.Decimal128FromInt32(333333000)}, nil),
  1393  		},
  1394  		{
  1395  			info: "decimal64(10,5) to decimal64(10, 4)",
  1396  			inputs: []testutil.FunctionTestInput{
  1397  				testutil.NewFunctionTestInput(
  1398  					types.Type{Oid: types.T_decimal64, Size: 8, Width: 10, Scale: 5},
  1399  					[]types.Decimal64{types.Decimal64FromInt32(33333300)}, nil),
  1400  				testutil.NewFunctionTestInput(
  1401  					types.Type{Oid: types.T_decimal64, Size: 8, Width: 10, Scale: 4},
  1402  					[]types.Decimal64{}, nil),
  1403  			},
  1404  			expect: testutil.NewFunctionTestResult(
  1405  				types.Type{Oid: types.T_decimal64, Size: 8, Width: 10, Scale: 4}, false,
  1406  				[]types.Decimal64{types.Decimal64FromInt32(33333300)}, nil),
  1407  		},
  1408  		{
  1409  			info: "decimal64(10,5) to decimal128(20, 5)",
  1410  			inputs: []testutil.FunctionTestInput{
  1411  				testutil.NewFunctionTestInput(
  1412  					types.Type{Oid: types.T_decimal64, Size: 8, Width: 10, Scale: 5},
  1413  					[]types.Decimal64{types.Decimal64FromInt32(333333000)}, nil),
  1414  				testutil.NewFunctionTestInput(
  1415  					types.Type{Oid: types.T_decimal128, Size: 16, Width: 20, Scale: 5},
  1416  					[]types.Decimal128{}, nil),
  1417  			},
  1418  			expect: testutil.NewFunctionTestResult(
  1419  				types.Type{Oid: types.T_decimal128, Size: 16, Width: 20, Scale: 5}, false,
  1420  				[]types.Decimal128{types.Decimal128FromInt32(333333000)}, nil),
  1421  		},
  1422  		{
  1423  			info: "decimal128(20,5) to decimal128(20, 4)",
  1424  			inputs: []testutil.FunctionTestInput{
  1425  				testutil.NewFunctionTestInput(
  1426  					types.Type{Oid: types.T_decimal128, Size: 16, Width: 20, Scale: 5},
  1427  					[]types.Decimal128{types.Decimal128FromInt32(33333300)}, nil),
  1428  				testutil.NewFunctionTestInput(
  1429  					types.Type{Oid: types.T_decimal128, Size: 16, Width: 20, Scale: 5},
  1430  					[]types.Decimal128{}, nil),
  1431  			},
  1432  			expect: testutil.NewFunctionTestResult(
  1433  				types.Type{Oid: types.T_decimal128, Size: 16, Width: 20, Scale: 5}, false,
  1434  				[]types.Decimal128{types.Decimal128FromInt32(33333300)}, nil),
  1435  		},
  1436  		{
  1437  			info: "decimal64 to str type",
  1438  			inputs: []testutil.FunctionTestInput{
  1439  				testutil.NewFunctionTestInput(
  1440  					types.Type{Oid: types.T_decimal64, Size: 8, Width: 10, Scale: 5},
  1441  					[]types.Decimal64{types.Decimal64FromInt32(1234)}, nil),
  1442  				testutil.NewFunctionTestInput(
  1443  					types.T_varchar.ToType(),
  1444  					[]string{}, nil),
  1445  			},
  1446  			expect: testutil.NewFunctionTestResult(
  1447  				types.T_varchar.ToType(), false,
  1448  				[]string{"1234.00000"}, nil),
  1449  		},
  1450  		{
  1451  			info: "decimal128 to str type",
  1452  			inputs: []testutil.FunctionTestInput{
  1453  				testutil.NewFunctionTestInput(
  1454  					types.Type{Oid: types.T_decimal128, Size: 8, Width: 20, Scale: 2},
  1455  					[]types.Decimal128{types.Decimal128FromInt32(1234)}, nil),
  1456  				testutil.NewFunctionTestInput(
  1457  					types.T_varchar.ToType(),
  1458  					[]string{}, nil),
  1459  			},
  1460  			expect: testutil.NewFunctionTestResult(
  1461  				types.T_varchar.ToType(), false,
  1462  				[]string{"1234.00"}, nil),
  1463  		},
  1464  	}
  1465  	castTimestampToOthers := []tcTemp{
  1466  		{
  1467  			info: "timestamp to str type",
  1468  			inputs: []testutil.FunctionTestInput{
  1469  				testutil.NewFunctionTestInput(
  1470  					types.T_timestamp.ToType(),
  1471  					[]types.Timestamp{s01ts}, nil),
  1472  				testutil.NewFunctionTestInput(
  1473  					types.T_varchar.ToType(), []string{}, nil),
  1474  			},
  1475  			expect: testutil.NewFunctionTestResult(
  1476  				types.T_varchar.ToType(), false,
  1477  				[]string{"2020-08-23 11:52:21"}, nil),
  1478  		},
  1479  	}
  1480  
  1481  	// init the testCases
  1482  	testCases = append(testCases, castToSameTypeCases...)
  1483  	testCases = append(testCases, castInt8ToOthers...)
  1484  	testCases = append(testCases, castInt16ToOthers...)
  1485  	testCases = append(testCases, castInt32ToOthers...)
  1486  	testCases = append(testCases, castInt64ToOthers...)
  1487  	testCases = append(testCases, castUint8ToOthers...)
  1488  	testCases = append(testCases, castUint16ToOthers...)
  1489  	testCases = append(testCases, castUint32ToOthers...)
  1490  	testCases = append(testCases, castUint64ToOthers...)
  1491  	testCases = append(testCases, castFloat64ToOthers...)
  1492  	testCases = append(testCases, castFloat32ToOthers...)
  1493  	testCases = append(testCases, castStrToOthers...)
  1494  	testCases = append(testCases, castDecToOthers...)
  1495  	testCases = append(testCases, castTimestampToOthers...)
  1496  
  1497  	return testCases
  1498  }
  1499  
  1500  func TestCast(t *testing.T) {
  1501  	testCases := initCastTestCase()
  1502  
  1503  	// do the test work.
  1504  	proc := testutil.NewProcess()
  1505  	for _, tc := range testCases {
  1506  		fcTC := testutil.NewFunctionTestCase(proc,
  1507  			tc.inputs, tc.expect, NewCast)
  1508  		s, info := fcTC.Run()
  1509  		require.True(t, s, fmt.Sprintf("case is '%s', err info is '%s'", tc.info, info))
  1510  	}
  1511  }
  1512  
  1513  func BenchmarkCast(b *testing.B) {
  1514  	testCases := initCastTestCase()
  1515  	proc := testutil.NewProcess()
  1516  
  1517  	b.StartTimer()
  1518  	for _, tc := range testCases {
  1519  		fcTC := testutil.NewFunctionTestCase(proc,
  1520  			tc.inputs, tc.expect, NewCast)
  1521  		_ = fcTC.BenchMarkRun()
  1522  	}
  1523  	b.StopTimer()
  1524  }