@@ -72,6 +72,15 @@ func (sf *ScalarFunction) MarshalJSON() ([]byte, error) {
7272
7373// NewFunction creates a new scalar function or constant.
7474func NewFunction (ctx sessionctx.Context , funcName string , retType * types.FieldType , args ... Expression ) (Expression , error ) {
75+ return newFunction (ctx , true , funcName , retType , args ... )
76+ }
77+
78+ // NewFunctionBase creates a new scalar function or constant without constant fold
79+ func NewFunctionBase (ctx sessionctx.Context , funcName string , retType * types.FieldType , args ... Expression ) (Expression , error ) {
80+ return newFunction (ctx , false , funcName , retType , args ... )
81+ }
82+
83+ func newFunction (ctx sessionctx.Context , fold bool , funcName string , retType * types.FieldType , args ... Expression ) (Expression , error ) {
7584 if retType == nil {
7685 return nil , errors .Errorf ("RetType cannot be nil for ScalarFunction." )
7786 }
@@ -96,7 +105,10 @@ func NewFunction(ctx sessionctx.Context, funcName string, retType *types.FieldTy
96105 RetType : retType ,
97106 Function : f ,
98107 }
99- return FoldConstant (sf ), nil
108+ if fold {
109+ return FoldConstant (sf ), nil
110+ }
111+ return sf , nil
100112}
101113
102114// NewFunctionInternal is similar to NewFunction, but do not returns error, should only be used internally.
0 commit comments