github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/distsql_builtin.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package memex
    15  
    16  import (
    17  	"fmt"
    18  	"strconv"
    19  	"sync"
    20  	"time"
    21  
    22  	"github.com/whtcorpsinc/errors"
    23  	"github.com/whtcorpsinc/BerolinaSQL/perceptron"
    24  	"github.com/whtcorpsinc/BerolinaSQL/allegrosql"
    25  	"github.com/whtcorpsinc/milevadb/stochastikctx"
    26  	"github.com/whtcorpsinc/milevadb/stochastikctx/stmtctx"
    27  	"github.com/whtcorpsinc/milevadb/stochastikctx/variable"
    28  	"github.com/whtcorpsinc/milevadb/types"
    29  	"github.com/whtcorpsinc/milevadb/soliton/codec"
    30  	"github.com/whtcorpsinc/milevadb/soliton/mock"
    31  	"github.com/whtcorpsinc/fidelpb/go-fidelpb"
    32  )
    33  
    34  // PbTypeToFieldType converts fidelpb.FieldType to FieldType
    35  func PbTypeToFieldType(tp *fidelpb.FieldType) *types.FieldType {
    36  	return &types.FieldType{
    37  		Tp:      byte(tp.Tp),
    38  		Flag:    uint(tp.Flag),
    39  		Flen:    int(tp.Flen),
    40  		Decimal: int(tp.Decimal),
    41  		Charset: tp.Charset,
    42  		DefCauslate: protoToDefCauslation(tp.DefCauslate),
    43  	}
    44  }
    45  
    46  func getSignatureByPB(ctx stochastikctx.Context, sigCode fidelpb.ScalarFuncSig, tp *fidelpb.FieldType, args []Expression) (f builtinFunc, e error) {
    47  	fieldTp := PbTypeToFieldType(tp)
    48  	base, err := newBaseBuiltinFuncWithFieldType(ctx, fieldTp, args)
    49  	if err != nil {
    50  		return nil, err
    51  	}
    52  	valStr, _ := ctx.GetStochastikVars().GetSystemVar(variable.MaxAllowedPacket)
    53  	maxAllowedPacket, err := strconv.ParseUint(valStr, 10, 64)
    54  	if err != nil {
    55  		return nil, errors.Trace(err)
    56  	}
    57  	base.tp = fieldTp
    58  	switch sigCode {
    59  	case fidelpb.ScalarFuncSig_CastIntAsInt:
    60  		f = &builtinCastIntAsIntSig{newBaseBuiltinCastFunc(base, false)}
    61  	case fidelpb.ScalarFuncSig_CastIntAsReal:
    62  		f = &builtinCastIntAsRealSig{newBaseBuiltinCastFunc(base, false)}
    63  	case fidelpb.ScalarFuncSig_CastIntAsString:
    64  		f = &builtinCastIntAsStringSig{base}
    65  	case fidelpb.ScalarFuncSig_CastIntAsDecimal:
    66  		f = &builtinCastIntAsDecimalSig{newBaseBuiltinCastFunc(base, false)}
    67  	case fidelpb.ScalarFuncSig_CastIntAsTime:
    68  		f = &builtinCastIntAsTimeSig{base}
    69  	case fidelpb.ScalarFuncSig_CastIntAsDuration:
    70  		f = &builtinCastIntAsDurationSig{base}
    71  	case fidelpb.ScalarFuncSig_CastIntAsJson:
    72  		f = &builtinCastIntAsJSONSig{base}
    73  	case fidelpb.ScalarFuncSig_CastRealAsInt:
    74  		f = &builtinCastRealAsIntSig{newBaseBuiltinCastFunc(base, false)}
    75  	case fidelpb.ScalarFuncSig_CastRealAsReal:
    76  		f = &builtinCastRealAsRealSig{newBaseBuiltinCastFunc(base, false)}
    77  	case fidelpb.ScalarFuncSig_CastRealAsString:
    78  		f = &builtinCastRealAsStringSig{base}
    79  	case fidelpb.ScalarFuncSig_CastRealAsDecimal:
    80  		f = &builtinCastRealAsDecimalSig{newBaseBuiltinCastFunc(base, false)}
    81  	case fidelpb.ScalarFuncSig_CastRealAsTime:
    82  		f = &builtinCastRealAsTimeSig{base}
    83  	case fidelpb.ScalarFuncSig_CastRealAsDuration:
    84  		f = &builtinCastRealAsDurationSig{base}
    85  	case fidelpb.ScalarFuncSig_CastRealAsJson:
    86  		f = &builtinCastRealAsJSONSig{base}
    87  	case fidelpb.ScalarFuncSig_CastDecimalAsInt:
    88  		f = &builtinCastDecimalAsIntSig{newBaseBuiltinCastFunc(base, false)}
    89  	case fidelpb.ScalarFuncSig_CastDecimalAsReal:
    90  		f = &builtinCastDecimalAsRealSig{newBaseBuiltinCastFunc(base, false)}
    91  	case fidelpb.ScalarFuncSig_CastDecimalAsString:
    92  		f = &builtinCastDecimalAsStringSig{base}
    93  	case fidelpb.ScalarFuncSig_CastDecimalAsDecimal:
    94  		f = &builtinCastDecimalAsDecimalSig{newBaseBuiltinCastFunc(base, false)}
    95  	case fidelpb.ScalarFuncSig_CastDecimalAsTime:
    96  		f = &builtinCastDecimalAsTimeSig{base}
    97  	case fidelpb.ScalarFuncSig_CastDecimalAsDuration:
    98  		f = &builtinCastDecimalAsDurationSig{base}
    99  	case fidelpb.ScalarFuncSig_CastDecimalAsJson:
   100  		f = &builtinCastDecimalAsJSONSig{base}
   101  	case fidelpb.ScalarFuncSig_CastStringAsInt:
   102  		f = &builtinCastStringAsIntSig{newBaseBuiltinCastFunc(base, false)}
   103  	case fidelpb.ScalarFuncSig_CastStringAsReal:
   104  		f = &builtinCastStringAsRealSig{newBaseBuiltinCastFunc(base, false)}
   105  	case fidelpb.ScalarFuncSig_CastStringAsString:
   106  		f = &builtinCastStringAsStringSig{base}
   107  	case fidelpb.ScalarFuncSig_CastStringAsDecimal:
   108  		f = &builtinCastStringAsDecimalSig{newBaseBuiltinCastFunc(base, false)}
   109  	case fidelpb.ScalarFuncSig_CastStringAsTime:
   110  		f = &builtinCastStringAsTimeSig{base}
   111  	case fidelpb.ScalarFuncSig_CastStringAsDuration:
   112  		f = &builtinCastStringAsDurationSig{base}
   113  	case fidelpb.ScalarFuncSig_CastStringAsJson:
   114  		f = &builtinCastStringAsJSONSig{base}
   115  	case fidelpb.ScalarFuncSig_CastTimeAsInt:
   116  		f = &builtinCastTimeAsIntSig{newBaseBuiltinCastFunc(base, false)}
   117  	case fidelpb.ScalarFuncSig_CastTimeAsReal:
   118  		f = &builtinCastTimeAsRealSig{newBaseBuiltinCastFunc(base, false)}
   119  	case fidelpb.ScalarFuncSig_CastTimeAsString:
   120  		f = &builtinCastTimeAsStringSig{base}
   121  	case fidelpb.ScalarFuncSig_CastTimeAsDecimal:
   122  		f = &builtinCastTimeAsDecimalSig{newBaseBuiltinCastFunc(base, false)}
   123  	case fidelpb.ScalarFuncSig_CastTimeAsTime:
   124  		f = &builtinCastTimeAsTimeSig{base}
   125  	case fidelpb.ScalarFuncSig_CastTimeAsDuration:
   126  		f = &builtinCastTimeAsDurationSig{base}
   127  	case fidelpb.ScalarFuncSig_CastTimeAsJson:
   128  		f = &builtinCastTimeAsJSONSig{base}
   129  	case fidelpb.ScalarFuncSig_CastDurationAsInt:
   130  		f = &builtinCastDurationAsIntSig{newBaseBuiltinCastFunc(base, false)}
   131  	case fidelpb.ScalarFuncSig_CastDurationAsReal:
   132  		f = &builtinCastDurationAsRealSig{newBaseBuiltinCastFunc(base, false)}
   133  	case fidelpb.ScalarFuncSig_CastDurationAsString:
   134  		f = &builtinCastDurationAsStringSig{base}
   135  	case fidelpb.ScalarFuncSig_CastDurationAsDecimal:
   136  		f = &builtinCastDurationAsDecimalSig{newBaseBuiltinCastFunc(base, false)}
   137  	case fidelpb.ScalarFuncSig_CastDurationAsTime:
   138  		f = &builtinCastDurationAsTimeSig{base}
   139  	case fidelpb.ScalarFuncSig_CastDurationAsDuration:
   140  		f = &builtinCastDurationAsDurationSig{base}
   141  	case fidelpb.ScalarFuncSig_CastDurationAsJson:
   142  		f = &builtinCastDurationAsJSONSig{base}
   143  	case fidelpb.ScalarFuncSig_CastJsonAsInt:
   144  		f = &builtinCastJSONAsIntSig{newBaseBuiltinCastFunc(base, false)}
   145  	case fidelpb.ScalarFuncSig_CastJsonAsReal:
   146  		f = &builtinCastJSONAsRealSig{newBaseBuiltinCastFunc(base, false)}
   147  	case fidelpb.ScalarFuncSig_CastJsonAsString:
   148  		f = &builtinCastJSONAsStringSig{base}
   149  	case fidelpb.ScalarFuncSig_CastJsonAsDecimal:
   150  		f = &builtinCastJSONAsDecimalSig{newBaseBuiltinCastFunc(base, false)}
   151  	case fidelpb.ScalarFuncSig_CastJsonAsTime:
   152  		f = &builtinCastJSONAsTimeSig{base}
   153  	case fidelpb.ScalarFuncSig_CastJsonAsDuration:
   154  		f = &builtinCastJSONAsDurationSig{base}
   155  	case fidelpb.ScalarFuncSig_CastJsonAsJson:
   156  		f = &builtinCastJSONAsJSONSig{base}
   157  	case fidelpb.ScalarFuncSig_CoalesceInt:
   158  		f = &builtinCoalesceIntSig{base}
   159  	case fidelpb.ScalarFuncSig_CoalesceReal:
   160  		f = &builtinCoalesceRealSig{base}
   161  	case fidelpb.ScalarFuncSig_CoalesceDecimal:
   162  		f = &builtinCoalesceDecimalSig{base}
   163  	case fidelpb.ScalarFuncSig_CoalesceString:
   164  		f = &builtinCoalesceStringSig{base}
   165  	case fidelpb.ScalarFuncSig_CoalesceTime:
   166  		f = &builtinCoalesceTimeSig{base}
   167  	case fidelpb.ScalarFuncSig_CoalesceDuration:
   168  		f = &builtinCoalesceDurationSig{base}
   169  	case fidelpb.ScalarFuncSig_CoalesceJson:
   170  		f = &builtinCoalesceJSONSig{base}
   171  	case fidelpb.ScalarFuncSig_LTInt:
   172  		f = &builtinLTIntSig{base}
   173  	case fidelpb.ScalarFuncSig_LTReal:
   174  		f = &builtinLTRealSig{base}
   175  	case fidelpb.ScalarFuncSig_LTDecimal:
   176  		f = &builtinLTDecimalSig{base}
   177  	case fidelpb.ScalarFuncSig_LTString:
   178  		f = &builtinLTStringSig{base}
   179  	case fidelpb.ScalarFuncSig_LTTime:
   180  		f = &builtinLTTimeSig{base}
   181  	case fidelpb.ScalarFuncSig_LTDuration:
   182  		f = &builtinLTDurationSig{base}
   183  	case fidelpb.ScalarFuncSig_LTJson:
   184  		f = &builtinLTJSONSig{base}
   185  	case fidelpb.ScalarFuncSig_LEInt:
   186  		f = &builtinLEIntSig{base}
   187  	case fidelpb.ScalarFuncSig_LEReal:
   188  		f = &builtinLERealSig{base}
   189  	case fidelpb.ScalarFuncSig_LEDecimal:
   190  		f = &builtinLEDecimalSig{base}
   191  	case fidelpb.ScalarFuncSig_LEString:
   192  		f = &builtinLEStringSig{base}
   193  	case fidelpb.ScalarFuncSig_LETime:
   194  		f = &builtinLETimeSig{base}
   195  	case fidelpb.ScalarFuncSig_LEDuration:
   196  		f = &builtinLEDurationSig{base}
   197  	case fidelpb.ScalarFuncSig_LEJson:
   198  		f = &builtinLEJSONSig{base}
   199  	case fidelpb.ScalarFuncSig_GTInt:
   200  		f = &builtinGTIntSig{base}
   201  	case fidelpb.ScalarFuncSig_GTReal:
   202  		f = &builtinGTRealSig{base}
   203  	case fidelpb.ScalarFuncSig_GTDecimal:
   204  		f = &builtinGTDecimalSig{base}
   205  	case fidelpb.ScalarFuncSig_GTString:
   206  		f = &builtinGTStringSig{base}
   207  	case fidelpb.ScalarFuncSig_GTTime:
   208  		f = &builtinGTTimeSig{base}
   209  	case fidelpb.ScalarFuncSig_GTDuration:
   210  		f = &builtinGTDurationSig{base}
   211  	case fidelpb.ScalarFuncSig_GTJson:
   212  		f = &builtinGTJSONSig{base}
   213  	case fidelpb.ScalarFuncSig_GreatestInt:
   214  		f = &builtinGreatestIntSig{base}
   215  	case fidelpb.ScalarFuncSig_GreatestReal:
   216  		f = &builtinGreatestRealSig{base}
   217  	case fidelpb.ScalarFuncSig_GreatestDecimal:
   218  		f = &builtinGreatestDecimalSig{base}
   219  	case fidelpb.ScalarFuncSig_GreatestString:
   220  		f = &builtinGreatestStringSig{base}
   221  	case fidelpb.ScalarFuncSig_GreatestTime:
   222  		f = &builtinGreatestTimeSig{base}
   223  	case fidelpb.ScalarFuncSig_LeastInt:
   224  		f = &builtinLeastIntSig{base}
   225  	case fidelpb.ScalarFuncSig_LeastReal:
   226  		f = &builtinLeastRealSig{base}
   227  	case fidelpb.ScalarFuncSig_LeastDecimal:
   228  		f = &builtinLeastDecimalSig{base}
   229  	case fidelpb.ScalarFuncSig_LeastString:
   230  		f = &builtinLeastStringSig{base}
   231  	case fidelpb.ScalarFuncSig_LeastTime:
   232  		f = &builtinLeastTimeSig{base}
   233  	case fidelpb.ScalarFuncSig_IntervalInt:
   234  		f = &builtinIntervalIntSig{base, false} // Since interval function won't be pushed down to EinsteinDB, therefore it doesn't matter what value we give to hasNullable
   235  	case fidelpb.ScalarFuncSig_IntervalReal:
   236  		f = &builtinIntervalRealSig{base, false}
   237  	case fidelpb.ScalarFuncSig_GEInt:
   238  		f = &builtinGEIntSig{base}
   239  	case fidelpb.ScalarFuncSig_GEReal:
   240  		f = &builtinGERealSig{base}
   241  	case fidelpb.ScalarFuncSig_GEDecimal:
   242  		f = &builtinGEDecimalSig{base}
   243  	case fidelpb.ScalarFuncSig_GEString:
   244  		f = &builtinGEStringSig{base}
   245  	case fidelpb.ScalarFuncSig_GETime:
   246  		f = &builtinGETimeSig{base}
   247  	case fidelpb.ScalarFuncSig_GEDuration:
   248  		f = &builtinGEDurationSig{base}
   249  	case fidelpb.ScalarFuncSig_GEJson:
   250  		f = &builtinGEJSONSig{base}
   251  	case fidelpb.ScalarFuncSig_EQInt:
   252  		f = &builtinEQIntSig{base}
   253  	case fidelpb.ScalarFuncSig_EQReal:
   254  		f = &builtinEQRealSig{base}
   255  	case fidelpb.ScalarFuncSig_EQDecimal:
   256  		f = &builtinEQDecimalSig{base}
   257  	case fidelpb.ScalarFuncSig_EQString:
   258  		f = &builtinEQStringSig{base}
   259  	case fidelpb.ScalarFuncSig_EQTime:
   260  		f = &builtinEQTimeSig{base}
   261  	case fidelpb.ScalarFuncSig_EQDuration:
   262  		f = &builtinEQDurationSig{base}
   263  	case fidelpb.ScalarFuncSig_EQJson:
   264  		f = &builtinEQJSONSig{base}
   265  	case fidelpb.ScalarFuncSig_NEInt:
   266  		f = &builtinNEIntSig{base}
   267  	case fidelpb.ScalarFuncSig_NEReal:
   268  		f = &builtinNERealSig{base}
   269  	case fidelpb.ScalarFuncSig_NEDecimal:
   270  		f = &builtinNEDecimalSig{base}
   271  	case fidelpb.ScalarFuncSig_NEString:
   272  		f = &builtinNEStringSig{base}
   273  	case fidelpb.ScalarFuncSig_NETime:
   274  		f = &builtinNETimeSig{base}
   275  	case fidelpb.ScalarFuncSig_NEDuration:
   276  		f = &builtinNEDurationSig{base}
   277  	case fidelpb.ScalarFuncSig_NEJson:
   278  		f = &builtinNEJSONSig{base}
   279  	case fidelpb.ScalarFuncSig_NullEQInt:
   280  		f = &builtinNullEQIntSig{base}
   281  	case fidelpb.ScalarFuncSig_NullEQReal:
   282  		f = &builtinNullEQRealSig{base}
   283  	case fidelpb.ScalarFuncSig_NullEQDecimal:
   284  		f = &builtinNullEQDecimalSig{base}
   285  	case fidelpb.ScalarFuncSig_NullEQString:
   286  		f = &builtinNullEQStringSig{base}
   287  	case fidelpb.ScalarFuncSig_NullEQTime:
   288  		f = &builtinNullEQTimeSig{base}
   289  	case fidelpb.ScalarFuncSig_NullEQDuration:
   290  		f = &builtinNullEQDurationSig{base}
   291  	case fidelpb.ScalarFuncSig_NullEQJson:
   292  		f = &builtinNullEQJSONSig{base}
   293  	case fidelpb.ScalarFuncSig_PlusReal:
   294  		f = &builtinArithmeticPlusRealSig{base}
   295  	case fidelpb.ScalarFuncSig_PlusDecimal:
   296  		f = &builtinArithmeticPlusDecimalSig{base}
   297  	case fidelpb.ScalarFuncSig_PlusInt:
   298  		f = &builtinArithmeticPlusIntSig{base}
   299  	case fidelpb.ScalarFuncSig_MinusReal:
   300  		f = &builtinArithmeticMinusRealSig{base}
   301  	case fidelpb.ScalarFuncSig_MinusDecimal:
   302  		f = &builtinArithmeticMinusDecimalSig{base}
   303  	case fidelpb.ScalarFuncSig_MinusInt:
   304  		f = &builtinArithmeticMinusIntSig{base}
   305  	case fidelpb.ScalarFuncSig_MultiplyReal:
   306  		f = &builtinArithmeticMultiplyRealSig{base}
   307  	case fidelpb.ScalarFuncSig_MultiplyDecimal:
   308  		f = &builtinArithmeticMultiplyDecimalSig{base}
   309  	case fidelpb.ScalarFuncSig_MultiplyInt:
   310  		f = &builtinArithmeticMultiplyIntSig{base}
   311  	case fidelpb.ScalarFuncSig_DivideReal:
   312  		f = &builtinArithmeticDivideRealSig{base}
   313  	case fidelpb.ScalarFuncSig_DivideDecimal:
   314  		f = &builtinArithmeticDivideDecimalSig{base}
   315  	case fidelpb.ScalarFuncSig_IntDivideInt:
   316  		f = &builtinArithmeticIntDivideIntSig{base}
   317  	case fidelpb.ScalarFuncSig_IntDivideDecimal:
   318  		f = &builtinArithmeticIntDivideDecimalSig{base}
   319  	case fidelpb.ScalarFuncSig_ModReal:
   320  		f = &builtinArithmeticModRealSig{base}
   321  	case fidelpb.ScalarFuncSig_ModDecimal:
   322  		f = &builtinArithmeticModDecimalSig{base}
   323  	case fidelpb.ScalarFuncSig_ModInt:
   324  		f = &builtinArithmeticModIntSig{base}
   325  	case fidelpb.ScalarFuncSig_MultiplyIntUnsigned:
   326  		f = &builtinArithmeticMultiplyIntUnsignedSig{base}
   327  	case fidelpb.ScalarFuncSig_AbsInt:
   328  		f = &builtinAbsIntSig{base}
   329  	case fidelpb.ScalarFuncSig_AbsUInt:
   330  		f = &builtinAbsUIntSig{base}
   331  	case fidelpb.ScalarFuncSig_AbsReal:
   332  		f = &builtinAbsRealSig{base}
   333  	case fidelpb.ScalarFuncSig_AbsDecimal:
   334  		f = &builtinAbsDecSig{base}
   335  	case fidelpb.ScalarFuncSig_CeilIntToDec:
   336  		f = &builtinCeilIntToDecSig{base}
   337  	case fidelpb.ScalarFuncSig_CeilIntToInt:
   338  		f = &builtinCeilIntToIntSig{base}
   339  	case fidelpb.ScalarFuncSig_CeilDecToInt:
   340  		f = &builtinCeilDecToIntSig{base}
   341  	case fidelpb.ScalarFuncSig_CeilDecToDec:
   342  		f = &builtinCeilDecToDecSig{base}
   343  	case fidelpb.ScalarFuncSig_CeilReal:
   344  		f = &builtinCeilRealSig{base}
   345  	case fidelpb.ScalarFuncSig_FloorIntToDec:
   346  		f = &builtinFloorIntToDecSig{base}
   347  	case fidelpb.ScalarFuncSig_FloorIntToInt:
   348  		f = &builtinFloorIntToIntSig{base}
   349  	case fidelpb.ScalarFuncSig_FloorDecToInt:
   350  		f = &builtinFloorDecToIntSig{base}
   351  	case fidelpb.ScalarFuncSig_FloorDecToDec:
   352  		f = &builtinFloorDecToDecSig{base}
   353  	case fidelpb.ScalarFuncSig_FloorReal:
   354  		f = &builtinFloorRealSig{base}
   355  	case fidelpb.ScalarFuncSig_RoundReal:
   356  		f = &builtinRoundRealSig{base}
   357  	case fidelpb.ScalarFuncSig_RoundInt:
   358  		f = &builtinRoundIntSig{base}
   359  	case fidelpb.ScalarFuncSig_RoundDec:
   360  		f = &builtinRoundDecSig{base}
   361  	case fidelpb.ScalarFuncSig_RoundWithFracReal:
   362  		f = &builtinRoundWithFracRealSig{base}
   363  	case fidelpb.ScalarFuncSig_RoundWithFracInt:
   364  		f = &builtinRoundWithFracIntSig{base}
   365  	case fidelpb.ScalarFuncSig_RoundWithFracDec:
   366  		f = &builtinRoundWithFracDecSig{base}
   367  	case fidelpb.ScalarFuncSig_Log1Arg:
   368  		f = &builtinLog1ArgSig{base}
   369  	case fidelpb.ScalarFuncSig_Log2Args:
   370  		f = &builtinLog2ArgsSig{base}
   371  	case fidelpb.ScalarFuncSig_Log2:
   372  		f = &builtinLog2Sig{base}
   373  	case fidelpb.ScalarFuncSig_Log10:
   374  		f = &builtinLog10Sig{base}
   375  	//case fidelpb.ScalarFuncSig_Rand:
   376  	case fidelpb.ScalarFuncSig_RandWithSeedFirstGen:
   377  		f = &builtinRandWithSeedFirstGenSig{base}
   378  	case fidelpb.ScalarFuncSig_Pow:
   379  		f = &builtinPowSig{base}
   380  	case fidelpb.ScalarFuncSig_Conv:
   381  		f = &builtinConvSig{base}
   382  	case fidelpb.ScalarFuncSig_CRC32:
   383  		f = &builtinCRC32Sig{base}
   384  	case fidelpb.ScalarFuncSig_Sign:
   385  		f = &builtinSignSig{base}
   386  	case fidelpb.ScalarFuncSig_Sqrt:
   387  		f = &builtinSqrtSig{base}
   388  	case fidelpb.ScalarFuncSig_Acos:
   389  		f = &builtinAcosSig{base}
   390  	case fidelpb.ScalarFuncSig_Asin:
   391  		f = &builtinAsinSig{base}
   392  	case fidelpb.ScalarFuncSig_Atan1Arg:
   393  		f = &builtinAtan1ArgSig{base}
   394  	case fidelpb.ScalarFuncSig_Atan2Args:
   395  		f = &builtinAtan2ArgsSig{base}
   396  	case fidelpb.ScalarFuncSig_Cos:
   397  		f = &builtinCosSig{base}
   398  	case fidelpb.ScalarFuncSig_Cot:
   399  		f = &builtinCotSig{base}
   400  	case fidelpb.ScalarFuncSig_Degrees:
   401  		f = &builtinDegreesSig{base}
   402  	case fidelpb.ScalarFuncSig_Exp:
   403  		f = &builtinExpSig{base}
   404  	case fidelpb.ScalarFuncSig_PI:
   405  		f = &builtinPISig{base}
   406  	case fidelpb.ScalarFuncSig_Radians:
   407  		f = &builtinRadiansSig{base}
   408  	case fidelpb.ScalarFuncSig_Sin:
   409  		f = &builtinSinSig{base}
   410  	case fidelpb.ScalarFuncSig_Tan:
   411  		f = &builtinTanSig{base}
   412  	case fidelpb.ScalarFuncSig_TruncateInt:
   413  		f = &builtinTruncateIntSig{base}
   414  	case fidelpb.ScalarFuncSig_TruncateReal:
   415  		f = &builtinTruncateRealSig{base}
   416  	case fidelpb.ScalarFuncSig_TruncateDecimal:
   417  		f = &builtinTruncateDecimalSig{base}
   418  	case fidelpb.ScalarFuncSig_LogicalAnd:
   419  		f = &builtinLogicAndSig{base}
   420  	case fidelpb.ScalarFuncSig_LogicalOr:
   421  		f = &builtinLogicOrSig{base}
   422  	case fidelpb.ScalarFuncSig_LogicalXor:
   423  		f = &builtinLogicXorSig{base}
   424  	case fidelpb.ScalarFuncSig_UnaryNotInt:
   425  		f = &builtinUnaryNotIntSig{base}
   426  	case fidelpb.ScalarFuncSig_UnaryNotDecimal:
   427  		f = &builtinUnaryNotDecimalSig{base}
   428  	case fidelpb.ScalarFuncSig_UnaryNotReal:
   429  		f = &builtinUnaryNotRealSig{base}
   430  	case fidelpb.ScalarFuncSig_UnaryMinusInt:
   431  		f = &builtinUnaryMinusIntSig{base}
   432  	case fidelpb.ScalarFuncSig_UnaryMinusReal:
   433  		f = &builtinUnaryMinusRealSig{base}
   434  	case fidelpb.ScalarFuncSig_UnaryMinusDecimal:
   435  		f = &builtinUnaryMinusDecimalSig{base, false}
   436  	case fidelpb.ScalarFuncSig_DecimalIsNull:
   437  		f = &builtinDecimalIsNullSig{base}
   438  	case fidelpb.ScalarFuncSig_DurationIsNull:
   439  		f = &builtinDurationIsNullSig{base}
   440  	case fidelpb.ScalarFuncSig_RealIsNull:
   441  		f = &builtinRealIsNullSig{base}
   442  	case fidelpb.ScalarFuncSig_StringIsNull:
   443  		f = &builtinStringIsNullSig{base}
   444  	case fidelpb.ScalarFuncSig_TimeIsNull:
   445  		f = &builtinTimeIsNullSig{base}
   446  	case fidelpb.ScalarFuncSig_IntIsNull:
   447  		f = &builtinIntIsNullSig{base}
   448  	//case fidelpb.ScalarFuncSig_JsonIsNull:
   449  	case fidelpb.ScalarFuncSig_BitAndSig:
   450  		f = &builtinBitAndSig{base}
   451  	case fidelpb.ScalarFuncSig_BitOrSig:
   452  		f = &builtinBitOrSig{base}
   453  	case fidelpb.ScalarFuncSig_BitXorSig:
   454  		f = &builtinBitXorSig{base}
   455  	case fidelpb.ScalarFuncSig_BitNegSig:
   456  		f = &builtinBitNegSig{base}
   457  	case fidelpb.ScalarFuncSig_IntIsTrue:
   458  		f = &builtinIntIsTrueSig{base, false}
   459  	case fidelpb.ScalarFuncSig_RealIsTrue:
   460  		f = &builtinRealIsTrueSig{base, false}
   461  	case fidelpb.ScalarFuncSig_DecimalIsTrue:
   462  		f = &builtinDecimalIsTrueSig{base, false}
   463  	case fidelpb.ScalarFuncSig_IntIsFalse:
   464  		f = &builtinIntIsFalseSig{base, false}
   465  	case fidelpb.ScalarFuncSig_RealIsFalse:
   466  		f = &builtinRealIsFalseSig{base, false}
   467  	case fidelpb.ScalarFuncSig_DecimalIsFalse:
   468  		f = &builtinDecimalIsFalseSig{base, false}
   469  	case fidelpb.ScalarFuncSig_IntIsTrueWithNull:
   470  		f = &builtinIntIsTrueSig{base, true}
   471  	case fidelpb.ScalarFuncSig_RealIsTrueWithNull:
   472  		f = &builtinRealIsTrueSig{base, true}
   473  	case fidelpb.ScalarFuncSig_DecimalIsTrueWithNull:
   474  		f = &builtinDecimalIsTrueSig{base, true}
   475  	case fidelpb.ScalarFuncSig_IntIsFalseWithNull:
   476  		f = &builtinIntIsFalseSig{base, true}
   477  	case fidelpb.ScalarFuncSig_RealIsFalseWithNull:
   478  		f = &builtinRealIsFalseSig{base, true}
   479  	case fidelpb.ScalarFuncSig_DecimalIsFalseWithNull:
   480  		f = &builtinDecimalIsFalseSig{base, true}
   481  	case fidelpb.ScalarFuncSig_LeftShift:
   482  		f = &builtinLeftShiftSig{base}
   483  	case fidelpb.ScalarFuncSig_RightShift:
   484  		f = &builtinRightShiftSig{base}
   485  	case fidelpb.ScalarFuncSig_BitCount:
   486  		f = &builtinBitCountSig{base}
   487  	case fidelpb.ScalarFuncSig_GetParamString:
   488  		f = &builtinGetParamStringSig{base}
   489  	case fidelpb.ScalarFuncSig_GetVar:
   490  		f = &builtinGetVarSig{base}
   491  	//case fidelpb.ScalarFuncSig_EventSig:
   492  	case fidelpb.ScalarFuncSig_SetVar:
   493  		f = &builtinSetVarSig{base}
   494  	//case fidelpb.ScalarFuncSig_ValuesDecimal:
   495  	//	f = &builtinValuesDecimalSig{base}
   496  	//case fidelpb.ScalarFuncSig_ValuesDuration:
   497  	//	f = &builtinValuesDurationSig{base}
   498  	//case fidelpb.ScalarFuncSig_ValuesInt:
   499  	//	f = &builtinValuesIntSig{base}
   500  	//case fidelpb.ScalarFuncSig_ValuesJSON:
   501  	//	f = &builtinValuesJSONSig{base}
   502  	//case fidelpb.ScalarFuncSig_ValuesReal:
   503  	//	f = &builtinValuesRealSig{base}
   504  	//case fidelpb.ScalarFuncSig_ValuesString:
   505  	//	f = &builtinValuesStringSig{base}
   506  	//case fidelpb.ScalarFuncSig_ValuesTime:
   507  	//	f = &builtinValuesTimeSig{base}
   508  	case fidelpb.ScalarFuncSig_InInt:
   509  		f = &builtinInIntSig{baseInSig: baseInSig{baseBuiltinFunc: base}}
   510  	case fidelpb.ScalarFuncSig_InReal:
   511  		f = &builtinInRealSig{baseInSig: baseInSig{baseBuiltinFunc: base}}
   512  	case fidelpb.ScalarFuncSig_InDecimal:
   513  		f = &builtinInDecimalSig{baseInSig: baseInSig{baseBuiltinFunc: base}}
   514  	case fidelpb.ScalarFuncSig_InString:
   515  		f = &builtinInStringSig{baseInSig: baseInSig{baseBuiltinFunc: base}}
   516  	case fidelpb.ScalarFuncSig_InTime:
   517  		f = &builtinInTimeSig{baseInSig: baseInSig{baseBuiltinFunc: base}}
   518  	case fidelpb.ScalarFuncSig_InDuration:
   519  		f = &builtinInDurationSig{baseInSig: baseInSig{baseBuiltinFunc: base}}
   520  	case fidelpb.ScalarFuncSig_InJson:
   521  		f = &builtinInJSONSig{baseBuiltinFunc: base}
   522  	case fidelpb.ScalarFuncSig_IfNullInt:
   523  		f = &builtinIfNullIntSig{base}
   524  	case fidelpb.ScalarFuncSig_IfNullReal:
   525  		f = &builtinIfNullRealSig{base}
   526  	case fidelpb.ScalarFuncSig_IfNullDecimal:
   527  		f = &builtinIfNullDecimalSig{base}
   528  	case fidelpb.ScalarFuncSig_IfNullString:
   529  		f = &builtinIfNullStringSig{base}
   530  	case fidelpb.ScalarFuncSig_IfNullTime:
   531  		f = &builtinIfNullTimeSig{base}
   532  	case fidelpb.ScalarFuncSig_IfNullDuration:
   533  		f = &builtinIfNullDurationSig{base}
   534  	case fidelpb.ScalarFuncSig_IfInt:
   535  		f = &builtinIfIntSig{base}
   536  	case fidelpb.ScalarFuncSig_IfReal:
   537  		f = &builtinIfRealSig{base}
   538  	case fidelpb.ScalarFuncSig_IfDecimal:
   539  		f = &builtinIfDecimalSig{base}
   540  	case fidelpb.ScalarFuncSig_IfString:
   541  		f = &builtinIfStringSig{base}
   542  	case fidelpb.ScalarFuncSig_IfTime:
   543  		f = &builtinIfTimeSig{base}
   544  	case fidelpb.ScalarFuncSig_IfDuration:
   545  		f = &builtinIfDurationSig{base}
   546  	case fidelpb.ScalarFuncSig_IfNullJson:
   547  		f = &builtinIfNullJSONSig{base}
   548  	case fidelpb.ScalarFuncSig_IfJson:
   549  		f = &builtinIfJSONSig{base}
   550  	case fidelpb.ScalarFuncSig_CaseWhenInt:
   551  		f = &builtinCaseWhenIntSig{base}
   552  	case fidelpb.ScalarFuncSig_CaseWhenReal:
   553  		f = &builtinCaseWhenRealSig{base}
   554  	case fidelpb.ScalarFuncSig_CaseWhenDecimal:
   555  		f = &builtinCaseWhenDecimalSig{base}
   556  	case fidelpb.ScalarFuncSig_CaseWhenString:
   557  		f = &builtinCaseWhenStringSig{base}
   558  	case fidelpb.ScalarFuncSig_CaseWhenTime:
   559  		f = &builtinCaseWhenTimeSig{base}
   560  	case fidelpb.ScalarFuncSig_CaseWhenDuration:
   561  		f = &builtinCaseWhenDurationSig{base}
   562  	case fidelpb.ScalarFuncSig_CaseWhenJson:
   563  		f = &builtinCaseWhenJSONSig{base}
   564  	//case fidelpb.ScalarFuncSig_AesDecrypt:
   565  	//	f = &builtinAesDecryptSig{base}
   566  	//case fidelpb.ScalarFuncSig_AesEncrypt:
   567  	//	f = &builtinAesEncryptSig{base}
   568  	case fidelpb.ScalarFuncSig_Compress:
   569  		f = &builtinCompressSig{base}
   570  	case fidelpb.ScalarFuncSig_MD5:
   571  		f = &builtinMD5Sig{base}
   572  	case fidelpb.ScalarFuncSig_Password:
   573  		f = &builtinPasswordSig{base}
   574  	case fidelpb.ScalarFuncSig_RandomBytes:
   575  		f = &builtinRandomBytesSig{base}
   576  	case fidelpb.ScalarFuncSig_SHA1:
   577  		f = &builtinSHA1Sig{base}
   578  	case fidelpb.ScalarFuncSig_SHA2:
   579  		f = &builtinSHA2Sig{base}
   580  	case fidelpb.ScalarFuncSig_Uncompress:
   581  		f = &builtinUncompressSig{base}
   582  	case fidelpb.ScalarFuncSig_UncompressedLength:
   583  		f = &builtinUncompressedLengthSig{base}
   584  	case fidelpb.ScalarFuncSig_Database:
   585  		f = &builtinDatabaseSig{base}
   586  	case fidelpb.ScalarFuncSig_FoundEvents:
   587  		f = &builtinFoundEventsSig{base}
   588  	case fidelpb.ScalarFuncSig_CurrentUser:
   589  		f = &builtinCurrentUserSig{base}
   590  	case fidelpb.ScalarFuncSig_User:
   591  		f = &builtinUserSig{base}
   592  	case fidelpb.ScalarFuncSig_ConnectionID:
   593  		f = &builtinConnectionIDSig{base}
   594  	case fidelpb.ScalarFuncSig_LastInsertID:
   595  		f = &builtinLastInsertIDSig{base}
   596  	case fidelpb.ScalarFuncSig_LastInsertIDWithID:
   597  		f = &builtinLastInsertIDWithIDSig{base}
   598  	case fidelpb.ScalarFuncSig_Version:
   599  		f = &builtinVersionSig{base}
   600  	case fidelpb.ScalarFuncSig_MilevaDBVersion:
   601  		f = &builtinMilevaDBVersionSig{base}
   602  	case fidelpb.ScalarFuncSig_EventCount:
   603  		f = &builtinEventCountSig{base}
   604  	case fidelpb.ScalarFuncSig_Sleep:
   605  		f = &builtinSleepSig{base}
   606  	case fidelpb.ScalarFuncSig_Lock:
   607  		f = &builtinLockSig{base}
   608  	case fidelpb.ScalarFuncSig_ReleaseLock:
   609  		f = &builtinReleaseLockSig{base}
   610  	case fidelpb.ScalarFuncSig_DecimalAnyValue:
   611  		f = &builtinDecimalAnyValueSig{base}
   612  	case fidelpb.ScalarFuncSig_DurationAnyValue:
   613  		f = &builtinDurationAnyValueSig{base}
   614  	case fidelpb.ScalarFuncSig_IntAnyValue:
   615  		f = &builtinIntAnyValueSig{base}
   616  	case fidelpb.ScalarFuncSig_JSONAnyValue:
   617  		f = &builtinJSONAnyValueSig{base}
   618  	case fidelpb.ScalarFuncSig_RealAnyValue:
   619  		f = &builtinRealAnyValueSig{base}
   620  	case fidelpb.ScalarFuncSig_StringAnyValue:
   621  		f = &builtinStringAnyValueSig{base}
   622  	case fidelpb.ScalarFuncSig_TimeAnyValue:
   623  		f = &builtinTimeAnyValueSig{base}
   624  	case fidelpb.ScalarFuncSig_InetAton:
   625  		f = &builtinInetAtonSig{base}
   626  	case fidelpb.ScalarFuncSig_InetNtoa:
   627  		f = &builtinInetNtoaSig{base}
   628  	case fidelpb.ScalarFuncSig_Inet6Aton:
   629  		f = &builtinInet6AtonSig{base}
   630  	case fidelpb.ScalarFuncSig_Inet6Ntoa:
   631  		f = &builtinInet6NtoaSig{base}
   632  	case fidelpb.ScalarFuncSig_IsIPv4:
   633  		f = &builtinIsIPv4Sig{base}
   634  	case fidelpb.ScalarFuncSig_IsIPv4Compat:
   635  		f = &builtinIsIPv4CompatSig{base}
   636  	case fidelpb.ScalarFuncSig_IsIPv4Mapped:
   637  		f = &builtinIsIPv4MappedSig{base}
   638  	case fidelpb.ScalarFuncSig_IsIPv6:
   639  		f = &builtinIsIPv6Sig{base}
   640  	case fidelpb.ScalarFuncSig_UUID:
   641  		f = &builtinUUIDSig{base}
   642  	case fidelpb.ScalarFuncSig_LikeSig:
   643  		f = &builtinLikeSig{base, nil, false, sync.Once{}}
   644  	//case fidelpb.ScalarFuncSig_RegexpSig:
   645  	//	f = &builtinRegexpSig{base}
   646  	//case fidelpb.ScalarFuncSig_RegexpUTF8Sig:
   647  	//	f = &builtinRegexpUTF8Sig{base}
   648  	case fidelpb.ScalarFuncSig_JsonExtractSig:
   649  		f = &builtinJSONExtractSig{base}
   650  	case fidelpb.ScalarFuncSig_JsonUnquoteSig:
   651  		f = &builtinJSONUnquoteSig{base}
   652  	case fidelpb.ScalarFuncSig_JsonTypeSig:
   653  		f = &builtinJSONTypeSig{base}
   654  	case fidelpb.ScalarFuncSig_JsonSetSig:
   655  		f = &builtinJSONSetSig{base}
   656  	case fidelpb.ScalarFuncSig_JsonInsertSig:
   657  		f = &builtinJSONInsertSig{base}
   658  	case fidelpb.ScalarFuncSig_JsonReplaceSig:
   659  		f = &builtinJSONReplaceSig{base}
   660  	case fidelpb.ScalarFuncSig_JsonRemoveSig:
   661  		f = &builtinJSONRemoveSig{base}
   662  	case fidelpb.ScalarFuncSig_JsonMergeSig:
   663  		f = &builtinJSONMergeSig{base}
   664  	case fidelpb.ScalarFuncSig_JsonObjectSig:
   665  		f = &builtinJSONObjectSig{base}
   666  	case fidelpb.ScalarFuncSig_JsonArraySig:
   667  		f = &builtinJSONArraySig{base}
   668  	case fidelpb.ScalarFuncSig_JsonValidJsonSig:
   669  		f = &builtinJSONValidJSONSig{base}
   670  	case fidelpb.ScalarFuncSig_JsonContainsSig:
   671  		f = &builtinJSONContainsSig{base}
   672  	case fidelpb.ScalarFuncSig_JsonArrayAppendSig:
   673  		f = &builtinJSONArrayAppendSig{base}
   674  	case fidelpb.ScalarFuncSig_JsonArrayInsertSig:
   675  		f = &builtinJSONArrayInsertSig{base}
   676  	//case fidelpb.ScalarFuncSig_JsonMergePatchSig:
   677  	case fidelpb.ScalarFuncSig_JsonMergePreserveSig:
   678  		f = &builtinJSONMergeSig{base}
   679  	case fidelpb.ScalarFuncSig_JsonContainsPathSig:
   680  		f = &builtinJSONContainsPathSig{base}
   681  	//case fidelpb.ScalarFuncSig_JsonPrettySig:
   682  	case fidelpb.ScalarFuncSig_JsonQuoteSig:
   683  		f = &builtinJSONQuoteSig{base}
   684  	case fidelpb.ScalarFuncSig_JsonSearchSig:
   685  		f = &builtinJSONSearchSig{base}
   686  	case fidelpb.ScalarFuncSig_JsonStorageSizeSig:
   687  		f = &builtinJSONStorageSizeSig{base}
   688  	case fidelpb.ScalarFuncSig_JsonDepthSig:
   689  		f = &builtinJSONDepthSig{base}
   690  	case fidelpb.ScalarFuncSig_JsonKeysSig:
   691  		f = &builtinJSONKeysSig{base}
   692  	case fidelpb.ScalarFuncSig_JsonLengthSig:
   693  		f = &builtinJSONLengthSig{base}
   694  	case fidelpb.ScalarFuncSig_JsonKeys2ArgsSig:
   695  		f = &builtinJSONKeys2ArgsSig{base}
   696  	case fidelpb.ScalarFuncSig_JsonValidStringSig:
   697  		f = &builtinJSONValidStringSig{base}
   698  	case fidelpb.ScalarFuncSig_JsonValidOthersSig:
   699  		f = &builtinJSONValidOthersSig{base}
   700  	case fidelpb.ScalarFuncSig_DateFormatSig:
   701  		f = &builtinDateFormatSig{base}
   702  	//case fidelpb.ScalarFuncSig_DateLiteral:
   703  	//	f = &builtinDateLiteralSig{base}
   704  	case fidelpb.ScalarFuncSig_DateDiff:
   705  		f = &builtinDateDiffSig{base}
   706  	case fidelpb.ScalarFuncSig_NullTimeDiff:
   707  		f = &builtinNullTimeDiffSig{base}
   708  	case fidelpb.ScalarFuncSig_TimeStringTimeDiff:
   709  		f = &builtinTimeStringTimeDiffSig{base}
   710  	case fidelpb.ScalarFuncSig_DurationStringTimeDiff:
   711  		f = &builtinDurationStringTimeDiffSig{base}
   712  	case fidelpb.ScalarFuncSig_DurationDurationTimeDiff:
   713  		f = &builtinDurationDurationTimeDiffSig{base}
   714  	case fidelpb.ScalarFuncSig_StringTimeTimeDiff:
   715  		f = &builtinStringTimeTimeDiffSig{base}
   716  	case fidelpb.ScalarFuncSig_StringDurationTimeDiff:
   717  		f = &builtinStringDurationTimeDiffSig{base}
   718  	case fidelpb.ScalarFuncSig_StringStringTimeDiff:
   719  		f = &builtinStringStringTimeDiffSig{base}
   720  	case fidelpb.ScalarFuncSig_TimeTimeTimeDiff:
   721  		f = &builtinTimeTimeTimeDiffSig{base}
   722  	case fidelpb.ScalarFuncSig_Date:
   723  		f = &builtinDateSig{base}
   724  	case fidelpb.ScalarFuncSig_Hour:
   725  		f = &builtinHourSig{base}
   726  	case fidelpb.ScalarFuncSig_Minute:
   727  		f = &builtinMinuteSig{base}
   728  	case fidelpb.ScalarFuncSig_Second:
   729  		f = &builtinSecondSig{base}
   730  	case fidelpb.ScalarFuncSig_MicroSecond:
   731  		f = &builtinMicroSecondSig{base}
   732  	case fidelpb.ScalarFuncSig_Month:
   733  		f = &builtinMonthSig{base}
   734  	case fidelpb.ScalarFuncSig_MonthName:
   735  		f = &builtinMonthNameSig{base}
   736  	case fidelpb.ScalarFuncSig_NowWithArg:
   737  		f = &builtinNowWithArgSig{base}
   738  	case fidelpb.ScalarFuncSig_NowWithoutArg:
   739  		f = &builtinNowWithoutArgSig{base}
   740  	case fidelpb.ScalarFuncSig_DayName:
   741  		f = &builtinDayNameSig{base}
   742  	case fidelpb.ScalarFuncSig_DayOfMonth:
   743  		f = &builtinDayOfMonthSig{base}
   744  	case fidelpb.ScalarFuncSig_DayOfWeek:
   745  		f = &builtinDayOfWeekSig{base}
   746  	case fidelpb.ScalarFuncSig_DayOfYear:
   747  		f = &builtinDayOfYearSig{base}
   748  	case fidelpb.ScalarFuncSig_WeekWithMode:
   749  		f = &builtinWeekWithModeSig{base}
   750  	case fidelpb.ScalarFuncSig_WeekWithoutMode:
   751  		f = &builtinWeekWithoutModeSig{base}
   752  	case fidelpb.ScalarFuncSig_WeekDay:
   753  		f = &builtinWeekDaySig{base}
   754  	case fidelpb.ScalarFuncSig_WeekOfYear:
   755  		f = &builtinWeekOfYearSig{base}
   756  	case fidelpb.ScalarFuncSig_Year:
   757  		f = &builtinYearSig{base}
   758  	case fidelpb.ScalarFuncSig_YearWeekWithMode:
   759  		f = &builtinYearWeekWithModeSig{base}
   760  	case fidelpb.ScalarFuncSig_YearWeekWithoutMode:
   761  		f = &builtinYearWeekWithoutModeSig{base}
   762  	case fidelpb.ScalarFuncSig_GetFormat:
   763  		f = &builtinGetFormatSig{base}
   764  	case fidelpb.ScalarFuncSig_SysDateWithFsp:
   765  		f = &builtinSysDateWithFspSig{base}
   766  	case fidelpb.ScalarFuncSig_SysDateWithoutFsp:
   767  		f = &builtinSysDateWithoutFspSig{base}
   768  	case fidelpb.ScalarFuncSig_CurrentDate:
   769  		f = &builtinCurrentDateSig{base}
   770  	case fidelpb.ScalarFuncSig_CurrentTime0Arg:
   771  		f = &builtinCurrentTime0ArgSig{base}
   772  	case fidelpb.ScalarFuncSig_CurrentTime1Arg:
   773  		f = &builtinCurrentTime1ArgSig{base}
   774  	case fidelpb.ScalarFuncSig_Time:
   775  		f = &builtinTimeSig{base}
   776  	//case fidelpb.ScalarFuncSig_TimeLiteral:
   777  	//	f = &builtinTimeLiteralSig{base}
   778  	case fidelpb.ScalarFuncSig_UTCDate:
   779  		f = &builtinUTCDateSig{base}
   780  	case fidelpb.ScalarFuncSig_UTCTimestampWithArg:
   781  		f = &builtinUTCTimestampWithArgSig{base}
   782  	case fidelpb.ScalarFuncSig_UTCTimestampWithoutArg:
   783  		f = &builtinUTCTimestampWithoutArgSig{base}
   784  	case fidelpb.ScalarFuncSig_AddDatetimeAndDuration:
   785  		f = &builtinAddDatetimeAndDurationSig{base}
   786  	case fidelpb.ScalarFuncSig_AddDatetimeAndString:
   787  		f = &builtinAddDatetimeAndStringSig{base}
   788  	case fidelpb.ScalarFuncSig_AddTimeDateTimeNull:
   789  		f = &builtinAddTimeDateTimeNullSig{base}
   790  	case fidelpb.ScalarFuncSig_AddStringAndDuration:
   791  		f = &builtinAddStringAndDurationSig{base}
   792  	case fidelpb.ScalarFuncSig_AddStringAndString:
   793  		f = &builtinAddStringAndStringSig{base}
   794  	case fidelpb.ScalarFuncSig_AddTimeStringNull:
   795  		f = &builtinAddTimeStringNullSig{base}
   796  	case fidelpb.ScalarFuncSig_AddDurationAndDuration:
   797  		f = &builtinAddDurationAndDurationSig{base}
   798  	case fidelpb.ScalarFuncSig_AddDurationAndString:
   799  		f = &builtinAddDurationAndStringSig{base}
   800  	case fidelpb.ScalarFuncSig_AddTimeDurationNull:
   801  		f = &builtinAddTimeDurationNullSig{base}
   802  	case fidelpb.ScalarFuncSig_AddDateAndDuration:
   803  		f = &builtinAddDateAndDurationSig{base}
   804  	case fidelpb.ScalarFuncSig_AddDateAndString:
   805  		f = &builtinAddDateAndStringSig{base}
   806  	case fidelpb.ScalarFuncSig_SubDatetimeAndDuration:
   807  		f = &builtinSubDatetimeAndDurationSig{base}
   808  	case fidelpb.ScalarFuncSig_SubDatetimeAndString:
   809  		f = &builtinSubDatetimeAndStringSig{base}
   810  	case fidelpb.ScalarFuncSig_SubTimeDateTimeNull:
   811  		f = &builtinSubTimeDateTimeNullSig{base}
   812  	case fidelpb.ScalarFuncSig_SubStringAndDuration:
   813  		f = &builtinSubStringAndDurationSig{base}
   814  	case fidelpb.ScalarFuncSig_SubStringAndString:
   815  		f = &builtinSubStringAndStringSig{base}
   816  	case fidelpb.ScalarFuncSig_SubTimeStringNull:
   817  		f = &builtinSubTimeStringNullSig{base}
   818  	case fidelpb.ScalarFuncSig_SubDurationAndDuration:
   819  		f = &builtinSubDurationAndDurationSig{base}
   820  	case fidelpb.ScalarFuncSig_SubDurationAndString:
   821  		f = &builtinSubDurationAndStringSig{base}
   822  	case fidelpb.ScalarFuncSig_SubTimeDurationNull:
   823  		f = &builtinSubTimeDurationNullSig{base}
   824  	case fidelpb.ScalarFuncSig_SubDateAndDuration:
   825  		f = &builtinSubDateAndDurationSig{base}
   826  	case fidelpb.ScalarFuncSig_SubDateAndString:
   827  		f = &builtinSubDateAndStringSig{base}
   828  	case fidelpb.ScalarFuncSig_UnixTimestampCurrent:
   829  		f = &builtinUnixTimestampCurrentSig{base}
   830  	case fidelpb.ScalarFuncSig_UnixTimestampInt:
   831  		f = &builtinUnixTimestampIntSig{base}
   832  	case fidelpb.ScalarFuncSig_UnixTimestamFIDelec:
   833  		f = &builtinUnixTimestamFIDelecSig{base}
   834  	//case fidelpb.ScalarFuncSig_ConvertTz:
   835  	//	f = &builtinConvertTzSig{base}
   836  	case fidelpb.ScalarFuncSig_MakeDate:
   837  		f = &builtinMakeDateSig{base}
   838  	case fidelpb.ScalarFuncSig_MakeTime:
   839  		f = &builtinMakeTimeSig{base}
   840  	case fidelpb.ScalarFuncSig_PeriodAdd:
   841  		f = &builtinPeriodAddSig{base}
   842  	case fidelpb.ScalarFuncSig_PeriodDiff:
   843  		f = &builtinPeriodDiffSig{base}
   844  	case fidelpb.ScalarFuncSig_Quarter:
   845  		f = &builtinQuarterSig{base}
   846  	case fidelpb.ScalarFuncSig_SecToTime:
   847  		f = &builtinSecToTimeSig{base}
   848  	case fidelpb.ScalarFuncSig_TimeToSec:
   849  		f = &builtinTimeToSecSig{base}
   850  	case fidelpb.ScalarFuncSig_TimestampAdd:
   851  		f = &builtinTimestampAddSig{base}
   852  	case fidelpb.ScalarFuncSig_ToDays:
   853  		f = &builtinToDaysSig{base}
   854  	case fidelpb.ScalarFuncSig_ToSeconds:
   855  		f = &builtinToSecondsSig{base}
   856  	case fidelpb.ScalarFuncSig_UTCTimeWithArg:
   857  		f = &builtinUTCTimeWithArgSig{base}
   858  	case fidelpb.ScalarFuncSig_UTCTimeWithoutArg:
   859  		f = &builtinUTCTimeWithoutArgSig{base}
   860  	//case fidelpb.ScalarFuncSig_Timestamp1Arg:
   861  	//	f = &builtinTimestamp1ArgSig{base}
   862  	//case fidelpb.ScalarFuncSig_Timestamp2Args:
   863  	//	f = &builtinTimestamp2ArgsSig{base}
   864  	//case fidelpb.ScalarFuncSig_TimestampLiteral:
   865  	//	f = &builtinTimestampLiteralSig{base}
   866  	case fidelpb.ScalarFuncSig_LastDay:
   867  		f = &builtinLastDaySig{base}
   868  	case fidelpb.ScalarFuncSig_StrToDateDate:
   869  		f = &builtinStrToDateDateSig{base}
   870  	case fidelpb.ScalarFuncSig_StrToDateDatetime:
   871  		f = &builtinStrToDateDatetimeSig{base}
   872  	case fidelpb.ScalarFuncSig_StrToDateDuration:
   873  		f = &builtinStrToDateDurationSig{base}
   874  	case fidelpb.ScalarFuncSig_FromUnixTime1Arg:
   875  		f = &builtinFromUnixTime1ArgSig{base}
   876  	case fidelpb.ScalarFuncSig_FromUnixTime2Arg:
   877  		f = &builtinFromUnixTime2ArgSig{base}
   878  	case fidelpb.ScalarFuncSig_ExtractDatetime:
   879  		f = &builtinExtractDatetimeSig{base}
   880  	case fidelpb.ScalarFuncSig_ExtractDuration:
   881  		f = &builtinExtractDurationSig{base}
   882  	//case fidelpb.ScalarFuncSig_AddDateStringString:
   883  	//	f = &builtinAddDateStringStringSig{base}
   884  	//case fidelpb.ScalarFuncSig_AddDateStringInt:
   885  	//	f = &builtinAddDateStringIntSig{base}
   886  	//case fidelpb.ScalarFuncSig_AddDateStringDecimal:
   887  	//	f = &builtinAddDateStringDecimalSig{base}
   888  	//case fidelpb.ScalarFuncSig_AddDateIntString:
   889  	//	f = &builtinAddDateIntStringSig{base}
   890  	//case fidelpb.ScalarFuncSig_AddDateIntInt:
   891  	//	f = &builtinAddDateIntIntSig{base}
   892  	//case fidelpb.ScalarFuncSig_AddDateDatetimeString:
   893  	//	f = &builtinAddDateDatetimeStringSig{base}
   894  	//case fidelpb.ScalarFuncSig_AddDateDatetimeInt:
   895  	//	f = &builtinAddDateDatetimeIntSig{base}
   896  	//case fidelpb.ScalarFuncSig_SubDateStringString:
   897  	//	f = &builtinSubDateStringStringSig{base}
   898  	//case fidelpb.ScalarFuncSig_SubDateStringInt:
   899  	//	f = &builtinSubDateStringIntSig{base}
   900  	//case fidelpb.ScalarFuncSig_SubDateStringDecimal:
   901  	//	f = &builtinSubDateStringDecimalSig{base}
   902  	//case fidelpb.ScalarFuncSig_SubDateIntString:
   903  	//	f = &builtinSubDateIntStringSig{base}
   904  	//case fidelpb.ScalarFuncSig_SubDateIntInt:
   905  	//	f = &builtinSubDateIntIntSig{base}
   906  	//case fidelpb.ScalarFuncSig_SubDateDatetimeString:
   907  	//	f = &builtinSubDateDatetimeStringSig{base}
   908  	//case fidelpb.ScalarFuncSig_SubDateDatetimeInt:
   909  	//	f = &builtinSubDateDatetimeIntSig{base}
   910  	case fidelpb.ScalarFuncSig_FromDays:
   911  		f = &builtinFromDaysSig{base}
   912  	case fidelpb.ScalarFuncSig_TimeFormat:
   913  		f = &builtinTimeFormatSig{base}
   914  	case fidelpb.ScalarFuncSig_TimestamFIDeliff:
   915  		f = &builtinTimestamFIDeliffSig{base}
   916  	case fidelpb.ScalarFuncSig_BitLength:
   917  		f = &builtinBitLengthSig{base}
   918  	case fidelpb.ScalarFuncSig_Bin:
   919  		f = &builtinBinSig{base}
   920  	case fidelpb.ScalarFuncSig_ASCII:
   921  		f = &builtinASCIISig{base}
   922  	case fidelpb.ScalarFuncSig_Char:
   923  		f = &builtinCharSig{base}
   924  	case fidelpb.ScalarFuncSig_CharLengthUTF8:
   925  		f = &builtinCharLengthUTF8Sig{base}
   926  	case fidelpb.ScalarFuncSig_Concat:
   927  		f = &builtinConcatSig{base, maxAllowedPacket}
   928  	case fidelpb.ScalarFuncSig_ConcatWS:
   929  		f = &builtinConcatWSSig{base, maxAllowedPacket}
   930  	case fidelpb.ScalarFuncSig_Convert:
   931  		f = &builtinConvertSig{base}
   932  	case fidelpb.ScalarFuncSig_Elt:
   933  		f = &builtinEltSig{base}
   934  	case fidelpb.ScalarFuncSig_ExportSet3Arg:
   935  		f = &builtinExportSet3ArgSig{base}
   936  	case fidelpb.ScalarFuncSig_ExportSet4Arg:
   937  		f = &builtinExportSet4ArgSig{base}
   938  	case fidelpb.ScalarFuncSig_ExportSet5Arg:
   939  		f = &builtinExportSet5ArgSig{base}
   940  	case fidelpb.ScalarFuncSig_FieldInt:
   941  		f = &builtinFieldIntSig{base}
   942  	case fidelpb.ScalarFuncSig_FieldReal:
   943  		f = &builtinFieldRealSig{base}
   944  	case fidelpb.ScalarFuncSig_FieldString:
   945  		f = &builtinFieldStringSig{base}
   946  	case fidelpb.ScalarFuncSig_FindInSet:
   947  		f = &builtinFindInSetSig{base}
   948  	case fidelpb.ScalarFuncSig_Format:
   949  		f = &builtinFormatSig{base}
   950  	case fidelpb.ScalarFuncSig_FormatWithLocale:
   951  		f = &builtinFormatWithLocaleSig{base}
   952  	case fidelpb.ScalarFuncSig_FromBase64:
   953  		f = &builtinFromBase64Sig{base, maxAllowedPacket}
   954  	case fidelpb.ScalarFuncSig_HexIntArg:
   955  		f = &builtinHexIntArgSig{base}
   956  	case fidelpb.ScalarFuncSig_HexStrArg:
   957  		f = &builtinHexStrArgSig{base}
   958  	case fidelpb.ScalarFuncSig_InsertUTF8:
   959  		f = &builtinInsertUTF8Sig{base, maxAllowedPacket}
   960  	case fidelpb.ScalarFuncSig_Insert:
   961  		f = &builtinInsertSig{base, maxAllowedPacket}
   962  	case fidelpb.ScalarFuncSig_InstrUTF8:
   963  		f = &builtinInstrUTF8Sig{base}
   964  	case fidelpb.ScalarFuncSig_Instr:
   965  		f = &builtinInstrSig{base}
   966  	case fidelpb.ScalarFuncSig_LTrim:
   967  		f = &builtinLTrimSig{base}
   968  	case fidelpb.ScalarFuncSig_LeftUTF8:
   969  		f = &builtinLeftUTF8Sig{base}
   970  	case fidelpb.ScalarFuncSig_Left:
   971  		f = &builtinLeftSig{base}
   972  	case fidelpb.ScalarFuncSig_Length:
   973  		f = &builtinLengthSig{base}
   974  	case fidelpb.ScalarFuncSig_Locate2ArgsUTF8:
   975  		f = &builtinLocate2ArgsUTF8Sig{base}
   976  	case fidelpb.ScalarFuncSig_Locate3ArgsUTF8:
   977  		f = &builtinLocate3ArgsUTF8Sig{base}
   978  	case fidelpb.ScalarFuncSig_Locate2Args:
   979  		f = &builtinLocate2ArgsSig{base}
   980  	case fidelpb.ScalarFuncSig_Locate3Args:
   981  		f = &builtinLocate3ArgsSig{base}
   982  	case fidelpb.ScalarFuncSig_Lower:
   983  		f = &builtinLowerSig{base}
   984  	case fidelpb.ScalarFuncSig_LpadUTF8:
   985  		f = &builtinLpadUTF8Sig{base, maxAllowedPacket}
   986  	case fidelpb.ScalarFuncSig_Lpad:
   987  		f = &builtinLpadSig{base, maxAllowedPacket}
   988  	case fidelpb.ScalarFuncSig_MakeSet:
   989  		f = &builtinMakeSetSig{base}
   990  	case fidelpb.ScalarFuncSig_OctInt:
   991  		f = &builtinOctIntSig{base}
   992  	case fidelpb.ScalarFuncSig_OctString:
   993  		f = &builtinOctStringSig{base}
   994  	case fidelpb.ScalarFuncSig_Ord:
   995  		f = &builtinOrdSig{base}
   996  	case fidelpb.ScalarFuncSig_Quote:
   997  		f = &builtinQuoteSig{base}
   998  	case fidelpb.ScalarFuncSig_RTrim:
   999  		f = &builtinRTrimSig{base}
  1000  	case fidelpb.ScalarFuncSig_Repeat:
  1001  		f = &builtinRepeatSig{base, maxAllowedPacket}
  1002  	case fidelpb.ScalarFuncSig_Replace:
  1003  		f = &builtinReplaceSig{base}
  1004  	case fidelpb.ScalarFuncSig_ReverseUTF8:
  1005  		f = &builtinReverseUTF8Sig{base}
  1006  	case fidelpb.ScalarFuncSig_Reverse:
  1007  		f = &builtinReverseSig{base}
  1008  	case fidelpb.ScalarFuncSig_RightUTF8:
  1009  		f = &builtinRightUTF8Sig{base}
  1010  	case fidelpb.ScalarFuncSig_Right:
  1011  		f = &builtinRightSig{base}
  1012  	case fidelpb.ScalarFuncSig_RpadUTF8:
  1013  		f = &builtinRpadUTF8Sig{base, maxAllowedPacket}
  1014  	case fidelpb.ScalarFuncSig_Rpad:
  1015  		f = &builtinRpadSig{base, maxAllowedPacket}
  1016  	case fidelpb.ScalarFuncSig_Space:
  1017  		f = &builtinSpaceSig{base, maxAllowedPacket}
  1018  	case fidelpb.ScalarFuncSig_Strcmp:
  1019  		f = &builtinStrcmpSig{base}
  1020  	case fidelpb.ScalarFuncSig_Substring2ArgsUTF8:
  1021  		f = &builtinSubstring2ArgsUTF8Sig{base}
  1022  	case fidelpb.ScalarFuncSig_Substring3ArgsUTF8:
  1023  		f = &builtinSubstring3ArgsUTF8Sig{base}
  1024  	case fidelpb.ScalarFuncSig_Substring2Args:
  1025  		f = &builtinSubstring2ArgsSig{base}
  1026  	case fidelpb.ScalarFuncSig_Substring3Args:
  1027  		f = &builtinSubstring3ArgsSig{base}
  1028  	case fidelpb.ScalarFuncSig_SubstringIndex:
  1029  		f = &builtinSubstringIndexSig{base}
  1030  	case fidelpb.ScalarFuncSig_ToBase64:
  1031  		f = &builtinToBase64Sig{base, maxAllowedPacket}
  1032  	case fidelpb.ScalarFuncSig_Trim1Arg:
  1033  		f = &builtinTrim1ArgSig{base}
  1034  	case fidelpb.ScalarFuncSig_Trim2Args:
  1035  		f = &builtinTrim2ArgsSig{base}
  1036  	case fidelpb.ScalarFuncSig_Trim3Args:
  1037  		f = &builtinTrim3ArgsSig{base}
  1038  	case fidelpb.ScalarFuncSig_UnHex:
  1039  		f = &builtinUnHexSig{base}
  1040  	case fidelpb.ScalarFuncSig_Upper:
  1041  		f = &builtinUpperSig{base}
  1042  
  1043  	default:
  1044  		e = errFunctionNotExists.GenWithStackByArgs("FUNCTION", sigCode)
  1045  		return nil, e
  1046  	}
  1047  	f.setPbCode(sigCode)
  1048  	return f, nil
  1049  }
  1050  
  1051  func newDistALLEGROSQLFunctionBySig(sc *stmtctx.StatementContext, sigCode fidelpb.ScalarFuncSig, tp *fidelpb.FieldType, args []Expression) (Expression, error) {
  1052  	ctx := mock.NewContext()
  1053  	ctx.GetStochastikVars().StmtCtx = sc
  1054  	f, err := getSignatureByPB(ctx, sigCode, tp, args)
  1055  	if err != nil {
  1056  		return nil, err
  1057  	}
  1058  	return &ScalarFunction{
  1059  		FuncName: perceptron.NewCIStr(fmt.Sprintf("sig_%T", f)),
  1060  		Function: f,
  1061  		RetType:  f.getRetTp(),
  1062  	}, nil
  1063  }
  1064  
  1065  // PBToExprs converts pb structures to memexs.
  1066  func PBToExprs(pbExprs []*fidelpb.Expr, fieldTps []*types.FieldType, sc *stmtctx.StatementContext) ([]Expression, error) {
  1067  	exprs := make([]Expression, 0, len(pbExprs))
  1068  	for _, expr := range pbExprs {
  1069  		e, err := PBToExpr(expr, fieldTps, sc)
  1070  		if err != nil {
  1071  			return nil, errors.Trace(err)
  1072  		}
  1073  		if e == nil {
  1074  			return nil, errors.Errorf("pb to memex failed, pb memex is %v", expr)
  1075  		}
  1076  		exprs = append(exprs, e)
  1077  	}
  1078  	return exprs, nil
  1079  }
  1080  
  1081  // PBToExpr converts pb structure to memex.
  1082  func PBToExpr(expr *fidelpb.Expr, tps []*types.FieldType, sc *stmtctx.StatementContext) (Expression, error) {
  1083  	switch expr.Tp {
  1084  	case fidelpb.ExprType_DeferredCausetRef:
  1085  		_, offset, err := codec.DecodeInt(expr.Val)
  1086  		if err != nil {
  1087  			return nil, err
  1088  		}
  1089  		return &DeferredCauset{Index: int(offset), RetType: tps[offset]}, nil
  1090  	case fidelpb.ExprType_Null:
  1091  		return &Constant{Value: types.Causet{}, RetType: types.NewFieldType(allegrosql.TypeNull)}, nil
  1092  	case fidelpb.ExprType_Int64:
  1093  		return convertInt(expr.Val)
  1094  	case fidelpb.ExprType_Uint64:
  1095  		return convertUint(expr.Val)
  1096  	case fidelpb.ExprType_String:
  1097  		return convertString(expr.Val, expr.FieldType)
  1098  	case fidelpb.ExprType_Bytes:
  1099  		return &Constant{Value: types.NewBytesCauset(expr.Val), RetType: types.NewFieldType(allegrosql.TypeString)}, nil
  1100  	case fidelpb.ExprType_Float32:
  1101  		return convertFloat(expr.Val, true)
  1102  	case fidelpb.ExprType_Float64:
  1103  		return convertFloat(expr.Val, false)
  1104  	case fidelpb.ExprType_MysqlDecimal:
  1105  		return convertDecimal(expr.Val)
  1106  	case fidelpb.ExprType_MysqlDuration:
  1107  		return convertDuration(expr.Val)
  1108  	case fidelpb.ExprType_MysqlTime:
  1109  		return convertTime(expr.Val, expr.FieldType, sc.TimeZone)
  1110  	case fidelpb.ExprType_MysqlJson:
  1111  		return convertJSON(expr.Val)
  1112  	}
  1113  	if expr.Tp != fidelpb.ExprType_ScalarFunc {
  1114  		panic("should be a fidelpb.ExprType_ScalarFunc")
  1115  	}
  1116  	// Then it must be a scalar function.
  1117  	args := make([]Expression, 0, len(expr.Children))
  1118  	for _, child := range expr.Children {
  1119  		if child.Tp == fidelpb.ExprType_ValueList {
  1120  			results, err := decodeValueList(child.Val)
  1121  			if err != nil {
  1122  				return nil, err
  1123  			}
  1124  			if len(results) == 0 {
  1125  				return &Constant{Value: types.NewCauset(false), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil
  1126  			}
  1127  			args = append(args, results...)
  1128  			continue
  1129  		}
  1130  		arg, err := PBToExpr(child, tps, sc)
  1131  		if err != nil {
  1132  			return nil, err
  1133  		}
  1134  		args = append(args, arg)
  1135  	}
  1136  	sf, err := newDistALLEGROSQLFunctionBySig(sc, expr.Sig, expr.FieldType, args)
  1137  	if err != nil {
  1138  		return nil, err
  1139  	}
  1140  
  1141  	return sf, nil
  1142  }
  1143  
  1144  func convertTime(data []byte, ftPB *fidelpb.FieldType, tz *time.Location) (*Constant, error) {
  1145  	ft := PbTypeToFieldType(ftPB)
  1146  	_, v, err := codec.DecodeUint(data)
  1147  	if err != nil {
  1148  		return nil, err
  1149  	}
  1150  	var t types.Time
  1151  	t.SetType(ft.Tp)
  1152  	t.SetFsp(int8(ft.Decimal))
  1153  	err = t.FromPackedUint(v)
  1154  	if err != nil {
  1155  		return nil, err
  1156  	}
  1157  	if ft.Tp == allegrosql.TypeTimestamp && tz != time.UTC {
  1158  		err = t.ConvertTimeZone(time.UTC, tz)
  1159  		if err != nil {
  1160  			return nil, err
  1161  		}
  1162  	}
  1163  	return &Constant{Value: types.NewTimeCauset(t), RetType: ft}, nil
  1164  }
  1165  
  1166  func decodeValueList(data []byte) ([]Expression, error) {
  1167  	if len(data) == 0 {
  1168  		return nil, nil
  1169  	}
  1170  	list, err := codec.Decode(data, 1)
  1171  	if err != nil {
  1172  		return nil, err
  1173  	}
  1174  	result := make([]Expression, 0, len(list))
  1175  	for _, value := range list {
  1176  		result = append(result, &Constant{Value: value})
  1177  	}
  1178  	return result, nil
  1179  }
  1180  
  1181  func convertInt(val []byte) (*Constant, error) {
  1182  	var d types.Causet
  1183  	_, i, err := codec.DecodeInt(val)
  1184  	if err != nil {
  1185  		return nil, errors.Errorf("invalid int % x", val)
  1186  	}
  1187  	d.SetInt64(i)
  1188  	return &Constant{Value: d, RetType: types.NewFieldType(allegrosql.TypeLonglong)}, nil
  1189  }
  1190  
  1191  func convertUint(val []byte) (*Constant, error) {
  1192  	var d types.Causet
  1193  	_, u, err := codec.DecodeUint(val)
  1194  	if err != nil {
  1195  		return nil, errors.Errorf("invalid uint % x", val)
  1196  	}
  1197  	d.SetUint64(u)
  1198  	return &Constant{Value: d, RetType: &types.FieldType{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, nil
  1199  }
  1200  
  1201  func convertString(val []byte, tp *fidelpb.FieldType) (*Constant, error) {
  1202  	var d types.Causet
  1203  	d.SetBytesAsString(val, protoToDefCauslation(tp.DefCauslate), uint32(tp.Flen))
  1204  	return &Constant{Value: d, RetType: types.NewFieldType(allegrosql.TypeVarString)}, nil
  1205  }
  1206  
  1207  func convertFloat(val []byte, f32 bool) (*Constant, error) {
  1208  	var d types.Causet
  1209  	_, f, err := codec.DecodeFloat(val)
  1210  	if err != nil {
  1211  		return nil, errors.Errorf("invalid float % x", val)
  1212  	}
  1213  	if f32 {
  1214  		d.SetFloat32(float32(f))
  1215  	} else {
  1216  		d.SetFloat64(f)
  1217  	}
  1218  	return &Constant{Value: d, RetType: types.NewFieldType(allegrosql.TypeDouble)}, nil
  1219  }
  1220  
  1221  func convertDecimal(val []byte) (*Constant, error) {
  1222  	_, dec, precision, frac, err := codec.DecodeDecimal(val)
  1223  	var d types.Causet
  1224  	d.SetMysqlDecimal(dec)
  1225  	d.SetLength(precision)
  1226  	d.SetFrac(frac)
  1227  	if err != nil {
  1228  		return nil, errors.Errorf("invalid decimal % x", val)
  1229  	}
  1230  	return &Constant{Value: d, RetType: types.NewFieldType(allegrosql.TypeNewDecimal)}, nil
  1231  }
  1232  
  1233  func convertDuration(val []byte) (*Constant, error) {
  1234  	var d types.Causet
  1235  	_, i, err := codec.DecodeInt(val)
  1236  	if err != nil {
  1237  		return nil, errors.Errorf("invalid duration %d", i)
  1238  	}
  1239  	d.SetMysqlDuration(types.Duration{Duration: time.Duration(i), Fsp: types.MaxFsp})
  1240  	return &Constant{Value: d, RetType: types.NewFieldType(allegrosql.TypeDuration)}, nil
  1241  }
  1242  
  1243  func convertJSON(val []byte) (*Constant, error) {
  1244  	var d types.Causet
  1245  	_, d, err := codec.DecodeOne(val)
  1246  	if err != nil {
  1247  		return nil, errors.Errorf("invalid json % x", val)
  1248  	}
  1249  	if d.HoTT() != types.HoTTMysqlJSON {
  1250  		return nil, errors.Errorf("invalid Causet.HoTT() %d", d.HoTT())
  1251  	}
  1252  	return &Constant{Value: d, RetType: types.NewFieldType(allegrosql.TypeJSON)}, nil
  1253  }