1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +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:
Sergey Zefirov
2023-11-21 23:46:03 +03:00
committed by Leonid Fedorov
parent 1935c9c1da
commit 2eca3ee656
5 changed files with 97 additions and 22 deletions

View File

@ -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