You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
fix(funcexp): MCOL-5607: JSON function use crashes query execution (#3028)
JSON functions were implemented violating an assumption of their pureness, as they should not have any state. This concrete patch fixes implementation of JSON_VALUE function.
This commit is contained in:
committed by
Leonid Fedorov
parent
1935c9c1da
commit
2eca3ee656
@ -65,27 +65,17 @@ bool JSONPathWrapper::extract(std::string& ret, rowgroup::Row& row, execplan::SP
|
||||
|
||||
const string& js = funcParamJS->data()->getStrVal(row, isNullJS);
|
||||
const string_view jsp = funcParamPath->data()->getStrVal(row, isNullPath);
|
||||
|
||||
if (isNullJS || isNullPath)
|
||||
return true;
|
||||
|
||||
int error = 0;
|
||||
|
||||
if (!parsed)
|
||||
{
|
||||
if (!constant)
|
||||
{
|
||||
ConstantColumn* constCol = dynamic_cast<ConstantColumn*>(funcParamPath->data());
|
||||
constant = (constCol != nullptr);
|
||||
}
|
||||
if (json_path_setup(&p, getCharset(funcParamPath), (const uchar*)jsp.data(),
|
||||
(const uchar*)jsp.data() + jsp.size()))
|
||||
return true;
|
||||
|
||||
if (isNullPath || json_path_setup(&p, getCharset(funcParamPath), (const uchar*)jsp.data(),
|
||||
(const uchar*)jsp.data() + jsp.size()))
|
||||
return true;
|
||||
|
||||
parsed = constant;
|
||||
}
|
||||
|
||||
JSONEgWrapper je(js, getCharset(funcParamJS));
|
||||
JSONEgWrapper je(getCharset(funcParamJS), (const uchar*)js.data(), (const uchar*)js.data() + js.size());
|
||||
|
||||
currStep = p.steps;
|
||||
|
||||
@ -112,11 +102,29 @@ CalpontSystemCatalog::ColType Func_json_value::operationType(FunctionParm& fp,
|
||||
return fp[0]->data()->resultType();
|
||||
}
|
||||
|
||||
class JSONPathWrapperValue : public JSONPathWrapper
|
||||
{
|
||||
public:
|
||||
JSONPathWrapperValue()
|
||||
{
|
||||
}
|
||||
virtual ~JSONPathWrapperValue()
|
||||
{
|
||||
}
|
||||
|
||||
bool checkAndGetValue(JSONEgWrapper* je, string& res, int* error) override
|
||||
{
|
||||
return je->checkAndGetScalar(res, error);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
string Func_json_value::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& type)
|
||||
{
|
||||
string ret;
|
||||
isNull = JSONPathWrapper::extract(ret, row, fp[0], fp[1]);
|
||||
JSONPathWrapperValue pw;
|
||||
isNull = pw.extract(ret, row, fp[0], fp[1]);
|
||||
return isNull ? "" : ret;
|
||||
}
|
||||
} // namespace funcexp
|
||||
|
@ -54,6 +54,11 @@ namespace funcexp
|
||||
typedef std::vector<execplan::SPTP> FunctionParm;
|
||||
|
||||
/** @brief Func class
|
||||
*
|
||||
* @desc IMPORTANT: functions are pure transformers, they should
|
||||
* not have state shared between invocations. This is so because
|
||||
* functions' objects are, essentially, singletons and the same
|
||||
* objects will be used in diffeent threads.
|
||||
*/
|
||||
class Func
|
||||
{
|
||||
|
@ -56,6 +56,7 @@ class JSONPathWrapper : public JSONPath
|
||||
{
|
||||
}
|
||||
virtual bool checkAndGetValue(JSONEgWrapper* je, std::string& ret, int* error) = 0;
|
||||
public:
|
||||
bool extract(std::string& ret, rowgroup::Row& row, execplan::SPTP& funcParmJS,
|
||||
execplan::SPTP& funcParmPath);
|
||||
};
|
||||
@ -381,7 +382,7 @@ class Func_json_merge_patch : public Func_Str
|
||||
|
||||
/** @brief Func_json_value class
|
||||
*/
|
||||
class Func_json_value : public Func_Str, public JSONPathWrapper
|
||||
class Func_json_value : public Func_Str
|
||||
{
|
||||
public:
|
||||
Func_json_value() : Func_Str("json_value")
|
||||
@ -391,11 +392,6 @@ class Func_json_value : public Func_Str, public JSONPathWrapper
|
||||
{
|
||||
}
|
||||
|
||||
bool checkAndGetValue(JSONEgWrapper* je, string& res, int* error) override
|
||||
{
|
||||
return je->checkAndGetScalar(res, error);
|
||||
}
|
||||
|
||||
execplan::CalpontSystemCatalog::ColType operationType(
|
||||
FunctionParm& fp, execplan::CalpontSystemCatalog::ColType& resultType) override;
|
||||
|
||||
|
Reference in New Issue
Block a user