diff --git a/pkg/sql/plan/build_update.go b/pkg/sql/plan/build_update.go index caeb9cb18e9b2..92595683321ba 100644 --- a/pkg/sql/plan/build_update.go +++ b/pkg/sql/plan/build_update.go @@ -145,7 +145,12 @@ func rewriteUpdateQueryLastNode(builder *QueryBuilder, planCtxs []*dmlPlanCtx, l } else { pos := idx + colIdx if col.OnUpdate != nil && col.OnUpdate.Expr != nil { - lastNode.ProjectList[pos] = col.OnUpdate.Expr + newDefExpr := DeepCopyExpr(col.OnUpdate.Expr) + err = replaceFuncId(builder.GetContext(), newDefExpr) + if err != nil { + return err + } + lastNode.ProjectList[pos] = newDefExpr } if col != nil && col.Typ.Id == int32(types.T_enum) { diff --git a/pkg/sql/plan/build_util.go b/pkg/sql/plan/build_util.go index 3075d5f70f4dd..9fcedf4028ac3 100644 --- a/pkg/sql/plan/build_util.go +++ b/pkg/sql/plan/build_util.go @@ -30,6 +30,7 @@ import ( "github.com/matrixorigin/matrixone/pkg/sql/colexec" "github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect" "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" + "github.com/matrixorigin/matrixone/pkg/sql/plan/function" "github.com/matrixorigin/matrixone/pkg/vm/process" ) @@ -478,7 +479,33 @@ func getDefaultExpr(ctx context.Context, d *plan.ColDef) (*Expr, error) { }, }, nil } - return d.Default.Expr, nil + newDefExpr := DeepCopyExpr(d.Default.Expr) + err := replaceFuncId(ctx, newDefExpr) + return newDefExpr, err +} + +func replaceFuncId(ctx context.Context, expr *Expr) error { + switch fun := expr.Expr.(type) { + case *plan.Expr_F: + for _, arg := range fun.F.Args { + err := replaceFuncId(ctx, arg) + if err != nil { + return err + } + } + + fnName := fun.F.Func.ObjName + newFID, err := function.GetFunctionIdByName(ctx, fnName) + if err != nil { + return err + } + oldFID, oldIdx := function.DecodeOverloadID(fun.F.Func.Obj) + if oldFID != newFID { + fun.F.Func.Obj = function.EncodeOverloadID(newFID, oldIdx) + } + default: + } + return nil } func judgeUnixTimestampReturnType(timestr string) types.T { diff --git a/pkg/sql/plan/build_util_test.go b/pkg/sql/plan/build_util_test.go new file mode 100644 index 0000000000000..ba220d26d22a8 --- /dev/null +++ b/pkg/sql/plan/build_util_test.go @@ -0,0 +1,61 @@ +// Copyright 2024 Matrix Origin +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package plan + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/matrixorigin/matrixone/pkg/pb/plan" + "github.com/matrixorigin/matrixone/pkg/sql/plan/function" +) + +func Test_replaceFuncId(t *testing.T) { + case1 := &Expr{ + Expr: &plan.Expr_F{ + F: &plan.Function{ + Func: &ObjectRef{ + ObjName: "current_timestamp", + Obj: function.CURRENT_TIMESTAMP, + }, + Args: []*Expr{ + { + Expr: &plan.Expr_Col{ + Col: &plan.ColRef{ + RelPos: 1, + ColPos: 10, + Name: "a", + }, + }, + }, + }, + }, + }, + } + + err := replaceFuncId(context.Background(), case1) + assert.NoError(t, err) + + case1ColDef := &plan.ColDef{ + Default: &plan.Default{ + Expr: case1, + }, + } + case1Expr, err := getDefaultExpr(context.Background(), case1ColDef) + assert.NoError(t, err) + assert.NotNil(t, case1Expr) +} diff --git a/pkg/sql/plan/function/function.go b/pkg/sql/plan/function/function.go index 1ac7d7ac4c48e..bbdb53983bb76 100644 --- a/pkg/sql/plan/function/function.go +++ b/pkg/sql/plan/function/function.go @@ -510,3 +510,6 @@ func (selectList *FunctionSelectList) Contains(row uint64) bool { } return !selectList.SelectList[row] } + +var EncodeOverloadID = encodeOverloadID +var GetFunctionIdByName = getFunctionIdByName diff --git a/pkg/sql/plan/function/function_id.go b/pkg/sql/plan/function/function_id.go index e070e199efbe7..fc05f8962fc10 100644 --- a/pkg/sql/plan/function/function_id.go +++ b/pkg/sql/plan/function/function_id.go @@ -21,385 +21,386 @@ const ( // All function IDs const ( - EQUAL = iota // = - NOT_EQUAL // <> - GREAT_THAN // > - GREAT_EQUAL // >= - LESS_THAN // < - LESS_EQUAL // <= - BETWEEN - UNARY_PLUS // UNARY_PLUS + - UNARY_MINUS // UNARY_MINUS - - UNARY_TILDE // UNARY_TILDE ~ - PLUS // + - MINUS // - - MULTI // * - DIV // / - INTEGER_DIV // Div - MOD // % - CONCAT // || - AND - OR - XOR - NOT - CAST - BIT_CAST - IS - ISNOT - ISNULL - ISNOTNULL - ISTRUE - ISNOTTRUE - ISFALSE - ISNOTFALSE - ISEMPTY - NOT_IN_ROWS - OP_BIT_AND // & - OP_BIT_OR // | - OP_BIT_XOR // ^ - OP_BIT_SHIFT_LEFT // << - OP_BIT_SHIFT_RIGHT // >> - - ABS - ACOS - ADDDATE - ADDTIME - AES_DECRYPT - AES_ENCRYPT - ANY_VALUE - APPROX_COUNT - ARRAY_AGG - ARRAY_APPEND - ARRAY_CAT - ARRAY_CONTAINS - ARRAY_POSITION - ARRAY_SIZE - ASCII - ASIN - ASSERT - ATAN - ATAN2 - AVG - AVG_TW_CACHE - AVG_TW_RESULT - BASE64_DECODE - BASE64_ENCODE - BIT_AND - BIT_LENGTH - BIT_NOT - BIT_OR - BIT_XOR - BITAGG_AND - BITAGG_OR - BOOLAGG_AND - BOOLAGG_OR - CASE - CEIL - CHR - COALESCE - FIELD - CONCAT_WS - CONTAINS - CORR - COS - COT - CRC32 - COUNT - COUNT_IF - COVAR_POP - COVAR_SAMPLE - CONVERT_TZ - CUME_DIST - CURRENT_DATE - CURRENT_TIMESTAMP - DATE_FROM_PARTS - DATE_PART - DATEADD - DATEDIFF - TIMEDIFF - TIMESTAMPDIFF - DENSE_RANK - MO_WIN_DIVISOR - EMPTY - ENDSWITH - EXP - FINDINSET - FIRST_VALUE - FLOOR - GREATEST - GROUPING - HASH - HASH_AGG - HEX_DECODE - HEX_ENCODE - HEX - UNHEX - MD5 - IFF - IFNULL - ILIKE - ILIKE_ALL - ILIKE_ANY - IN - LAG - LAST_VALUE - LEAD - LEAST - LEFT - LENGTH - LENGTH_UTF8 - LIKE - LIKE_ALL - LIKE_ANY - LN - NOT_IN - LOG - LOG2 - LOG10 - LOWER - LPAD - LTRIM - MAX - MEDIAN - MIN - MODE - MONTH - NORMAL - NTH_VALUE - NTILE - NULLIF - PERCENT_RANK - PI - POSITION - POW - PREFIX_EQ - PREFIX_IN - PREFIX_BETWEEN - RADIAN - RANDOM - RANK - REGEXP - REGEXP_INSTR - REGEXP_LIKE - REGEXP_REPLACE - REGEXP_SUBSTR - REG_MATCH - NOT_REG_MATCH - REPEAT - REPLACE - REVERSE - RIGHT - ROUND - ROW_NUMBER - RPAD - RTRIM - SIGN - SIN - SINH - SPACE - SPLIT - SPLIT_PART - SQRT - STARCOUNT - STARTSWITH - STDDEV_POP - STDDEV_SAMPLE - SUBSTR - SUM - SYSDATE - GROUP_CONCAT - TAN - TO_DATE - STR_TO_DATE - TO_INTERVAL - TRANSLATE - TRIM - UNIFORM - SHA1 - SHA2 - UTC_TIMESTAMP - UNIX_TIMESTAMP - FROM_UNIXTIME - UPPER - VAR_POP - VAR_SAMPLE + EQUAL = 0 // = + NOT_EQUAL = 1 // <> + GREAT_THAN = 2 // > + GREAT_EQUAL = 3 // >= + LESS_THAN = 4 // < + LESS_EQUAL = 5 // <= + BETWEEN = 6 + UNARY_PLUS = 7 // UNARY_PLUS + + UNARY_MINUS = 8 // UNARY_MINUS - + UNARY_TILDE = 9 // UNARY_TILDE ~ + PLUS = 10 // + + MINUS = 11 // - + MULTI = 12 // * + DIV = 13 // / + INTEGER_DIV = 14 // Div + MOD = 15 // % + CONCAT = 16 // || + AND = 17 + OR = 18 + XOR = 19 + NOT = 20 + CAST = 21 + BIT_CAST = 22 + IS = 23 + ISNOT = 24 + ISNULL = 25 + ISNOTNULL = 26 + ISTRUE = 27 + ISNOTTRUE = 28 + ISFALSE = 29 + ISNOTFALSE = 30 + ISEMPTY = 31 + NOT_IN_ROWS = 32 + OP_BIT_AND = 33 // & + OP_BIT_OR = 34 // | + OP_BIT_XOR = 35 // ^ + OP_BIT_SHIFT_LEFT = 36 // << + OP_BIT_SHIFT_RIGHT = 37 // >> + + ABS = 38 + ACOS = 39 + ADDDATE = 40 + ADDTIME = 41 + AES_DECRYPT = 42 + AES_ENCRYPT = 43 + ANY_VALUE = 44 + APPROX_COUNT = 45 + ARRAY_AGG = 46 + ARRAY_APPEND = 47 + ARRAY_CAT = 48 + ARRAY_CONTAINS = 49 + ARRAY_POSITION = 50 + ARRAY_SIZE = 51 + ASCII = 52 + ASIN = 53 + ASSERT = 54 + ATAN = 55 + ATAN2 = 56 + AVG = 57 + AVG_TW_CACHE = 58 + AVG_TW_RESULT = 59 + BASE64_DECODE = 60 + BASE64_ENCODE = 61 + BIT_AND = 62 + BIT_LENGTH = 63 + BIT_NOT = 64 + BIT_OR = 65 + BIT_XOR = 66 + BITAGG_AND = 67 + BITAGG_OR = 68 + BOOLAGG_AND = 69 + BOOLAGG_OR = 70 + CASE = 71 + CEIL = 72 + CHR = 73 + COALESCE = 74 + FIELD = 75 + CONCAT_WS = 76 + CONTAINS = 77 + CORR = 78 + COS = 79 + COT = 80 + CRC32 = 81 + COUNT = 82 + COUNT_IF = 83 + COVAR_POP = 84 + COVAR_SAMPLE = 85 + CONVERT_TZ = 86 + CUME_DIST = 87 + CURRENT_DATE = 88 + CURRENT_TIMESTAMP = 89 + DATE_FROM_PARTS = 90 + DATE_PART = 91 + DATEADD = 92 + DATEDIFF = 93 + TIMEDIFF = 94 + TIMESTAMPDIFF = 95 + DENSE_RANK = 96 + MO_WIN_DIVISOR = 97 + EMPTY = 98 + ENDSWITH = 99 + EXP = 100 + FINDINSET = 101 + FIRST_VALUE = 102 + FLOOR = 103 + GREATEST = 104 + GROUPING = 105 + HASH = 106 + HASH_AGG = 107 + HEX_DECODE = 108 + HEX_ENCODE = 109 + HEX = 110 + UNHEX = 111 + MD5 = 112 + IFF = 113 + IFNULL = 114 + ILIKE = 115 + ILIKE_ALL = 116 + ILIKE_ANY = 117 + IN = 118 + LAG = 119 + LAST_VALUE = 120 + LEAD = 121 + LEAST = 122 + LEFT = 123 + LENGTH = 124 + LENGTH_UTF8 = 125 + LIKE = 126 + LIKE_ALL = 127 + LIKE_ANY = 128 + LN = 129 + NOT_IN = 130 + LOG = 131 + LOG2 = 132 + LOG10 = 133 + LOWER = 134 + LPAD = 135 + LTRIM = 136 + MAX = 137 + MEDIAN = 138 + MIN = 139 + MODE = 140 + MONTH = 141 + NORMAL = 142 + NTH_VALUE = 143 + NTILE = 144 + NULLIF = 145 + PERCENT_RANK = 146 + PI = 147 + POSITION = 148 + POW = 149 + PREFIX_EQ = 150 + PREFIX_IN = 151 + PREFIX_BETWEEN = 152 + RADIAN = 153 + RANDOM = 154 + RANK = 155 + REGEXP = 156 + REGEXP_INSTR = 157 + REGEXP_LIKE = 158 + REGEXP_REPLACE = 159 + REGEXP_SUBSTR = 160 + REG_MATCH = 161 + NOT_REG_MATCH = 162 + REPEAT = 163 + REPLACE = 164 + REVERSE = 165 + RIGHT = 166 + ROUND = 167 + ROW_NUMBER = 168 + RPAD = 169 + RTRIM = 170 + SIGN = 171 + SIN = 172 + SINH = 173 + SPACE = 174 + SPLIT = 175 + SPLIT_PART = 176 + SQRT = 177 + STARCOUNT = 178 + STARTSWITH = 179 + STDDEV_POP = 180 + STDDEV_SAMPLE = 181 + SUBSTR = 182 + SUM = 183 + SYSDATE = 184 + GROUP_CONCAT = 185 + TAN = 186 + TO_DATE = 187 + STR_TO_DATE = 188 + TO_INTERVAL = 189 + TRANSLATE = 190 + TRIM = 191 + UNIFORM = 192 + SHA1 = 193 + SHA2 = 194 + UTC_TIMESTAMP = 195 + UNIX_TIMESTAMP = 196 + FROM_UNIXTIME = 197 + UPPER = 198 + VAR_POP = 199 + VAR_SAMPLE = 200 // Date and Time functions - LAST_DAY - MAKEDATE - - DATE - TIME - DAY - DAYOFYEAR - INTERVAL - EXTRACT - OCT - SUBSTRING - ENCODE - DECODE - TO_BASE64 - FROM_BASE64 - SUBSTRING_INDEX - WEEK - WEEKDAY - YEAR - HOUR - MINUTE - SECOND - TO_DAYS - TO_SECONDS - - DATE_ADD - DATE_SUB - APPROX_COUNT_DISTINCT - - LOAD_FILE - SAVE_FILE + LAST_DAY = 201 + MAKEDATE = 202 + + DATE = 203 + TIME = 204 + DAY = 205 + DAYOFYEAR = 206 + INTERVAL = 207 + EXTRACT = 208 + OCT = 209 + SUBSTRING = 210 + ENCODE = 211 + DECODE = 212 + TO_BASE64 = 213 + FROM_BASE64 = 214 + SUBSTRING_INDEX = 215 + WEEK = 216 + WEEKDAY = 217 + YEAR = 218 + HOUR = 219 + MINUTE = 220 + SECOND = 221 + TO_DAYS = 222 + TO_SECONDS = 223 + + DATE_ADD = 224 + DATE_SUB = 225 + APPROX_COUNT_DISTINCT = 226 + + LOAD_FILE = 227 + SAVE_FILE = 228 //information functions //Reference to : https://dev.mysql.com/doc/refman/8.0/en/information-functions.html - DATABASE - USER - CONNECTION_ID - CHARSET - CONVERT - CURRENT_ROLE - FOUND_ROWS - ICULIBVERSION - LAST_INSERT_ID - LAST_QUERY_ID - LAST_UUID - ROLES_GRAPHML - ROW_COUNT - VERSION - COLLATION - CURRENT_ACCOUNT_ID - CURRENT_ACCOUNT_NAME - CURRENT_ROLE_ID - CURRENT_ROLE_NAME - CURRENT_USER_ID - CURRENT_USER_NAME - - TIMESTAMP - DATE_FORMAT - JSON_EXTRACT - JSON_EXTRACT_STRING - JSON_EXTRACT_FLOAT64 - JSON_QUOTE - JSON_UNQUOTE - JSON_ROW - JQ - TRY_JQ - WASM - TRY_WASM - FORMAT - SLEEP - INSTR - LOCATE - - UUID - SERIAL - SERIAL_FULL - SERIAL_EXTRACT - BIN - - ENABLE_FAULT_INJECTION - DISABLE_FAULT_INJECTION - ADD_FAULT_POINT // Add a fault point - REMOVE_FAULT_POINT // Remove - TRIGGER_FAULT_POINT // Trigger. - MO_WIN_TRUNCATE - - MO_MEMORY_USAGE // Dump memory usage - MO_ENABLE_MEMORY_USAGE_DETAIL - MO_DISABLE_MEMORY_USAGE_DETAIL + DATABASE = 229 + USER = 230 + CONNECTION_ID = 231 + CHARSET = 232 + CONVERT = 233 + CURRENT_ROLE = 234 + FOUND_ROWS = 235 + ICULIBVERSION = 236 + LAST_INSERT_ID = 237 + LAST_QUERY_ID = 238 + LAST_UUID = 239 + ROLES_GRAPHML = 240 + ROW_COUNT = 241 + VERSION = 242 + COLLATION = 243 + CURRENT_ACCOUNT_ID = 244 + CURRENT_ACCOUNT_NAME = 245 + CURRENT_ROLE_ID = 246 + CURRENT_ROLE_NAME = 247 + CURRENT_USER_ID = 248 + CURRENT_USER_NAME = 249 + + TIMESTAMP = 250 + DATE_FORMAT = 251 + JSON_EXTRACT = 252 + JSON_EXTRACT_STRING = 253 + JSON_EXTRACT_FLOAT64 = 254 + JSON_QUOTE = 255 + JSON_UNQUOTE = 256 + JSON_ROW = 257 + + JQ = 258 + TRY_JQ = 259 + WASM = 260 + TRY_WASM = 261 + FORMAT = 262 + SLEEP = 263 + INSTR = 264 + LOCATE = 265 + + UUID = 266 + SERIAL = 267 + SERIAL_FULL = 268 + SERIAL_EXTRACT = 269 + BIN = 270 + + ENABLE_FAULT_INJECTION = 271 + DISABLE_FAULT_INJECTION = 272 + ADD_FAULT_POINT = 273 // Add a fault point + REMOVE_FAULT_POINT = 274 // Remove + TRIGGER_FAULT_POINT = 275 // Trigger. + MO_WIN_TRUNCATE = 276 + + MO_MEMORY_USAGE = 277 // Dump memory usage + MO_ENABLE_MEMORY_USAGE_DETAIL = 278 + MO_DISABLE_MEMORY_USAGE_DETAIL = 279 // MO_CTL is used to check some internal status, and issue some ctl commands to the service. // see builtin.ctl.ctl.go to get detail. - MO_CTL + MO_CTL = 280 - MO_SHOW_VISIBLE_BIN // parse type/onUpdate/default []byte to visible string - MO_SHOW_VISIBLE_BIN_ENUM // parse type/onUpdate/default []byte to visible string for enum - MO_SHOW_COL_UNIQUE // show column whether unique key + MO_SHOW_VISIBLE_BIN = 281 // parse type/onUpdate/default []byte to visible string + MO_SHOW_VISIBLE_BIN_ENUM = 282 // parse type/onUpdate/default []byte to visible string for enum + MO_SHOW_COL_UNIQUE = 283 // show column whether unique key - MO_TABLE_ROWS // table rows - MO_TABLE_SIZE // table size - MO_TABLE_COL_MAX // table column max value - MO_TABLE_COL_MIN // table column min value + MO_TABLE_ROWS = 284 // table rows + MO_TABLE_SIZE = 285 // table size + MO_TABLE_COL_MAX = 286 // table column max value + MO_TABLE_COL_MIN = 287 // table column min value - MO_LOG_DATE // parse date from string, like __mo_filepath - PURGE_LOG // purge mo internal log, like rawlog, statement_info, metric - MO_ADMIN_NAME // get mo admin name of account - MO_CU - MO_CU_V1 - MO_EXPLAIN_PHY + MO_LOG_DATE = 288 // parse date from string, like __mo_filepath + PURGE_LOG = 289 // purge mo internal log, like rawlog, statement_info, metric + MO_ADMIN_NAME = 290 // get mo admin name of account + MO_CU = 291 + MO_CU_V1 = 292 + MO_EXPLAIN_PHY = 293 - GIT_VERSION - BUILD_VERSION + GIT_VERSION = 294 + BUILD_VERSION = 295 // be used: insert into t1 values(1,1) on duplicate key update a=values(a)+a+1 - VALUES - BINARY - INTERNAL_CHAR_LENGTH - INTERNAL_CHAR_SIZE - INTERNAL_NUMERIC_PRECISION - INTERNAL_NUMERIC_SCALE - INTERNAL_DATETIME_SCALE - INTERNAL_COLUMN_CHARACTER_SET - INTERNAL_AUTO_INCREMENT + VALUES = 296 + BINARY = 297 + INTERNAL_CHAR_LENGTH = 298 + INTERNAL_CHAR_SIZE = 299 + INTERNAL_NUMERIC_PRECISION = 300 + INTERNAL_NUMERIC_SCALE = 301 + INTERNAL_DATETIME_SCALE = 302 + INTERNAL_COLUMN_CHARACTER_SET = 303 + INTERNAL_AUTO_INCREMENT = 304 // be used: enum - CAST_INDEX_TO_VALUE - CAST_VALUE_TO_INDEX - CAST_INDEX_VALUE_TO_INDEX + CAST_INDEX_TO_VALUE = 305 + CAST_VALUE_TO_INDEX = 306 + CAST_INDEX_VALUE_TO_INDEX = 307 // be used: show snapshots - CAST_NANO_TO_TIMESTAMP + CAST_NANO_TO_TIMESTAMP = 308 // be used: show pitr - CAST_RANGE_VALUE_UNIT + CAST_RANGE_VALUE_UNIT = 309 //Sequence function - NEXTVAL - SETVAL - CURRVAL - LASTVAL + NEXTVAL = 310 + SETVAL = 311 + CURRVAL = 312 + LASTVAL = 313 // Array Function - SUMMATION - L1_NORM // L1_NORMALIZATION - L2_NORM // L2 NORMALIZATION - INNER_PRODUCT - COSINE_SIMILARITY - VECTOR_DIMS //VECTOR DIMENSIONS - NORMALIZE_L2 //NORMALIZE L2 - L2_DISTANCE //L2_DISTANCE - L2_DISTANCE_SQ //L2_DISTANCE_SQ - COSINE_DISTANCE //COSINE_DISTANCE - CLUSTER_CENTERS // CLUSTER_CENTERS - SUB_VECTOR // SUB_VECTOR - - PYTHON_UDF + SUMMATION = 314 + L1_NORM = 315 // L1_NORMALIZATION + L2_NORM = 316 // L2 NORMALIZATION + INNER_PRODUCT = 317 + COSINE_SIMILARITY = 318 + VECTOR_DIMS = 319 //VECTOR DIMENSIONS + NORMALIZE_L2 = 320 //NORMALIZE L2 + L2_DISTANCE = 321 //L2_DISTANCE + L2_DISTANCE_SQ = 322 //L2_DISTANCE_SQ + COSINE_DISTANCE = 323 //COSINE_DISTANCE + CLUSTER_CENTERS = 324 // CLUSTER_CENTERS + SUB_VECTOR = 325 // SUB_VECTOR + + PYTHON_UDF = 326 // observation function - MO_CPU - MO_MEMORY - MO_CPU_DUMP + MO_CPU = 327 + MO_MEMORY = 328 + MO_CPU_DUMP = 329 // bitmap function - BITMAP_BIT_POSITION - BITMAP_BUCKET_NUMBER - BITMAP_COUNT - BITMAP_CONSTRUCT_AGG - BITMAP_OR_AGG + BITMAP_BIT_POSITION = 330 + BITMAP_BUCKET_NUMBER = 331 + BITMAP_COUNT = 332 + BITMAP_CONSTRUCT_AGG = 333 + BITMAP_OR_AGG = 334 // fulltext function - FULLTEXT_MATCH - FULLTEXT_MATCH_SCORE + FULLTEXT_MATCH = 335 + FULLTEXT_MATCH_SCORE = 336 // FUNCTION_END_NUMBER is not a function, just a flag to record the max number of function. // TODO: every one should put the new function id in front of this one if you want to make a new function. - FUNCTION_END_NUMBER + FUNCTION_END_NUMBER = 337 ) // functionIdRegister is what function we have registered already. diff --git a/pkg/sql/plan/function/function_id_test.go b/pkg/sql/plan/function/function_id_test.go new file mode 100644 index 0000000000000..5f80094bc306d --- /dev/null +++ b/pkg/sql/plan/function/function_id_test.go @@ -0,0 +1,404 @@ +// Copyright 2021 - 2022 Matrix Origin +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package function + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +// all fixed function ids defined at 2024-12-12 +var predefinedFunids = map[int]int{ + EQUAL: 0, + NOT_EQUAL: 1, + GREAT_THAN: 2, + GREAT_EQUAL: 3, + LESS_THAN: 4, + LESS_EQUAL: 5, + BETWEEN: 6, + UNARY_PLUS: 7, + UNARY_MINUS: 8, + UNARY_TILDE: 9, + PLUS: 10, + MINUS: 11, + MULTI: 12, + DIV: 13, + INTEGER_DIV: 14, + MOD: 15, + CONCAT: 16, + AND: 17, + OR: 18, + XOR: 19, + NOT: 20, + CAST: 21, + BIT_CAST: 22, + IS: 23, + ISNOT: 24, + ISNULL: 25, + ISNOTNULL: 26, + ISTRUE: 27, + ISNOTTRUE: 28, + ISFALSE: 29, + ISNOTFALSE: 30, + ISEMPTY: 31, + NOT_IN_ROWS: 32, + OP_BIT_AND: 33, + OP_BIT_OR: 34, + OP_BIT_XOR: 35, + OP_BIT_SHIFT_LEFT: 36, + OP_BIT_SHIFT_RIGHT: 37, + + ABS: 38, + ACOS: 39, + ADDDATE: 40, + ADDTIME: 41, + AES_DECRYPT: 42, + AES_ENCRYPT: 43, + ANY_VALUE: 44, + APPROX_COUNT: 45, + ARRAY_AGG: 46, + ARRAY_APPEND: 47, + ARRAY_CAT: 48, + ARRAY_CONTAINS: 49, + ARRAY_POSITION: 50, + ARRAY_SIZE: 51, + ASCII: 52, + ASIN: 53, + ASSERT: 54, + ATAN: 55, + ATAN2: 56, + AVG: 57, + AVG_TW_CACHE: 58, + AVG_TW_RESULT: 59, + BASE64_DECODE: 60, + BASE64_ENCODE: 61, + BIT_AND: 62, + BIT_LENGTH: 63, + BIT_NOT: 64, + BIT_OR: 65, + BIT_XOR: 66, + BITAGG_AND: 67, + BITAGG_OR: 68, + BOOLAGG_AND: 69, + BOOLAGG_OR: 70, + CASE: 71, + CEIL: 72, + CHR: 73, + COALESCE: 74, + FIELD: 75, + CONCAT_WS: 76, + CONTAINS: 77, + CORR: 78, + COS: 79, + COT: 80, + CRC32: 81, + COUNT: 82, + COUNT_IF: 83, + COVAR_POP: 84, + COVAR_SAMPLE: 85, + CONVERT_TZ: 86, + CUME_DIST: 87, + CURRENT_DATE: 88, + CURRENT_TIMESTAMP: 89, + DATE_FROM_PARTS: 90, + DATE_PART: 91, + DATEADD: 92, + DATEDIFF: 93, + TIMEDIFF: 94, + TIMESTAMPDIFF: 95, + DENSE_RANK: 96, + MO_WIN_DIVISOR: 97, + EMPTY: 98, + ENDSWITH: 99, + EXP: 100, + FINDINSET: 101, + FIRST_VALUE: 102, + FLOOR: 103, + GREATEST: 104, + GROUPING: 105, + HASH: 106, + HASH_AGG: 107, + HEX_DECODE: 108, + HEX_ENCODE: 109, + HEX: 110, + UNHEX: 111, + MD5: 112, + IFF: 113, + IFNULL: 114, + ILIKE: 115, + ILIKE_ALL: 116, + ILIKE_ANY: 117, + IN: 118, + LAG: 119, + LAST_VALUE: 120, + LEAD: 121, + LEAST: 122, + LEFT: 123, + LENGTH: 124, + LENGTH_UTF8: 125, + LIKE: 126, + LIKE_ALL: 127, + LIKE_ANY: 128, + LN: 129, + NOT_IN: 130, + LOG: 131, + LOG2: 132, + LOG10: 133, + LOWER: 134, + LPAD: 135, + LTRIM: 136, + MAX: 137, + MEDIAN: 138, + MIN: 139, + MODE: 140, + MONTH: 141, + NORMAL: 142, + NTH_VALUE: 143, + NTILE: 144, + NULLIF: 145, + PERCENT_RANK: 146, + PI: 147, + POSITION: 148, + POW: 149, + PREFIX_EQ: 150, + PREFIX_IN: 151, + PREFIX_BETWEEN: 152, + RADIAN: 153, + RANDOM: 154, + RANK: 155, + REGEXP: 156, + REGEXP_INSTR: 157, + REGEXP_LIKE: 158, + REGEXP_REPLACE: 159, + REGEXP_SUBSTR: 160, + REG_MATCH: 161, + NOT_REG_MATCH: 162, + REPEAT: 163, + REPLACE: 164, + REVERSE: 165, + RIGHT: 166, + ROUND: 167, + ROW_NUMBER: 168, + RPAD: 169, + RTRIM: 170, + SIGN: 171, + SIN: 172, + SINH: 173, + SPACE: 174, + SPLIT: 175, + SPLIT_PART: 176, + SQRT: 177, + STARCOUNT: 178, + STARTSWITH: 179, + STDDEV_POP: 180, + STDDEV_SAMPLE: 181, + SUBSTR: 182, + SUM: 183, + SYSDATE: 184, + GROUP_CONCAT: 185, + TAN: 186, + TO_DATE: 187, + STR_TO_DATE: 188, + TO_INTERVAL: 189, + TRANSLATE: 190, + TRIM: 191, + UNIFORM: 192, + SHA1: 193, + SHA2: 194, + UTC_TIMESTAMP: 195, + UNIX_TIMESTAMP: 196, + FROM_UNIXTIME: 197, + UPPER: 198, + VAR_POP: 199, + VAR_SAMPLE: 200, + LAST_DAY: 201, + MAKEDATE: 202, + DATE: 203, + TIME: 204, + DAY: 205, + DAYOFYEAR: 206, + INTERVAL: 207, + EXTRACT: 208, + OCT: 209, + SUBSTRING: 210, + ENCODE: 211, + DECODE: 212, + TO_BASE64: 213, + FROM_BASE64: 214, + SUBSTRING_INDEX: 215, + WEEK: 216, + WEEKDAY: 217, + YEAR: 218, + HOUR: 219, + MINUTE: 220, + SECOND: 221, + TO_DAYS: 222, + TO_SECONDS: 223, + + DATE_ADD: 224, + DATE_SUB: 225, + APPROX_COUNT_DISTINCT: 226, + + LOAD_FILE: 227, + SAVE_FILE: 228, + DATABASE: 229, + USER: 230, + CONNECTION_ID: 231, + CHARSET: 232, + CONVERT: 233, + CURRENT_ROLE: 234, + FOUND_ROWS: 235, + ICULIBVERSION: 236, + LAST_INSERT_ID: 237, + LAST_QUERY_ID: 238, + LAST_UUID: 239, + ROLES_GRAPHML: 240, + ROW_COUNT: 241, + VERSION: 242, + COLLATION: 243, + CURRENT_ACCOUNT_ID: 244, + CURRENT_ACCOUNT_NAME: 245, + CURRENT_ROLE_ID: 246, + CURRENT_ROLE_NAME: 247, + CURRENT_USER_ID: 248, + CURRENT_USER_NAME: 249, + + TIMESTAMP: 250, + DATE_FORMAT: 251, + JSON_EXTRACT: 252, + JSON_EXTRACT_STRING: 253, + JSON_EXTRACT_FLOAT64: 254, + JSON_QUOTE: 255, + JSON_UNQUOTE: 256, + JSON_ROW: 257, + + JQ: 258, + TRY_JQ: 259, + WASM: 260, + TRY_WASM: 261, + FORMAT: 262, + SLEEP: 263, + INSTR: 264, + LOCATE: 265, + + UUID: 266, + SERIAL: 267, + SERIAL_FULL: 268, + SERIAL_EXTRACT: 269, + BIN: 270, + + ENABLE_FAULT_INJECTION: 271, + DISABLE_FAULT_INJECTION: 272, + ADD_FAULT_POINT: 273, + REMOVE_FAULT_POINT: 274, + TRIGGER_FAULT_POINT: 275, + MO_WIN_TRUNCATE: 276, + + MO_MEMORY_USAGE: 277, + MO_ENABLE_MEMORY_USAGE_DETAIL: 278, + MO_DISABLE_MEMORY_USAGE_DETAIL: 279, + + MO_CTL: 280, + + MO_SHOW_VISIBLE_BIN: 281, + MO_SHOW_VISIBLE_BIN_ENUM: 282, + MO_SHOW_COL_UNIQUE: 283, + + MO_TABLE_ROWS: 284, + MO_TABLE_SIZE: 285, + MO_TABLE_COL_MAX: 286, + MO_TABLE_COL_MIN: 287, + + MO_LOG_DATE: 288, + PURGE_LOG: 289, + MO_ADMIN_NAME: 290, + MO_CU: 291, + MO_CU_V1: 292, + MO_EXPLAIN_PHY: 293, + + GIT_VERSION: 294, + BUILD_VERSION: 295, + + VALUES: 296, + BINARY: 297, + INTERNAL_CHAR_LENGTH: 298, + INTERNAL_CHAR_SIZE: 299, + INTERNAL_NUMERIC_PRECISION: 300, + INTERNAL_NUMERIC_SCALE: 301, + INTERNAL_DATETIME_SCALE: 302, + INTERNAL_COLUMN_CHARACTER_SET: 303, + INTERNAL_AUTO_INCREMENT: 304, + + CAST_INDEX_TO_VALUE: 305, + CAST_VALUE_TO_INDEX: 306, + CAST_INDEX_VALUE_TO_INDEX: 307, + + CAST_NANO_TO_TIMESTAMP: 308, + CAST_RANGE_VALUE_UNIT: 309, + + NEXTVAL: 310, + SETVAL: 311, + CURRVAL: 312, + LASTVAL: 313, + + SUMMATION: 314, + L1_NORM: 315, + L2_NORM: 316, + INNER_PRODUCT: 317, + COSINE_SIMILARITY: 318, + VECTOR_DIMS: 319, + NORMALIZE_L2: 320, + L2_DISTANCE: 321, + L2_DISTANCE_SQ: 322, + COSINE_DISTANCE: 323, + CLUSTER_CENTERS: 324, + SUB_VECTOR: 325, + + PYTHON_UDF: 326, + + MO_CPU: 327, + MO_MEMORY: 328, + MO_CPU_DUMP: 329, + + BITMAP_BIT_POSITION: 330, + BITMAP_BUCKET_NUMBER: 331, + BITMAP_COUNT: 332, + BITMAP_CONSTRUCT_AGG: 333, + BITMAP_OR_AGG: 334, + + FULLTEXT_MATCH: 335, + FULLTEXT_MATCH_SCORE: 336, + + FUNCTION_END_NUMBER: 337, +} + +func Test_funids(t *testing.T) { + check := func(fid int) { + if _, ok := predefinedFunids[fid]; !ok { + require.Failf(t, "no functionid in 'predefinedFunids'", "put funtion id %d into 'predefinedFunids'", fid) + } else { + require.Equal(t, fid, predefinedFunids[fid]) + } + require.Greater(t, FUNCTION_END_NUMBER, fid) + } + for _, fun := range allSupportedFunctions { + check(fun.functionId) + } + + for _, fid := range functionIdRegister { + check(int(fid)) + } +}