1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-07 03:22:57 +03:00

MDEV-32854: Make JSON_DEPTH_LIMIT unlimited

This patch is the columnstore-part of the task. Columnstore wanted to have
previous 32 depth, so this patch aims at keeping the compatibility.
This commit is contained in:
Rucha Deodhar
2025-05-22 15:42:12 +05:30
parent 9ab6330ef7
commit f4dfde6992
26 changed files with 526 additions and 113 deletions

View File

@@ -354,25 +354,25 @@ void FunctionColumn::unserialize(messageqcpp::ByteStream& b)
fFunctor = fDynamicFunctor = new Func_json_contains(); fFunctor = fDynamicFunctor = new Func_json_contains();
if (dynamic_cast<Func_json_array_append*>(fFunctor)) if (dynamic_cast<Func_json_array_append*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_array_append(); fFunctor = fDynamicFunctor = new Func_json_array_append(fFunctionParms.size());
if (dynamic_cast<Func_json_array_insert*>(fFunctor)) if (dynamic_cast<Func_json_array_insert*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_array_insert(); fFunctor = fDynamicFunctor = new Func_json_array_insert(fFunctionParms.size());
if (auto f = dynamic_cast<Func_json_insert*>(fFunctor)) if (auto f = dynamic_cast<Func_json_insert*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_insert(f->getMode()); fFunctor = fDynamicFunctor = new Func_json_insert(f->getMode());
if (dynamic_cast<Func_json_remove*>(fFunctor)) if (dynamic_cast<Func_json_remove*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_remove(); fFunctor = fDynamicFunctor = new Func_json_remove(fFunctionParms.size());
if (dynamic_cast<Func_json_contains_path*>(fFunctor)) if (dynamic_cast<Func_json_contains_path*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_contains_path(); fFunctor = fDynamicFunctor = new Func_json_contains_path(fFunctionParms.size());
if (dynamic_cast<Func_json_search*>(fFunctor)) if (dynamic_cast<Func_json_search*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_search(); fFunctor = fDynamicFunctor = new Func_json_search(fFunctionParms.size());
if (dynamic_cast<Func_json_extract*>(fFunctor)) if (dynamic_cast<Func_json_extract*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_extract(); fFunctor = fDynamicFunctor = new Func_json_extract(fFunctionParms.size());
} }
bool FunctionColumn::operator==(const FunctionColumn& t) const bool FunctionColumn::operator==(const FunctionColumn& t) const

View File

@@ -28,7 +28,6 @@ string Func_json_array_append::getStrVal(rowgroup::Row& row, FunctionParm& fp, b
return ""; return "";
const CHARSET_INFO* cs = getCharset(fp[0]); const CHARSET_INFO* cs = getCharset(fp[0]);
json_engine_t jsEg; json_engine_t jsEg;
const uchar* arrEnd; const uchar* arrEnd;
size_t strRestLen; size_t strRestLen;
@@ -37,6 +36,16 @@ string Func_json_array_append::getStrVal(rowgroup::Row& row, FunctionParm& fp, b
initJSPaths(paths, fp, 1, 2); initJSPaths(paths, fp, 1, 2);
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
for (size_t i=0; i<paths.size(); i++)
{
JSONPath& path = paths[i];
initJsonArray(&path.p.steps, sizeof(json_path_step_t), &p_steps_arr[i]);
}
#endif
utils::NullString tmpJS(js); utils::NullString tmpJS(js);
for (size_t i = 1, j = 0; i < fp.size(); i += 2, j++) for (size_t i = 1, j = 0; i < fp.size(); i += 2, j++)
{ {

View File

@@ -1,6 +1,8 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "constantcolumn.h" #include "constantcolumn.h"
#include "json_lib.h"
#include "my_sys.h"
using namespace execplan; using namespace execplan;
#include "rowgroup.h" #include "rowgroup.h"
@@ -31,10 +33,21 @@ string Func_json_array_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, b
json_engine_t jsEg; json_engine_t jsEg;
string retJS; string retJS;
retJS.reserve(js.length() + 8);
retJS.reserve(js.length() + 8);
initJSPaths(paths, fp, 1, 2); initJSPaths(paths, fp, 1, 2);
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
for (size_t i=0; i<paths.size(); i++)
{
JSONPath& path = paths[i];
initJsonArray(&path.p.steps, sizeof(json_path_step_t), &p_steps_arr[i]);
}
#endif
utils::NullString tmpJS(js); utils::NullString tmpJS(js);
for (size_t i = 1, j = 0; i < fp.size(); i += 2, j++) for (size_t i = 1, j = 0; i < fp.size(); i += 2, j++)
{ {
@@ -43,19 +56,34 @@ string Func_json_array_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, b
JSONPath& path = paths[j]; JSONPath& path = paths[j];
if (!path.parsed) if (!path.parsed)
{ {
if (parseJSPath(path, row, fp[i]) || path.p.last_step - 1 < path.p.steps || #if MYSQL_VERSION_ID >= 120100
json_path_step_t *last_step= reinterpret_cast<json_path_step_t*>(mem_root_dynamic_array_get_val(&path.p.steps, path.p.last_step_idx)),
*initial_step= reinterpret_cast<json_path_step_t*>(path.p.steps.buffer);
#endif
#if MYSQL_VERSION_ID >= 120100
if (parseJSPath(path, row, fp[i]) || (last_step - 1) < initial_step ||
last_step->type != JSON_PATH_ARRAY)
#else
if (parseJSPath(path, row, fp[i]) || path.p.last_step - 1 < path.p.steps ||
path.p.last_step->type != JSON_PATH_ARRAY) path.p.last_step->type != JSON_PATH_ARRAY)
#endif
{ {
if (path.p.s.error == 0) if (path.p.s.error == 0)
path.p.s.error = SHOULD_END_WITH_ARRAY; path.p.s.error = SHOULD_END_WITH_ARRAY;
goto error; goto error;
} }
#if MYSQL_VERSION_ID >= 120100
path.p.last_step_idx--;
#else
path.p.last_step--; path.p.last_step--;
#endif
} }
initJSEngine(jsEg, cs, tmpJS); initJSEngine(jsEg, cs, tmpJS);
#if MYSQL_VERSION_ID < 120100
path.currStep = path.p.steps; path.currStep = path.p.steps;
#endif
int jsErr = 0; int jsErr = 0;
if (locateJSPath(jsEg, path, &jsErr)) if (locateJSPath(jsEg, path, &jsErr))
@@ -82,7 +110,13 @@ string Func_json_array_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, b
while (json_scan_next(&jsEg) == 0 && jsEg.state != JST_ARRAY_END) while (json_scan_next(&jsEg) == 0 && jsEg.state != JST_ARRAY_END)
{ {
DBUG_ASSERT(jsEg.state == JST_VALUE); DBUG_ASSERT(jsEg.state == JST_VALUE);
#if MYSQL_VERSION_ID >= 120100
if (itemSize == ((reinterpret_cast<json_path_step_t*>
(mem_root_dynamic_array_get_val(&path.p.steps,
path.p.last_step_idx)))[1].n_item))
#else
if (itemSize == path.p.last_step[1].n_item) if (itemSize == path.p.last_step[1].n_item)
#endif
{ {
itemPos = (const char*)jsEg.s.c_str; itemPos = (const char*)jsEg.s.c_str;
break; break;

View File

@@ -1,6 +1,7 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "constantcolumn.h" #include "constantcolumn.h"
#include "json_lib.h"
#include "rowgroup.h" #include "rowgroup.h"
using namespace execplan; using namespace execplan;
using namespace rowgroup; using namespace rowgroup;
@@ -160,6 +161,10 @@ bool Func_json_contains::getBoolVal(Row& row, FunctionParm& fp, bool& isNull,
CalpontSystemCatalog::ColType& /*type*/) CalpontSystemCatalog::ColType& /*type*/)
{ {
bool isNullJS = false, isNullVal = false; bool isNullJS = false, isNullVal = false;
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT], valEg_stack[JSON_DEPTH_LIMIT];
#endif
const auto& js = fp[0]->data()->getStrVal(row, isNullJS); const auto& js = fp[0]->data()->getStrVal(row, isNullJS);
const auto& val = fp[1]->data()->getStrVal(row, isNullVal); const auto& val = fp[1]->data()->getStrVal(row, isNullVal);
if (isNullJS || isNullVal) if (isNullJS || isNullVal)
@@ -182,6 +187,9 @@ bool Func_json_contains::getBoolVal(Row& row, FunctionParm& fp, bool& isNull,
} }
json_engine_t jsEg; json_engine_t jsEg;
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSEngine(jsEg, getCharset(fp[0]), js); initJSEngine(jsEg, getCharset(fp[0]), js);
if (fp.size() > 2) if (fp.size() > 2)
@@ -194,6 +202,9 @@ bool Func_json_contains::getBoolVal(Row& row, FunctionParm& fp, bool& isNull,
} }
json_engine_t valEg; json_engine_t valEg;
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&valEg.stack, sizeof(int), &valEg_stack);
#endif
initJSEngine(valEg, getCharset(fp[1]), arg2Val); initJSEngine(valEg, getCharset(fp[1]), arg2Val);
if (json_read_value(&jsEg) || json_read_value(&valEg)) if (json_read_value(&jsEg) || json_read_value(&valEg))

View File

@@ -17,7 +17,7 @@ using namespace funcexp::helpers;
namespace funcexp namespace funcexp
{ {
CalpontSystemCatalog::ColType Func_json_contains_path::operationType( CalpontSystemCatalog::ColType Func_json_contains_path::operationType(
FunctionParm& fp, CalpontSystemCatalog::ColType& /*resultType*/) FunctionParm& fp, [[maybe_unused]] CalpontSystemCatalog::ColType& resultType)
{ {
return fp[0]->data()->resultType(); return fp[0]->data()->resultType();
} }
@@ -26,7 +26,7 @@ CalpontSystemCatalog::ColType Func_json_contains_path::operationType(
* getBoolVal API definition * getBoolVal API definition
*/ */
bool Func_json_contains_path::getBoolVal(Row& row, FunctionParm& fp, bool& isNull, bool Func_json_contains_path::getBoolVal(Row& row, FunctionParm& fp, bool& isNull,
CalpontSystemCatalog::ColType& /*type*/) [[maybe_unused]] CalpontSystemCatalog::ColType& type)
{ {
const auto& js_ns = fp[0]->data()->getStrVal(row, isNull); const auto& js_ns = fp[0]->data()->getStrVal(row, isNull);
if (isNull) if (isNull)
@@ -62,6 +62,15 @@ bool Func_json_contains_path::getBoolVal(Row& row, FunctionParm& fp, bool& isNul
} }
initJSPaths(paths, fp, 2, 1); initJSPaths(paths, fp, 2, 1);
#if MYSQL_VERSION_ID >= 120100
for (size_t i=0; i<paths.size(); i++)
{
JSONPath& path = paths[i];
initJsonArray(&path.p.steps, sizeof(json_path_step_t), &p_steps_arr[i]);
}
#endif
if (paths.size() == 0) if (paths.size() == 0)
hasFound.assign(argSize, false); hasFound.assign(argSize, false);
@@ -84,6 +93,15 @@ bool Func_json_contains_path::getBoolVal(Row& row, FunctionParm& fp, bool& isNul
json_engine_t jsEg; json_engine_t jsEg;
json_path_t p; json_path_t p;
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
json_path_step_t p_steps[JSON_DEPTH_LIMIT];
initJsonArray(&p.steps, sizeof(json_path_step_t), &p_steps);
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
json_get_path_start(&jsEg, getCharset(fp[0]), (const uchar*)js.data(), (const uchar*)js.data() + js.size(), json_get_path_start(&jsEg, getCharset(fp[0]), (const uchar*)js.data(), (const uchar*)js.data() + js.size(),
&p); &p);
@@ -99,12 +117,20 @@ bool Func_json_contains_path::getBoolVal(Row& row, FunctionParm& fp, bool& isNul
while (json_get_path_next(&jsEg, &p) == 0) while (json_get_path_next(&jsEg, &p) == 0)
{ {
#if MYSQL_VERSION_ID >= 100900 #if MYSQL_VERSION_ID >= 100900
#if MYSQL_VERSION_ID >= 120100
json_path_step_t *last_step= reinterpret_cast<json_path_step_t*>
(mem_root_dynamic_array_get_val(&p.steps,
p.last_step_idx));
if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY &&
json_skip_array_and_count(&jsEg, arrayCounters + (last_step - reinterpret_cast<json_path_step_t*>(p.steps.buffer))))
#else
if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY && if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY &&
json_skip_array_and_count(&jsEg, arrayCounters + (p.last_step - p.steps))) json_skip_array_and_count(&jsEg, arrayCounters + (p.last_step - p.steps)))
{ {
result = true; result = true;
break; break;
} }
#endif
#endif #endif
for (int restSize = argSize, curr = 0; restSize > 0; restSize--, curr++) for (int restSize = argSize, curr = 0; restSize > 0; restSize--, curr++)

View File

@@ -1,5 +1,6 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "json_lib.h"
using namespace execplan; using namespace execplan;
#include "rowgroup.h" #include "rowgroup.h"
@@ -28,8 +29,12 @@ int64_t Func_json_depth::getIntVal(rowgroup::Row& row, FunctionParm& fp, bool& i
int depth = 0, currDepth = 0; int depth = 0, currDepth = 0;
bool incDepth = true; bool incDepth = true;
json_engine_t jsEg; json_engine_t jsEg;
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSEngine(jsEg, getCharset(fp[0]), js); initJSEngine(jsEg, getCharset(fp[0]), js);
do do

View File

@@ -27,6 +27,16 @@ CalpontSystemCatalog::ColType Func_json_equals::operationType(FunctionParm& fp,
bool Func_json_equals::getBoolVal(Row& row, FunctionParm& fp, bool& isNull, bool Func_json_equals::getBoolVal(Row& row, FunctionParm& fp, bool& isNull,
CalpontSystemCatalog::ColType& /*type*/) CalpontSystemCatalog::ColType& /*type*/)
{ {
#if MYSQL_VERSION_ID >= 120100
json_engine_t je;
MEM_ROOT_DYNAMIC_ARRAY array;
int je_stack[JSON_DEPTH_LIMIT];
struct json_norm_value *buffer_array[JSON_DEPTH_LIMIT];
initJsonArray(&je.stack, sizeof(int), &je_stack);
initJsonArray(&array, sizeof(struct json_norm_value*), buffer_array);
#endif
// auto release the DYNAMIC_STRING // auto release the DYNAMIC_STRING
using DynamicString = unique_ptr<DYNAMIC_STRING, decltype(&dynstr_free)>; using DynamicString = unique_ptr<DYNAMIC_STRING, decltype(&dynstr_free)>;
@@ -56,13 +66,22 @@ bool Func_json_equals::getBoolVal(Row& row, FunctionParm& fp, bool& isNull,
const string_view js2 = js2_ns.unsafeStringRef(); const string_view js2 = js2_ns.unsafeStringRef();
bool result = false; bool result = false;
#if MYSQL_VERSION_ID >= 120100
if (json_normalize(str1.get(), js1.data(), js1.size(), getCharset(fp[0]), NULL, &je, &array))
#else
if (json_normalize(str1.get(), js1.data(), js1.size(), getCharset(fp[0]))) if (json_normalize(str1.get(), js1.data(), js1.size(), getCharset(fp[0])))
#endif
{ {
isNull = true; isNull = true;
return result; return result;
} }
#if MYSQL_VERSION_ID >= 120100
if (json_normalize(str2.get(), js2.data(), js2.size(), getCharset(fp[1]), NULL, &je, &array))
#else
if (json_normalize(str2.get(), js2.data(), js2.size(), getCharset(fp[1]))) if (json_normalize(str2.get(), js2.data(), js2.size(), getCharset(fp[1])))
#endif
{ {
isNull = true; isNull = true;
return result; return result;

View File

@@ -1,6 +1,7 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "constantcolumn.h" #include "constantcolumn.h"
#include "json_lib.h"
#include "rowgroup.h" #include "rowgroup.h"
using namespace execplan; using namespace execplan;
using namespace rowgroup; using namespace rowgroup;
@@ -30,8 +31,13 @@ bool Func_json_exists::getBoolVal(Row& row, FunctionParm& fp, bool& isNull,
int jsErr = 0; int jsErr = 0;
json_engine_t jsEg; json_engine_t jsEg;
initJSEngine(jsEg, getCharset(fp[0]), js);
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSEngine(jsEg, getCharset(fp[0]), js);
if (!path.parsed && parseJSPath(path, row, fp[1])) if (!path.parsed && parseJSPath(path, row, fp[1]))
goto error; goto error;

View File

@@ -38,6 +38,21 @@ int Func_json_extract::doExtract(Row& row, FunctionParm& fp, json_value_types* t
initJSPaths(paths, fp, 1, 1); initJSPaths(paths, fp, 1, 1);
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT], savJSEg_stack[JSON_DEPTH_LIMIT];
json_path_step_t p_steps[JSON_DEPTH_LIMIT];
initJsonArray(&p.steps, sizeof(json_path_step_t), &p_steps);
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
initJsonArray(&savJSEg.stack, sizeof(int), &savJSEg_stack);
for (size_t i=0; i<paths.size(); i++)
{
JSONPath& path = paths[i];
initJsonArray(&path.p.steps, sizeof(json_path_step_t), &p_steps_arr[i]);
}
#endif
for (size_t i = 1; i < argSize; i++) for (size_t i = 1; i < argSize; i++)
{ {
JSONPath& path = paths[i - 1]; JSONPath& path = paths[i - 1];
@@ -71,8 +86,14 @@ int Func_json_extract::doExtract(Row& row, FunctionParm& fp, json_value_types* t
while (json_get_path_next(&jsEg, &p) == 0) while (json_get_path_next(&jsEg, &p) == 0)
{ {
#if MYSQL_VERSION_ID >= 100900 #if MYSQL_VERSION_ID >= 100900
#if MYSQL_VERSION_ID >= 120100
json_path_step_t *last_step= reinterpret_cast<json_path_step_t*>(mem_root_dynamic_array_get_val(&p.steps, p.last_step_idx));
if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY && if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY &&
json_skip_array_and_count(&jsEg, arrayCounter + (p.last_step - p.steps))) json_skip_array_and_count(&jsEg, arrayCounter + (last_step - reinterpret_cast<json_path_step_t*>(p.steps.buffer))))
#else
if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY &&
json_skip_array_and_count(&jsEg, arrayCounter + (last_step - reinterpret_cast<json_path_step_t*>(p.steps.buffer))))
#endif
return 1; return 1;
#endif #endif

View File

@@ -47,7 +47,15 @@ string Func_json_format::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
} }
json_engine_t jsEg; json_engine_t jsEg;
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack [JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSEngine(jsEg, getCharset(fp[0]), js); initJSEngine(jsEg, getCharset(fp[0]), js);
string ret; string ret;
if (doFormat(&jsEg, ret, fmt, tabSize)) if (doFormat(&jsEg, ret, fmt, tabSize))
{ {

View File

@@ -1,6 +1,7 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "constantcolumn.h" #include "constantcolumn.h"
#include "json_lib.h"
using namespace execplan; using namespace execplan;
#include "rowgroup.h" #include "rowgroup.h"
@@ -30,6 +31,10 @@ string Func_json_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
const bool isInsertMode = mode == INSERT || mode == SET; const bool isInsertMode = mode == INSERT || mode == SET;
const bool isReplaceMode = mode == REPLACE || mode == SET; const bool isReplaceMode = mode == REPLACE || mode == SET;
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
#endif
json_engine_t jsEg; json_engine_t jsEg;
int jsErr = 0; int jsErr = 0;
@@ -37,6 +42,10 @@ string Func_json_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
const CHARSET_INFO* cs = getCharset(fp[0]); const CHARSET_INFO* cs = getCharset(fp[0]);
json_string_set_cs(&keyName, cs); json_string_set_cs(&keyName, cs);
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSPaths(paths, fp, 1, 2); initJSPaths(paths, fp, 1, 2);
// Save the result of each merge and the result of the final merge separately // Save the result of each merge and the result of the final merge separately
@@ -46,8 +55,12 @@ string Func_json_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
{ {
const char* rawJS = tmpJS.str(); const char* rawJS = tmpJS.str();
const size_t jsLen = tmpJS.length(); const size_t jsLen = tmpJS.length();
JSONPath& path = paths[j]; JSONPath& path = paths[j];
#if MYSQL_VERSION_ID >= 120100
json_path_step_t *curr_last_step= nullptr;
#endif
const json_path_step_t* lastStep; const json_path_step_t* lastStep;
const char* valEnd; const char* valEnd;
@@ -56,14 +69,29 @@ string Func_json_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
if (parseJSPath(path, row, fp[i], false)) if (parseJSPath(path, row, fp[i], false))
goto error; goto error;
#if MYSQL_VERSION_ID >= 120100
path.p.last_step_idx--;
#else
path.p.last_step--; path.p.last_step--;
#endif
} }
initJSEngine(jsEg, cs, tmpJS); initJSEngine(jsEg, cs, tmpJS);
#if MYSQL_VERSION_ID >= 120100
if ((reinterpret_cast<json_path_step_t*>(mem_root_dynamic_array_get_val(&path.p.steps,
path.p.last_step_idx))) < reinterpret_cast<json_path_step_t*>(path.p.steps.buffer))
#else
if (path.p.last_step < path.p.steps) if (path.p.last_step < path.p.steps)
#endif
goto v_found; goto v_found;
#if MYSQL_VERSION_ID >= 120100
curr_last_step= reinterpret_cast<json_path_step_t*>(mem_root_dynamic_array_get_val(&path.p.steps,
path.p.last_step_idx));
if (curr_last_step >= reinterpret_cast<json_path_step_t*>(path.p.steps.buffer) && locateJSPath(jsEg, path, &jsErr))
#else
if (path.p.last_step >= path.p.steps && locateJSPath(jsEg, path, &jsErr)) if (path.p.last_step >= path.p.steps && locateJSPath(jsEg, path, &jsErr))
#endif
{ {
if (jsErr) if (jsErr)
goto error; goto error;
@@ -73,7 +101,12 @@ string Func_json_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
if (json_read_value(&jsEg)) if (json_read_value(&jsEg))
goto error; goto error;
#if MYSQL_VERSION_ID >= 120100
lastStep = curr_last_step + 1;
#else
lastStep = path.p.last_step + 1; lastStep = path.p.last_step + 1;
#endif
if (lastStep->type & JSON_PATH_ARRAY) if (lastStep->type & JSON_PATH_ARRAY)
{ {
IntType itemSize = 0; IntType itemSize = 0;

View File

@@ -61,8 +61,14 @@ string Func_json_keys::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isN
IntType keySize = 0; IntType keySize = 0;
string ret; string ret;
json_engine_t jsEg; json_engine_t jsEg;
initJSEngine(jsEg, getCharset(fp[0]), js);
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
memset(&jsEg_stack[0], 0, sizeof(jsEg_stack));
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSEngine(jsEg, getCharset(fp[0]), js);
if (fp.size() > 1) if (fp.size() > 1)
{ {
if (!path.parsed && parseJSPath(path, row, fp[1], false)) if (!path.parsed && parseJSPath(path, row, fp[1], false))

View File

@@ -1,6 +1,7 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "constantcolumn.h" #include "constantcolumn.h"
#include "json_lib.h"
using namespace execplan; using namespace execplan;
#include "rowgroup.h" #include "rowgroup.h"
@@ -31,6 +32,11 @@ int64_t Func_json_length::getIntVal(rowgroup::Row& row, FunctionParm& fp, bool&
int length = 0; int length = 0;
int err; int err;
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSEngine(jsEg, getCharset(fp[0]), js); initJSEngine(jsEg, getCharset(fp[0]), js);
if (fp.size() > 1) if (fp.size() > 1)

View File

@@ -1,5 +1,6 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "json_lib.h"
using namespace execplan; using namespace execplan;
#include "rowgroup.h" #include "rowgroup.h"
@@ -225,6 +226,13 @@ string Func_json_merge::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& is
json_engine_t jsEg1, jsEg2; json_engine_t jsEg1, jsEg2;
#if MYSQL_VERSION_ID >= 120100
int jsEg1_stack[JSON_DEPTH_LIMIT], jsEg2_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg1.stack, sizeof(int), &jsEg1_stack);
initJsonArray(&jsEg2.stack, sizeof(int), &jsEg2_stack);
#endif
utils::NullString tmpJS(js); utils::NullString tmpJS(js);
string retJS; string retJS;

View File

@@ -1,5 +1,6 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "json_lib.h"
using namespace execplan; using namespace execplan;
#include "rowgroup.h" #include "rowgroup.h"
@@ -277,6 +278,9 @@ string Func_json_merge_patch::getStrVal(rowgroup::Row& row, FunctionParm& fp, bo
json_engine_t jsEg1, jsEg2; json_engine_t jsEg1, jsEg2;
jsEg1.s.error = jsEg2.s.error = 0; jsEg1.s.error = jsEg2.s.error = 0;
#if MYSQL_VERSION_ID >= 120100
int jsEg1_stack[JSON_DEPTH_LIMIT], jsEg2_stack[JSON_DEPTH_LIMIT];
#endif
utils::NullString tmpJS(js); utils::NullString tmpJS(js);
string retJS; string retJS;
@@ -290,6 +294,10 @@ string Func_json_merge_patch::getStrVal(rowgroup::Row& row, FunctionParm& fp, bo
goto next; goto next;
} }
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&jsEg2.stack, sizeof(int), &jsEg2_stack);
#endif
initJSEngine(jsEg2, getCharset(fp[i]), js2); initJSEngine(jsEg2, getCharset(fp[i]), js2);
if (hasNullArg) if (hasNullArg)
@@ -304,6 +312,10 @@ string Func_json_merge_patch::getStrVal(rowgroup::Row& row, FunctionParm& fp, bo
goto next; goto next;
} }
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&jsEg1.stack, sizeof(int), &jsEg1_stack);
#endif
initJSEngine(jsEg1, getCharset(fp[0]), tmpJS); initJSEngine(jsEg1, getCharset(fp[0]), tmpJS);
if (doMergePatch(retJS, &jsEg1, &jsEg2, isEmpty)) if (doMergePatch(retJS, &jsEg1, &jsEg2, isEmpty))
{ {

View File

@@ -25,6 +25,16 @@ CalpontSystemCatalog::ColType Func_json_normalize::operationType(
string Func_json_normalize::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull, string Func_json_normalize::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& /*type*/) execplan::CalpontSystemCatalog::ColType& /*type*/)
{ {
#if MYSQL_VERSION_ID >= 120100
json_engine_t je;
MEM_ROOT_DYNAMIC_ARRAY array;
int je_stack[JSON_DEPTH_LIMIT];
struct json_norm_value *buffer_array[JSON_DEPTH_LIMIT];
initJsonArray(&je.stack, sizeof(int), &je_stack);
initJsonArray(&array, sizeof(struct json_norm_value*), buffer_array);
#endif
const auto js_ns = fp[0]->data()->getStrVal(row, isNull); const auto js_ns = fp[0]->data()->getStrVal(row, isNull);
if (isNull) if (isNull)
return ""; return "";
@@ -36,7 +46,11 @@ string Func_json_normalize::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool
if (init_dynamic_string(str.get(), NULL, 0, 0)) if (init_dynamic_string(str.get(), NULL, 0, 0))
goto error; goto error;
#if MYSQL_VERSION_ID >= 120100
if (json_normalize(str.get(), js.data(), js.size(), getCharset(fp[0]), NULL, &je, &array))
#else
if (json_normalize(str.get(), js.data(), js.size(), getCharset(fp[0]))) if (json_normalize(str.get(), js.data(), js.size(), getCharset(fp[0])))
#endif
goto error; goto error;
return str->str; return str->str;

View File

@@ -1,5 +1,6 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "json_lib.h"
#include "rowgroup.h" #include "rowgroup.h"
using namespace execplan; using namespace execplan;
using namespace rowgroup; using namespace rowgroup;
@@ -279,12 +280,23 @@ bool Func_json_overlaps::getBoolVal(Row& row, FunctionParm& fp, bool& /*isNull*/
CalpontSystemCatalog::ColType& /*type*/) CalpontSystemCatalog::ColType& /*type*/)
{ {
bool isNullJS1 = false, isNullJS2 = false; bool isNullJS1 = false, isNullJS2 = false;
#if MYSQL_VERSION_ID >= 120100
int jsEg1_stack[JSON_DEPTH_LIMIT], jsEg2_stack[JSON_DEPTH_LIMIT];
#endif
const auto js1 = fp[0]->data()->getStrVal(row, isNullJS1); const auto js1 = fp[0]->data()->getStrVal(row, isNullJS1);
const auto js2 = fp[1]->data()->getStrVal(row, isNullJS2); const auto js2 = fp[1]->data()->getStrVal(row, isNullJS2);
if (isNullJS1 || isNullJS2) if (isNullJS1 || isNullJS2)
return false; return false;
json_engine_t jsEg1, jsEg2; json_engine_t jsEg1, jsEg2;
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&jsEg1.stack, sizeof(int), &jsEg1_stack);
initJsonArray(&jsEg2.stack, sizeof(int), &jsEg2_stack);
#endif
initJSEngine(jsEg1, getCharset(fp[0]), js1); initJSEngine(jsEg1, getCharset(fp[0]), js1);
initJSEngine(jsEg2, getCharset(fp[1]), js2); initJSEngine(jsEg2, getCharset(fp[1]), js2);

View File

@@ -29,7 +29,6 @@ string Func_json_remove::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
return ""; return "";
json_engine_t jsEg; json_engine_t jsEg;
int jsErr = 0; int jsErr = 0;
json_string_t keyName; json_string_t keyName;
const CHARSET_INFO* cs = getCharset(fp[0]); const CHARSET_INFO* cs = getCharset(fp[0]);
@@ -37,6 +36,17 @@ string Func_json_remove::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
initJSPaths(paths, fp, 1, 1); initJSPaths(paths, fp, 1, 1);
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
for (size_t i=0; i<paths.size(); i++)
{
JSONPath& path = paths[i];
initJsonArray(&path.p.steps, sizeof(json_path_step_t), &p_steps_arr[i]);
}
#endif
string retJS; string retJS;
utils::NullString tmpJS(js); utils::NullString tmpJS(js);
for (size_t i = 1, j = 0; i < fp.size(); i++, j++) for (size_t i = 1, j = 0; i < fp.size(); i++, j++)
@@ -49,13 +59,25 @@ string Func_json_remove::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
const char *remStart = nullptr, *remEnd = nullptr; const char *remStart = nullptr, *remEnd = nullptr;
IntType itemSize = 0; IntType itemSize = 0;
#if MYSQL_VERSION_ID >= 120100
json_path_step_t *curr_last_step= nullptr;
#endif
if (!path.parsed) if (!path.parsed)
{ {
if (parseJSPath(path, row, fp[i], false)) if (parseJSPath(path, row, fp[i], false))
goto error; goto error;
path.p.last_step--; #if MYSQL_VERSION_ID >= 120100
path.p.last_step_idx--;
curr_last_step= reinterpret_cast<json_path_step_t*>
(mem_root_dynamic_array_get_val(&path.p.steps,
path.p.last_step_idx));
if (curr_last_step < reinterpret_cast<json_path_step_t*>(path.p.steps.buffer))
#else
path.p.last_step--;
if (path.p.last_step < path.p.steps) if (path.p.last_step < path.p.steps)
#endif
{ {
path.p.s.error = TRIVIAL_PATH_NOT_ALLOWED; path.p.s.error = TRIVIAL_PATH_NOT_ALLOWED;
goto error; goto error;
@@ -64,7 +86,11 @@ string Func_json_remove::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
initJSEngine(jsEg, cs, tmpJS); initJSEngine(jsEg, cs, tmpJS);
#if MYSQL_VERSION_ID >= 120100
if (curr_last_step < reinterpret_cast<json_path_step_t*>(path.p.steps.buffer))
#else
if (path.p.last_step < path.p.steps) if (path.p.last_step < path.p.steps)
#endif
goto v_found; goto v_found;
if (locateJSPath(jsEg, path, &jsErr) && jsErr) if (locateJSPath(jsEg, path, &jsErr) && jsErr)
@@ -73,7 +99,12 @@ string Func_json_remove::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
if (json_read_value(&jsEg)) if (json_read_value(&jsEg))
goto error; goto error;
#if MYSQL_VERSION_ID >= 120100
lastStep = curr_last_step + 1;
#else
lastStep = path.p.last_step + 1; lastStep = path.p.last_step + 1;
#endif
if (lastStep->type & JSON_PATH_ARRAY) if (lastStep->type & JSON_PATH_ARRAY)
{ {
if (jsEg.value_type != JSON_VALUE_ARRAY) if (jsEg.value_type != JSON_VALUE_ARRAY)

View File

@@ -20,12 +20,20 @@ namespace
static bool appendJSPath(string& ret, const json_path_t* p) static bool appendJSPath(string& ret, const json_path_t* p)
{ {
const json_path_step_t* c; const json_path_step_t* c;
#if MYSQL_VERSION_ID >= 120100
const json_path_step_t* last_step= (const json_path_step_t*)
(mem_root_dynamic_array_get_val((MEM_ROOT_DYNAMIC_ARRAY*)&p->steps,
(size_t)p->last_step_idx));
#endif
try try
{ {
ret.append("\"$"); ret.append("\"$");
#if MYSQL_VERSION_ID >= 120100
for (c = reinterpret_cast<json_path_step_t*>(p->steps.buffer)+1; c <= last_step; c++)
#else
for (c = p->steps + 1; c <= p->last_step; c++) for (c = p->steps + 1; c <= p->last_step; c++)
#endif
{ {
if (c->type & JSON_PATH_KEY) if (c->type & JSON_PATH_KEY)
{ {
@@ -144,9 +152,23 @@ string Func_json_search::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
initJSPaths(paths, fp, 4, 1); initJSPaths(paths, fp, 4, 1);
for (size_t i = 4; i < fp.size(); i++) #if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
json_path_step_t p_steps[JSON_DEPTH_LIMIT], savPath_steps[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
initJsonArray(&savPath.steps, sizeof(json_path_step_t), &savPath_steps);
initJsonArray(&p.steps, sizeof(json_path_step_t), &p_steps);
#endif
int n= p_steps_arr.size();
for (size_t i = 4; i < fp.size()+n; i++)
{ {
JSONPath& path = paths[i - 4]; JSONPath& path = paths[i - 4];
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&path.p.steps, sizeof(json_path_step_t), &p_steps_arr[i-4]);
#endif
if (!path.parsed) if (!path.parsed)
{ {
if (parseJSPath(path, row, fp[i])) if (parseJSPath(path, row, fp[i]))
@@ -162,8 +184,13 @@ string Func_json_search::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
while (json_get_path_next(&jsEg, &p) == 0) while (json_get_path_next(&jsEg, &p) == 0)
{ {
#if MYSQL_VERSION_ID >= 100900 #if MYSQL_VERSION_ID >= 100900
#if MYSQL_VERSION_ID >= 120100
if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY && if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY &&
json_skip_array_and_count(&jsEg, arrayCounter + p.last_step_idx))
#else
if (hasNegPath && jsEg.value_type == JSON_VALUE_ARRAY &&
json_skip_array_and_count(&jsEg, arrayCounter + (p.last_step - p.steps))) json_skip_array_and_count(&jsEg, arrayCounter + (p.last_step - p.steps)))
#endif
goto error; goto error;
#endif #endif
@@ -180,7 +207,11 @@ string Func_json_search::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
if (pathFound == 1) if (pathFound == 1)
{ {
savPath = p; savPath = p;
#if MYSQL_VERSION_ID >= 120100
mem_root_dynamic_array_copy_values(&savPath.steps, &p.steps);
#else
savPath.last_step = savPath.steps + (p.last_step - p.steps); savPath.last_step = savPath.steps + (p.last_step - p.steps);
#endif
} }
else else
{ {

View File

@@ -29,6 +29,11 @@ string Func_json_type::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isN
json_engine_t jsEg; json_engine_t jsEg;
string result; string result;
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSEngine(jsEg, getCharset(fp[0]), js); initJSEngine(jsEg, getCharset(fp[0]), js);
if (json_read_value(&jsEg)) if (json_read_value(&jsEg))

View File

@@ -1,5 +1,6 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "json_lib.h"
#include "jsonhelpers.h" #include "jsonhelpers.h"
using namespace execplan; using namespace execplan;
@@ -30,6 +31,12 @@ std::string Func_json_unquote::getStrVal(rowgroup::Row& row, FunctionParm& fp, b
int strLen; int strLen;
const CHARSET_INFO* cs = type.getCharset(); const CHARSET_INFO* cs = type.getCharset();
#if MYSQL_VERSION_ID >= 120100
int jsEg_stack[JSON_DEPTH_LIMIT];
initJsonArray(&jsEg.stack, sizeof(int), &jsEg_stack);
#endif
initJSEngine(jsEg, cs, js); initJSEngine(jsEg, cs, js);
json_read_value(&jsEg); json_read_value(&jsEg);

View File

@@ -25,10 +25,26 @@ CalpontSystemCatalog::ColType Func_json_valid::operationType(FunctionParm& fp,
bool Func_json_valid::getBoolVal(Row& row, FunctionParm& fp, bool& isNull, bool Func_json_valid::getBoolVal(Row& row, FunctionParm& fp, bool& isNull,
CalpontSystemCatalog::ColType& /*type*/) CalpontSystemCatalog::ColType& /*type*/)
{ {
int result= 0;
#if MYSQL_VERSION_ID >= 120100
json_engine_t je;
int je_stack[JSON_DEPTH_LIMIT];
initJsonArray(&je.stack, sizeof(int), &je_stack);
#endif
const auto js = fp[0]->data()->getStrVal(row, isNull); const auto js = fp[0]->data()->getStrVal(row, isNull);
if (isNull) if (isNull)
return false; return false;
return json_valid(js.unsafeStringRef().data(), js.unsafeStringRef().size(), getCharset(fp[0])); #if MYSQL_VERSION_ID >= 120100
result= json_valid(js.unsafeStringRef().data(), js.unsafeStringRef().size(), getCharset(fp[0]), &je);
#else
result= json_valid(js.unsafeStringRef().data(), js.unsafeStringRef().size(), getCharset(fp[0]));
#endif
if (result == 0)
return 1;
else
return 0;
} }
} // namespace funcexp } // namespace funcexp

View File

@@ -1,6 +1,7 @@
#include "functor_json.h" #include "functor_json.h"
#include "functioncolumn.h" #include "functioncolumn.h"
#include "constantcolumn.h" #include "constantcolumn.h"
#include "json_lib.h"
using namespace execplan; using namespace execplan;
#include "rowgroup.h" #include "rowgroup.h"
@@ -63,6 +64,13 @@ bool JSONPathWrapper::extract(std::string& ret, rowgroup::Row& row, execplan::SP
{ {
bool isNullJS = false, isNullPath = false; bool isNullJS = false, isNullPath = false;
#if MYSQL_VERSION_ID >= 120100
MEM_ROOT_DYNAMIC_ARRAY array;
IntType arrayCounters[JSON_DEPTH_LIMIT];
int je_stack[JSON_DEPTH_LIMIT];
json_path_step_t p_steps[JSON_DEPTH_LIMIT];
#endif
const utils::NullString& js = funcParamJS->data()->getStrVal(row, isNullJS); const utils::NullString& js = funcParamJS->data()->getStrVal(row, isNullJS);
const utils::NullString& sjsp = funcParamPath->data()->getStrVal(row, isNullPath); const utils::NullString& sjsp = funcParamPath->data()->getStrVal(row, isNullPath);
if (isNullJS || isNullPath) if (isNullJS || isNullPath)
@@ -70,21 +78,38 @@ bool JSONPathWrapper::extract(std::string& ret, rowgroup::Row& row, execplan::SP
int error = 0; int error = 0;
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&p.steps, sizeof(json_path_step_t), &p_steps);
#endif
if (json_path_setup(&p, getCharset(funcParamPath), (const uchar*)sjsp.str(), (const uchar*)sjsp.end())) if (json_path_setup(&p, getCharset(funcParamPath), (const uchar*)sjsp.str(), (const uchar*)sjsp.end()))
return true; return true;
JSONEgWrapper je(getCharset(funcParamJS), reinterpret_cast<const uchar*>(js.str()),
reinterpret_cast<const uchar*>(js.end()));
JSONEgWrapper je(getCharset(funcParamJS), reinterpret_cast<const uchar*>(js.str()),
reinterpret_cast<const uchar*>(js.end()), je_stack);
#if MYSQL_VERSION_ID >= 120100
initJsonArray(&je.stack, sizeof(int), &je_stack);
currStep = reinterpret_cast<json_path_step_t*>(p.steps.buffer);
initJsonArray(&array, sizeof(int), &arrayCounters);
#else
currStep = p.steps; currStep = p.steps;
#endif
do do
{ {
if (error) if (error)
return true; return true;
#if MYSQL_VERSION_ID >= 120100
if (json_find_path(&je, &p, &currStep, &array))
#else
IntType arrayCounters[JSON_DEPTH_LIMIT]; IntType arrayCounters[JSON_DEPTH_LIMIT];
if (json_find_path(&je, &p, &currStep, arrayCounters)) if (json_find_path(&je, &p, &currStep, arrayCounters))
#endif
return true; return true;
if (json_read_value(&je)) if (json_read_value(&je))

View File

@@ -27,15 +27,64 @@ struct JSONPath
json_path_step_t* currStep; json_path_step_t* currStep;
}; };
class Func_json_no_multipath
{
protected:
JSONPath path;
#if MYSQL_VERSION_ID >= 120100
json_path_step_t p_steps[JSON_DEPTH_LIMIT];
#endif
public:
Func_json_no_multipath()
{
#if MYSQL_VERSION_ID >= 120100
initJsonPathArray(&path.p.steps, &p_steps[0]);
#endif
}
};
class Func_json_multipath
{
protected:
std::vector<JSONPath> paths;
#if MYSQL_VERSION_ID >= 120100
std::vector<std::vector<json_path_step_t>> p_steps_arr;
#endif
public:
Func_json_multipath()
{
#if MYSQL_VERSION_ID >= 120100
p_steps_arr = std::vector<std::vector<json_path_step_t>>(paths.size(), std::vector<json_path_step_t>(JSON_DEPTH_LIMIT));
for (size_t i=0; i<paths.size(); i++)
{
JSONPath curr_path= paths[i];
initJsonPathArray(&curr_path.p.steps, &p_steps_arr[i][0]);
}
#endif
}
Func_json_multipath(size_t number_of_args)
{
#if MYSQL_VERSION_ID >= 120100
p_steps_arr = std::vector<std::vector<json_path_step_t>>(number_of_args, std::vector<json_path_step_t>(JSON_DEPTH_LIMIT));
#endif
}
~Func_json_multipath() {}
};
class JSONEgWrapper : public json_engine_t class JSONEgWrapper : public json_engine_t
{ {
public: public:
JSONEgWrapper(CHARSET_INFO* cs, const uchar* str, const uchar* end) JSONEgWrapper(CHARSET_INFO* cs, const uchar* str, const uchar* end, int *buffer)
{ {
mem_root_dynamic_array_init(NULL, PSI_INSTRUMENT_MEM,
&this->stack, sizeof(int), buffer,
JSON_DEPTH_DEFAULT, JSON_DEPTH_INC, MYF(0));
json_scan_start(this, cs, str, end); json_scan_start(this, cs, str, end);
} }
JSONEgWrapper(const std::string& str, CHARSET_INFO* cs) JSONEgWrapper(const std::string& str, CHARSET_INFO* cs)
: JSONEgWrapper(cs, (const uchar*)str.data(), (const uchar*)str.data() + str.size()) : JSONEgWrapper(cs, (const uchar*)str.data(), (const uchar*)str.data() + str.size(), NULL)
{ {
} }
bool checkAndGetScalar(std::string& ret, int* error); bool checkAndGetScalar(std::string& ret, int* error);
@@ -88,15 +137,11 @@ class Func_json_depth : public Func_Int
/** @brief Func_json_length class /** @brief Func_json_length class
*/ */
class Func_json_length : public Func_Int class Func_json_length : public Func_Int, public Func_json_no_multipath
{ {
protected:
JSONPath path;
public: public:
Func_json_length() : Func_Int("json_length") Func_json_length() : Func_Int("json_length"), Func_json_no_multipath()
{ {}
}
~Func_json_length() override = default; ~Func_json_length() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -192,13 +237,10 @@ class Func_json_array : public Func_Str
}; };
/** @brief Func_json_keys class /** @brief Func_json_keys class
*/ */
class Func_json_keys : public Func_Str class Func_json_keys : public Func_Str, public Func_json_no_multipath
{ {
protected:
JSONPath path;
public: public:
Func_json_keys() : Func_Str("json_keys") Func_json_keys() : Func_Str("json_keys"), Func_json_no_multipath()
{ {
} }
~Func_json_keys() override = default; ~Func_json_keys() override = default;
@@ -211,15 +253,11 @@ class Func_json_keys : public Func_Str
}; };
/** @brief Func_json_exists class /** @brief Func_json_exists class
*/ */
class Func_json_exists : public Func_Bool class Func_json_exists : public Func_Bool, public Func_json_no_multipath
{ {
protected:
JSONPath path;
public: public:
Func_json_exists() : Func_Bool("json_exists") Func_json_exists() : Func_Bool("json_exists"), Func_json_no_multipath()
{ {}
}
~Func_json_exists() override = default; ~Func_json_exists() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -231,15 +269,11 @@ class Func_json_exists : public Func_Bool
/** @brief Func_json_quote class /** @brief Func_json_quote class
*/ */
class Func_json_quote : public Func_Str class Func_json_quote : public Func_Str, public Func_json_no_multipath
{ {
protected:
JSONPath path;
public: public:
Func_json_quote() : Func_Str("json_quote") Func_json_quote() : Func_Str("json_quote"), Func_json_no_multipath()
{ {}
}
~Func_json_quote() override = default; ~Func_json_quote() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -251,15 +285,11 @@ class Func_json_quote : public Func_Str
/** @brief Func_json_unquote class /** @brief Func_json_unquote class
*/ */
class Func_json_unquote : public Func_Str class Func_json_unquote : public Func_Str, public Func_json_no_multipath
{ {
protected:
JSONPath path;
public: public:
Func_json_unquote() : Func_Str("json_unquote") Func_json_unquote() : Func_Str("json_unquote"), Func_json_no_multipath()
{ {}
}
~Func_json_unquote() override = default; ~Func_json_unquote() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -331,8 +361,7 @@ class Func_json_merge_patch : public Func_Str
{ {
public: public:
Func_json_merge_patch() : Func_Str("json_merge_patch") Func_json_merge_patch() : Func_Str("json_merge_patch")
{ {}
}
~Func_json_merge_patch() override = default; ~Func_json_merge_patch() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -377,18 +406,17 @@ class Func_json_query : public Func_Str
}; };
/** @brief Func_json_contains class /** @brief Func_json_contains class
*/ */
class Func_json_contains : public Func_Bool class Func_json_contains : public Func_Bool, public Func_json_no_multipath
{ {
protected: protected:
JSONPath path;
bool arg2Const; bool arg2Const;
bool arg2Parsed; // argument 2 is a constant or has been parsed bool arg2Parsed; // argument 2 is a constant or has been parsed
utils::NullString arg2Val; utils::NullString arg2Val;
public: public:
Func_json_contains() : Func_Bool("json_contains"), arg2Const(false), arg2Parsed(false), arg2Val("") Func_json_contains() : Func_Bool("json_contains"), arg2Const(false),
{ arg2Parsed(false), arg2Val("")
} {}
~Func_json_contains() override = default; ~Func_json_contains() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -399,15 +427,14 @@ class Func_json_contains : public Func_Bool
}; };
/** @brief Func_json_array_append class /** @brief Func_json_array_append class
*/ */
class Func_json_array_append : public Func_Str class Func_json_array_append : public Func_Str, public Func_json_multipath
{ {
protected:
std::vector<JSONPath> paths;
public: public:
Func_json_array_append() : Func_Str("json_array_append") Func_json_array_append() : Func_Str("json_array_append"), Func_json_multipath()
{ {}
} Func_json_array_append(size_t number_of_args) : Func_Str("json_array_append"),
Func_json_multipath(number_of_args)
{}
~Func_json_array_append() override = default; ~Func_json_array_append() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -421,15 +448,13 @@ class Func_json_array_append : public Func_Str
}; };
/** @brief Func_json_array_insert class /** @brief Func_json_array_insert class
*/ */
class Func_json_array_insert : public Func_Str class Func_json_array_insert : public Func_Str, public Func_json_multipath
{ {
protected:
std::vector<JSONPath> paths;
public: public:
Func_json_array_insert() : Func_Str("json_array_insert") Func_json_array_insert() : Func_Str("json_array_insert"), Func_json_multipath()
{ {}
} Func_json_array_insert(size_t number_of_args) : Func_Str("json_array_insert"), Func_json_multipath(number_of_args)
{}
~Func_json_array_insert() override = default; ~Func_json_array_insert() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -441,7 +466,7 @@ class Func_json_array_insert : public Func_Str
/** @brief Func_json_insert class /** @brief Func_json_insert class
*/ */
class Func_json_insert : public Func_Str class Func_json_insert : public Func_json_multipath, public Func_Str
{ {
public: public:
enum MODE enum MODE
@@ -454,12 +479,13 @@ class Func_json_insert : public Func_Str
protected: protected:
MODE mode; MODE mode;
std::vector<JSONPath> paths;
public: public:
Func_json_insert() : Func_Str("json_insert"), mode(INSERT) Func_json_insert() : Func_Str("json_insert"), mode(INSERT)
{ {}
} Func_json_insert(size_t number_of_args) : Func_json_multipath(number_of_args),
Func_Str("json_insert"), mode(INSERT)
{}
explicit Func_json_insert(MODE m) : mode(m) explicit Func_json_insert(MODE m) : mode(m)
{ {
assert(m != NONE); assert(m != NONE);
@@ -471,6 +497,17 @@ class Func_json_insert : public Func_Str
default: break; default: break;
} }
} }
explicit Func_json_insert(size_t number_of_args, MODE m) : Func_json_multipath(number_of_args), mode(m)
{
assert(m != NONE);
switch (m)
{
case INSERT: Func_Str::Func::funcName("json_insert"); break;
case REPLACE: Func_Str::Func::funcName("json_replace"); break;
case SET: Func_Str::Func::funcName("json_set"); break;
default: break;
}
}
~Func_json_insert() override = default; ~Func_json_insert() override = default;
MODE getMode() const MODE getMode() const
@@ -486,15 +523,13 @@ class Func_json_insert : public Func_Str
}; };
/** @brief Func_json_remove class /** @brief Func_json_remove class
*/ */
class Func_json_remove : public Func_Str class Func_json_remove : public Func_Str, public Func_json_multipath
{ {
protected:
std::vector<JSONPath> paths;
public: public:
Func_json_remove() : Func_Str("json_remove") Func_json_remove() : Func_Str("json_remove"), Func_json_multipath()
{ {}
} Func_json_remove(size_t number_of_args) : Func_Str("json_remove"), Func_json_multipath(number_of_args)
{}
~Func_json_remove() override = default; ~Func_json_remove() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -506,10 +541,9 @@ class Func_json_remove : public Func_Str
/** @brief Func_json_contains_path class /** @brief Func_json_contains_path class
*/ */
class Func_json_contains_path : public Func_Bool class Func_json_contains_path : public Func_json_multipath, public Func_Bool
{ {
protected: protected:
std::vector<JSONPath> paths;
std::vector<bool> hasFound; std::vector<bool> hasFound;
bool isModeOne; bool isModeOne;
bool isModeConst; bool isModeConst;
@@ -518,8 +552,11 @@ class Func_json_contains_path : public Func_Bool
public: public:
Func_json_contains_path() Func_json_contains_path()
: Func_Bool("json_contains_path"), isModeOne(false), isModeConst(false), isModeParsed(false) : Func_Bool("json_contains_path"), isModeOne(false), isModeConst(false), isModeParsed(false)
{ {}
} Func_json_contains_path(size_t number_of_args)
: Func_json_multipath(number_of_args), Func_Bool("json_contains_path"),
isModeOne(false), isModeConst(false), isModeParsed(false)
{}
~Func_json_contains_path() override = default; ~Func_json_contains_path() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -531,15 +568,11 @@ class Func_json_contains_path : public Func_Bool
/** @brief Func_json_overlaps class /** @brief Func_json_overlaps class
*/ */
class Func_json_overlaps : public Func_Bool class Func_json_overlaps : public Func_Bool, public Func_json_no_multipath
{ {
protected:
JSONPath path;
public: public:
Func_json_overlaps() : Func_Bool("json_overlaps") Func_json_overlaps() : Func_Bool("json_overlaps"), Func_json_no_multipath()
{ {}
}
~Func_json_overlaps() override = default; ~Func_json_overlaps() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -550,10 +583,9 @@ class Func_json_overlaps : public Func_Bool
}; };
/** @brief Func_json_search class /** @brief Func_json_search class
*/ */
class Func_json_search : public Func_Str class Func_json_search : public Func_json_multipath, public Func_Str
{ {
protected: protected:
std::vector<JSONPath> paths;
bool isModeParsed; bool isModeParsed;
bool isModeConst; bool isModeConst;
bool isModeOne; bool isModeOne;
@@ -562,8 +594,11 @@ class Func_json_search : public Func_Str
public: public:
Func_json_search() Func_json_search()
: Func_Str("json_search"), isModeParsed(false), isModeConst(false), isModeOne(false), escape('\\') : Func_Str("json_search"), isModeParsed(false), isModeConst(false), isModeOne(false), escape('\\')
{ {}
} Func_json_search(size_t number_of_args)
: Func_json_multipath(number_of_args), Func_Str("json_search"),
isModeParsed(false), isModeConst(false), isModeOne(false), escape('\\')
{}
~Func_json_search() override = default; ~Func_json_search() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(
@@ -577,15 +612,13 @@ class Func_json_search : public Func_Str
}; };
/** @brief Func_json_extract_string class /** @brief Func_json_extract_string class
*/ */
class Func_json_extract : public Func_Str class Func_json_extract : public Func_Str, public Func_json_multipath
{ {
protected:
std::vector<JSONPath> paths;
public: public:
Func_json_extract() : Func_Str("json_extract") Func_json_extract() : Func_Str("json_extract")
{ {}
} Func_json_extract(size_t number_of_args) : Func_Str("json_extract"), Func_json_multipath(number_of_args)
{}
~Func_json_extract() override = default; ~Func_json_extract() override = default;
execplan::CalpontSystemCatalog::ColType operationType( execplan::CalpontSystemCatalog::ColType operationType(

View File

@@ -335,7 +335,17 @@ int cmpPartJSPath(const json_path_step_t* a, const json_path_step_t* aEnd, const
int cmpJSPath(const json_path_t* a, const json_path_t* b, enum json_value_types vt, const int* arraySize) int cmpJSPath(const json_path_t* a, const json_path_t* b, enum json_value_types vt, const int* arraySize)
{ {
#if MYSQL_VERSION_ID >= 120100
json_path_step_t *a_last_step= reinterpret_cast<json_path_step_t*>
(mem_root_dynamic_array_get_val((MEM_ROOT_DYNAMIC_ARRAY*)&a->steps, (size_t)a->last_step_idx));
json_path_step_t *b_last_step= reinterpret_cast<json_path_step_t*>
(mem_root_dynamic_array_get_val((MEM_ROOT_DYNAMIC_ARRAY*)&b->steps, (size_t)b->last_step_idx));
return cmpPartJSPath((reinterpret_cast<json_path_step_t*>(a->steps.buffer)) + 1, a_last_step,
(reinterpret_cast<json_path_step_t*>(b->steps.buffer)) + 1, b_last_step,
vt, arraySize);
#else
return cmpPartJSPath(a->steps + 1, a->last_step, b->steps + 1, b->last_step, vt, arraySize); return cmpPartJSPath(a->steps + 1, a->last_step, b->steps + 1, b->last_step, vt, arraySize);
#endif
} }
int parseJSPath(JSONPath& path, rowgroup::Row& row, execplan::SPTP& parm, bool wildcards) int parseJSPath(JSONPath& path, rowgroup::Row& row, execplan::SPTP& parm, bool wildcards)
@@ -371,5 +381,16 @@ bool matchJSPath(const vector<funcexp::JSONPath>& paths, const json_path_t* p, j
} }
return false; return false;
} }
#if MYSQL_VERSION_ID >= 120100
void initJsonArray(MEM_ROOT_DYNAMIC_ARRAY *mem_root_array, size_t size, void *buffer)
{
mem_root_dynamic_array_init(NULL, PSI_INSTRUMENT_MEM | MY_INIT_BUFFER_USED | MY_BUFFER_NO_RESIZE,
mem_root_array, size, buffer,
JSON_DEPTH_LIMIT, 0, MYF(0));
return;
}
#endif
} // namespace helpers } // namespace helpers
} // namespace funcexp } // namespace funcexp

View File

@@ -55,6 +55,10 @@ using IntType = int;
using IntType = uint; using IntType = uint;
#endif #endif
#if MYSQL_VERSION_ID >= 120100
void initJsonArray(MEM_ROOT_DYNAMIC_ARRAY *mem_root_array, size_t size, void *buffer);
#endif
/* /*
Compatible with json_find_path function in json_lib Compatible with json_find_path function in json_lib
before 10.9: uint* array_counters before 10.9: uint* array_counters
@@ -63,8 +67,18 @@ using IntType = uint;
inline static int locateJSPath(json_engine_t& jsEg, JSONPath& path, int* jsErr = nullptr) inline static int locateJSPath(json_engine_t& jsEg, JSONPath& path, int* jsErr = nullptr)
{ {
IntType arrayCounters[JSON_DEPTH_LIMIT]; IntType arrayCounters[JSON_DEPTH_LIMIT];
#if MYSQL_VERSION_ID >= 120100
MEM_ROOT_DYNAMIC_ARRAY array;
initJsonArray(&array, sizeof(int), &arrayCounters);
path.currStep = reinterpret_cast<json_path_step_t*>(path.p.steps.buffer);
if (json_find_path(&jsEg, &path.p, &path.currStep, &array))
#else
path.currStep = path.p.steps; path.currStep = path.p.steps;
if (json_find_path(&jsEg, &path.p, &path.currStep, arrayCounters)) if (json_find_path(&jsEg, &path.p, &path.currStep, arrayCounters))
#endif
{ {
if (jsErr && jsEg.s.error) if (jsErr && jsEg.s.error)
*jsErr = 1; *jsErr = 1;