提交 a1f2b9ae 编写于 作者: Z zhang2014

ISSUES-2973 support nested json struct for visitParamExtractRaw

上级 918d17ff
......@@ -87,45 +87,47 @@ struct ExtractBool
struct ExtractRaw
{
inline static void skipAfterQuotationIfNeed(const UInt8 *& pos, const UInt8 * end, ColumnString::Chars_t & res_data)
{
if (pos + 1 < end && pos[1] == '"')
{
res_data.push_back(*pos);
++pos;
}
}
static constexpr size_t bytes_on_stack = 64;
using ExpectChars = PODArray<char, bytes_on_stack, AllocatorWithStackMemory<Allocator<false>, bytes_on_stack>>;
static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars_t & res_data)
{
std::vector<char> expect_end;
ExpectChars expects_end;
UInt8 current_expect_end = 0;
for (; pos != end; ++pos)
for (auto extract_begin = pos; pos != end; ++pos)
{
if (!expect_end.empty() && *pos == expect_end.back())
expect_end.pop_back();
if (*pos == current_expect_end)
{
expects_end.pop_back();
current_expect_end = (UInt8) (expects_end.empty() ? 0 : expects_end.back());
}
else
{
switch (*pos)
switch(*pos)
{
case '[':
expect_end.push_back(']');
case '[':
expects_end.push_back((current_expect_end = ']'));
break;
case '{':
expect_end.push_back('}');
case '{':
expects_end.push_back((current_expect_end = '}'));
break;
case '"':
expect_end.push_back('"');
case '"' :
expects_end.push_back((current_expect_end = '"'));
break;
case '\\':
skipAfterQuotationIfNeed(pos, end, res_data);
case '\\':
/// skip backslash
if (pos + 1 < end && pos[1] == '"')
pos++;
break;
default:
if (expect_end.empty() && (*pos == ',' || *pos == '}'))
if (!current_expect_end && (*pos == ',' || *pos == '}'))
{
res_data.insert(extract_begin, pos);
return;
}
}
}
res_data.push_back(*pos);
}
}
};
......
......@@ -27,5 +27,5 @@
</substitution>
</substitutions>
<query>SELECT count() FROM system.numbers WHERE NOT ignore(visitParamExtractRaw({param}, 'myparam'))</query>
<query>SELECT count() FROM system.numbers WHERE NOT ignore(visitParamExtractRaw(materialize({param}), 'myparam'))</query>
</test>
......@@ -9,5 +9,5 @@ test"string
"test_string"
"test\\"string"
"test\\"string"
[1,2,3]
["]", "2", "3"]
{"nested" : [1,2,3]}
......@@ -11,5 +11,5 @@ SELECT visitParamExtractRaw('{"myparam":"test_string"}', 'myparam');
SELECT visitParamExtractRaw('{"myparam": "test_string"}', 'myparam');
SELECT visitParamExtractRaw('{"myparam": "test\\"string"}', 'myparam');
SELECT visitParamExtractRaw('{"myparam": "test\\"string", "other":123}', 'myparam');
SELECT visitParamExtractRaw('{"myparam": [1,2,3], "other":123}', 'myparam');
SELECT visitParamExtractRaw('{"myparam": ["]", "2", "3"], "other":123}', 'myparam');
SELECT visitParamExtractRaw('{"myparam": {"nested" : [1,2,3]}, "other":123}', 'myparam');
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册