2019-08-04 14:15:47 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionsVisitParam.h>
|
2020-03-29 17:04:16 +00:00
|
|
|
#include <Functions/FunctionsStringSearchToString.h>
|
2019-08-04 14:15:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ExtractRaw
|
|
|
|
{
|
|
|
|
using ExpectChars = PODArrayWithStackMemory<char, 64>;
|
|
|
|
|
|
|
|
static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars & res_data)
|
|
|
|
{
|
|
|
|
ExpectChars expects_end;
|
|
|
|
UInt8 current_expect_end = 0;
|
|
|
|
|
2020-04-22 08:45:14 +00:00
|
|
|
for (const auto * extract_begin = pos; pos != end; ++pos)
|
2019-08-04 14:15:47 +00:00
|
|
|
{
|
|
|
|
if (current_expect_end && *pos == current_expect_end)
|
|
|
|
{
|
|
|
|
expects_end.pop_back();
|
|
|
|
current_expect_end = expects_end.empty() ? 0 : expects_end.back();
|
|
|
|
}
|
2020-05-30 19:44:22 +00:00
|
|
|
else if (current_expect_end == '"')
|
|
|
|
{
|
|
|
|
/// skip backslash
|
|
|
|
if (*pos == '\\' && pos + 1 < end && pos[1] == '"')
|
2020-05-31 15:01:59 +00:00
|
|
|
++pos;
|
2020-05-30 19:44:22 +00:00
|
|
|
}
|
2019-08-04 14:15:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (*pos)
|
|
|
|
{
|
|
|
|
case '[':
|
|
|
|
current_expect_end = ']';
|
|
|
|
expects_end.push_back(current_expect_end);
|
|
|
|
break;
|
|
|
|
case '{':
|
|
|
|
current_expect_end = '}';
|
|
|
|
expects_end.push_back(current_expect_end);
|
|
|
|
break;
|
|
|
|
case '"' :
|
|
|
|
current_expect_end = '"';
|
|
|
|
expects_end.push_back(current_expect_end);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!current_expect_end && (*pos == ',' || *pos == '}'))
|
|
|
|
{
|
|
|
|
res_data.insert(extract_begin, pos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameVisitParamExtractRaw { static constexpr auto name = "visitParamExtractRaw"; };
|
|
|
|
using FunctionVisitParamExtractRaw = FunctionsStringSearchToString<ExtractParamToStringImpl<ExtractRaw>, NameVisitParamExtractRaw>;
|
|
|
|
|
2021-04-01 20:07:01 +00:00
|
|
|
struct NameSimpleJSONExtractRaw { static constexpr auto name = "simpleJSONExtractRaw"; };
|
2021-03-30 16:25:56 +00:00
|
|
|
using FunctionSimpleJSONExtractRaw = FunctionsStringSearchToString<ExtractParamToStringImpl<ExtractRaw>, NameSimpleJSONExtractRaw>;
|
2019-08-04 14:15:47 +00:00
|
|
|
|
|
|
|
void registerFunctionVisitParamExtractRaw(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionVisitParamExtractRaw>();
|
2021-03-30 16:25:56 +00:00
|
|
|
factory.registerFunction<FunctionSimpleJSONExtractRaw>();
|
2019-08-04 14:15:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|