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

MCOL-785 Implement DISTRIBUTED JSON functions

The following functions are created:
Create function JSON_VALID and test cases
Create function JSON_DEPTH and test cases
Create function JSON_LENGTH and test cases
Create function JSON_EQUALS and test cases
Create function JSON_NORMALIZE and test cases
Create function JSON_TYPE and test cases
Create function JSON_OBJECT and test cases
Create function JSON_ARRAY and test cases
Create function JSON_KEYS and test cases
Create function JSON_EXISTS and test cases
Create function JSON_QUOTE/JSON_UNQUOTE and test cases
Create function JSON_COMPACT/DETAILED/LOOSE and test cases
Create function JSON_MERGE and test cases
Create function JSON_MERGE_PATCH and test cases
Create function JSON_VALUE and test cases
Create function JSON_QUERY and test cases
Create function JSON_CONTAINS and test cases
Create function JSON_ARRAY_APPEND and test cases
Create function JSON_ARRAY_INSERT and test cases
Create function JSON_INSERT/REPLACE/SET and test cases
Create function JSON_REMOVE and test cases
Create function JSON_CONTAINS_PATH and test cases
Create function JSON_OVERLAPS and test cases
Create function JSON_EXTRACT and test cases
Create function JSON_SEARCH and test cases

Note:
Some functions output differs from MDB because session variables that affects functions output,e.g JSON_QUOTE/JSON_UNQUOTE
This depends on MCOL-5212
This commit is contained in:
Ziy1-Tan
2022-06-23 10:49:29 +08:00
parent b5d8e0324b
commit cdd41f05f3
82 changed files with 8645 additions and 2 deletions

View File

@ -29,6 +29,7 @@ using namespace std;
#include <boost/algorithm/string.hpp>
using namespace boost;
#include "functor_json.h"
#include "bytestream.h"
#include "functioncolumn.h"
#include "constantcolumn.h"
@ -323,6 +324,46 @@ void FunctionColumn::unserialize(messageqcpp::ByteStream& b)
Func_decode* decode = dynamic_cast<Func_decode*>(fFunctor);
if (decode)
fFunctor = fDynamicFunctor = new Func_decode();
// Special treatment for json function contains the variable path. reset the variable path
if (dynamic_cast<Func_json_length*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_length();
if (dynamic_cast<Func_json_keys*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_keys();
if (dynamic_cast<Func_json_exists*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_exists();
if (dynamic_cast<Func_json_value*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_value();
if (dynamic_cast<Func_json_query*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_query();
if (dynamic_cast<Func_json_contains*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_contains();
if (dynamic_cast<Func_json_array_append*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_array_append();
if (dynamic_cast<Func_json_array_insert*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_array_insert();
if (auto f = dynamic_cast<Func_json_insert*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_insert(f->getMode());
if (dynamic_cast<Func_json_remove*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_remove();
if (dynamic_cast<Func_json_contains_path*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_contains_path();
if (dynamic_cast<Func_json_search*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_search();
if (dynamic_cast<Func_json_extract*>(fFunctor))
fFunctor = fDynamicFunctor = new Func_json_extract();
}
bool FunctionColumn::operator==(const FunctionColumn& t) const

View File

@ -3550,6 +3550,35 @@ ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupp
return rc;
}
// parse the boolean fields to string "true" or "false"
ReturnedColumn* buildBooleanConstantColumn(Item* item, gp_walk_info& gwi, bool& nonSupport)
{
ConstantColumn* cc = NULL;
if (gwi.thd)
{
{
if (!item->fixed())
{
item->fix_fields(gwi.thd, (Item**)&item);
}
}
}
int64_t val = static_cast<int64_t>(item->val_int());
cc = new ConstantColumnSInt(colType_MysqlToIDB(item), val ? "true" : "false", val);
if (cc)
cc->timeZone(gwi.timeZone);
if (cc && item->name.length)
cc->alias(item->name.str);
if (cc)
cc->charsetNumber(item->collation.collation->number);
return cc;
}
ArithmeticColumn* buildArithmeticColumn(Item_func* item, gp_walk_info& gwi, bool& nonSupport)
{
if (get_fe_conn_info_ptr() == NULL)
@ -4013,7 +4042,24 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
return NULL;
}
ReturnedColumn* rc = buildReturnedColumn(ifp->arguments()[i], gwi, nonSupport);
ReturnedColumn* rc = NULL;
// Special treatment for json functions
// All boolean arguments will be parsed as boolean string true(false)
// E.g. the result of `SELECT JSON_ARRAY(true, false)` should be [true, false] instead of [1, 0]
bool mayHasBoolArg = ((funcName == "json_insert" || funcName == "json_replace" ||
funcName == "json_set" || funcName == "json_array_append" ||
funcName == "json_array_insert") && i != 0 && i % 2 == 0) ||
(funcName == "json_array") ||
(funcName == "json_object" && i % 2 == 1);
bool isBoolType =
(ifp->arguments()[i]->const_item() && ifp->arguments()[i]->type_handler()->is_bool_type());
if (mayHasBoolArg && isBoolType)
rc = buildBooleanConstantColumn(ifp->arguments()[i], gwi, nonSupport);
else
rc = buildReturnedColumn(ifp->arguments()[i], gwi, nonSupport);
// MCOL-1510 It must be a temp table field, so find the corresponding column.
if (!rc && ifp->arguments()[i]->type() == Item::REF_ITEM)