diff --git a/ast/functions.go b/ast/functions.go index 332958253a955..bdd81485b92d6 100644 --- a/ast/functions.go +++ b/ast/functions.go @@ -290,19 +290,30 @@ const ( ValidatePasswordStrength = "validate_password_strength" // json functions - JSONType = "json_type" - JSONExtract = "json_extract" - JSONUnquote = "json_unquote" - JSONArray = "json_array" - JSONObject = "json_object" - JSONMerge = "json_merge" - JSONValid = "json_valid" - JSONSet = "json_set" - JSONInsert = "json_insert" - JSONReplace = "json_replace" - JSONRemove = "json_remove" - JSONContains = "json_contains" - JSONContainsPath = "json_contains_path" + JSONType = "json_type" + JSONExtract = "json_extract" + JSONUnquote = "json_unquote" + JSONArray = "json_array" + JSONObject = "json_object" + JSONMerge = "json_merge" + JSONSet = "json_set" + JSONInsert = "json_insert" + JSONReplace = "json_replace" + JSONRemove = "json_remove" + JSONContains = "json_contains" + JSONContainsPath = "json_contains_path" + JSONValid = "json_valid" + JSONArrayAppend = "json_array_append" + JSONArrayInsert = "json_array_insert" + JSONMergePatch = "json_merge_patch" + JSONMergePreserve = "json_merge_preserve" + JSONPretty = "json_pretty" + JSONQuote = "json_quote" + JSONSearch = "json_search" + JSONStorageSize = "json_storage_size" + JSONDepth = "json_depth" + JSONKeys = "json_keys" + JSONLength = "json_length" ) // FuncCallExpr is for function expression. diff --git a/expression/builtin.go b/expression/builtin.go index 396e550493ebf..8ddbff4f340c3 100644 --- a/expression/builtin.go +++ b/expression/builtin.go @@ -572,16 +572,28 @@ var funcs = map[string]functionClass{ ast.ValidatePasswordStrength: &validatePasswordStrengthFunctionClass{baseFunctionClass{ast.ValidatePasswordStrength, 1, 1}}, // json functions - ast.JSONType: &jsonTypeFunctionClass{baseFunctionClass{ast.JSONType, 1, 1}}, - ast.JSONExtract: &jsonExtractFunctionClass{baseFunctionClass{ast.JSONExtract, 2, -1}}, - ast.JSONUnquote: &jsonUnquoteFunctionClass{baseFunctionClass{ast.JSONUnquote, 1, 1}}, - ast.JSONSet: &jsonSetFunctionClass{baseFunctionClass{ast.JSONSet, 3, -1}}, - ast.JSONInsert: &jsonInsertFunctionClass{baseFunctionClass{ast.JSONInsert, 3, -1}}, - ast.JSONReplace: &jsonReplaceFunctionClass{baseFunctionClass{ast.JSONReplace, 3, -1}}, - ast.JSONRemove: &jsonRemoveFunctionClass{baseFunctionClass{ast.JSONRemove, 2, -1}}, - ast.JSONMerge: &jsonMergeFunctionClass{baseFunctionClass{ast.JSONMerge, 2, -1}}, - ast.JSONObject: &jsonObjectFunctionClass{baseFunctionClass{ast.JSONObject, 0, -1}}, - ast.JSONArray: &jsonArrayFunctionClass{baseFunctionClass{ast.JSONArray, 0, -1}}, - ast.JSONContains: &jsonContainsFunctionClass{baseFunctionClass{ast.JSONContains, 2, 3}}, - ast.JSONContainsPath: &jsonContainsPathFunctionClass{baseFunctionClass{ast.JSONContainsPath, 3, -1}}, + ast.JSONType: &jsonTypeFunctionClass{baseFunctionClass{ast.JSONType, 1, 1}}, + ast.JSONExtract: &jsonExtractFunctionClass{baseFunctionClass{ast.JSONExtract, 2, -1}}, + ast.JSONUnquote: &jsonUnquoteFunctionClass{baseFunctionClass{ast.JSONUnquote, 1, 1}}, + ast.JSONSet: &jsonSetFunctionClass{baseFunctionClass{ast.JSONSet, 3, -1}}, + ast.JSONInsert: &jsonInsertFunctionClass{baseFunctionClass{ast.JSONInsert, 3, -1}}, + ast.JSONReplace: &jsonReplaceFunctionClass{baseFunctionClass{ast.JSONReplace, 3, -1}}, + ast.JSONRemove: &jsonRemoveFunctionClass{baseFunctionClass{ast.JSONRemove, 2, -1}}, + ast.JSONMerge: &jsonMergeFunctionClass{baseFunctionClass{ast.JSONMerge, 2, -1}}, + ast.JSONObject: &jsonObjectFunctionClass{baseFunctionClass{ast.JSONObject, 0, -1}}, + ast.JSONArray: &jsonArrayFunctionClass{baseFunctionClass{ast.JSONArray, 0, -1}}, + ast.JSONContains: &jsonContainsFunctionClass{baseFunctionClass{ast.JSONContains, 2, 3}}, + ast.JSONContainsPath: &jsonContainsPathFunctionClass{baseFunctionClass{ast.JSONContainsPath, 3, -1}}, + ast.JSONValid: &jsonValidFunctionClass{baseFunctionClass{ast.JSONValid, 1, 1}}, + ast.JSONArrayAppend: &jsonArrayAppendFunctionClass{baseFunctionClass{ast.JSONArrayAppend, 3, -1}}, + ast.JSONArrayInsert: &jsonArrayInsertFunctionClass{baseFunctionClass{ast.JSONArrayInsert, 3, -1}}, + ast.JSONMergePatch: &jsonMergePatchFunctionClass{baseFunctionClass{ast.JSONMergePatch, 2, -1}}, + ast.JSONMergePreserve: &jsonMergePreserveFunctionClass{baseFunctionClass{ast.JSONMergePreserve, 2, -1}}, + ast.JSONPretty: &jsonPrettyFunctionClass{baseFunctionClass{ast.JSONPretty, 1, 1}}, + ast.JSONQuote: &jsonQuoteFunctionClass{baseFunctionClass{ast.JSONQuote, 1, 1}}, + ast.JSONSearch: &jsonSearchFunctionClass{baseFunctionClass{ast.JSONSearch, 3, -1}}, + ast.JSONStorageSize: &jsonStorageSizeFunctionClass{baseFunctionClass{ast.JSONStorageSize, 1, 1}}, + ast.JSONDepth: &jsonDepthFunctionClass{baseFunctionClass{ast.JSONDepth, 1, 1}}, + ast.JSONKeys: &jsonKeysFunctionClass{baseFunctionClass{ast.JSONKeys, 1, 2}}, + ast.JSONLength: &jsonLengthFunctionClass{baseFunctionClass{ast.JSONLength, 1, 2}}, } diff --git a/expression/builtin_json.go b/expression/builtin_json.go index 3a16eb7684abd..4926fe5c2e731 100644 --- a/expression/builtin_json.go +++ b/expression/builtin_json.go @@ -37,6 +37,18 @@ var ( _ functionClass = &jsonArrayFunctionClass{} _ functionClass = &jsonContainsFunctionClass{} _ functionClass = &jsonContainsPathFunctionClass{} + _ functionClass = &jsonValidFunctionClass{} + _ functionClass = &jsonArrayAppendFunctionClass{} + _ functionClass = &jsonArrayInsertFunctionClass{} + _ functionClass = &jsonMergePatchFunctionClass{} + _ functionClass = &jsonMergePreserveFunctionClass{} + _ functionClass = &jsonPrettyFunctionClass{} + _ functionClass = &jsonQuoteFunctionClass{} + _ functionClass = &jsonSearchFunctionClass{} + _ functionClass = &jsonStorageSizeFunctionClass{} + _ functionClass = &jsonDepthFunctionClass{} + _ functionClass = &jsonKeysFunctionClass{} + _ functionClass = &jsonLengthFunctionClass{} // Type of JSON value. _ builtinFunc = &builtinJSONTypeSig{} @@ -678,3 +690,99 @@ func (b *builtinJSONContainsSig) evalInt(row chunk.Row) (res int64, isNull bool, } return 0, false, nil } + +type jsonValidFunctionClass struct { + baseFunctionClass +} + +func (c *jsonValidFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_VALID") +} + +type jsonArrayAppendFunctionClass struct { + baseFunctionClass +} + +func (c *jsonArrayAppendFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_ARRAY_APPEND") +} + +type jsonArrayInsertFunctionClass struct { + baseFunctionClass +} + +func (c *jsonArrayInsertFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_ARRAY_INSERT") +} + +type jsonMergePatchFunctionClass struct { + baseFunctionClass +} + +func (c *jsonMergePatchFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_MERGE_PATCH") +} + +type jsonMergePreserveFunctionClass struct { + baseFunctionClass +} + +func (c *jsonMergePreserveFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_MERGE_PRESERVE") +} + +type jsonPrettyFunctionClass struct { + baseFunctionClass +} + +func (c *jsonPrettyFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_PRETTY") +} + +type jsonQuoteFunctionClass struct { + baseFunctionClass +} + +func (c *jsonQuoteFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_QUOTE") +} + +type jsonSearchFunctionClass struct { + baseFunctionClass +} + +func (c *jsonSearchFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_SEARCH") +} + +type jsonStorageSizeFunctionClass struct { + baseFunctionClass +} + +func (c *jsonStorageSizeFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_STORAGE_SIZE") +} + +type jsonDepthFunctionClass struct { + baseFunctionClass +} + +func (c *jsonDepthFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_DEPTH") +} + +type jsonKeysFunctionClass struct { + baseFunctionClass +} + +func (c *jsonKeysFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_KEYS") +} + +type jsonLengthFunctionClass struct { + baseFunctionClass +} + +func (c *jsonLengthFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { + return nil, errFunctionNotExists.GenByArgs("FUNCTION", "JSON_LENGTH") +}