JSONExtractString raw string support.

This commit is contained in:
Amos Bird 2021-10-20 11:52:48 +08:00
parent 0b3926950d
commit ddcf12c83b
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 14 additions and 10 deletions

View File

@ -744,6 +744,8 @@ public:
}
};
template <typename JSONParser>
class JSONExtractRawImpl;
template <typename JSONParser>
class JSONExtractStringImpl
@ -760,9 +762,12 @@ public:
static bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &)
{
if (!element.isString())
if (element.isNull())
return false;
if (!element.isString())
return JSONExtractRawImpl<JSONParser>::insertResultToColumn(dest, element, {});
auto str = element.getString();
ColumnString & col_str = assert_cast<ColumnString &>(dest);
col_str.insertData(str.data(), str.size());
@ -770,9 +775,6 @@ public:
}
};
template <typename JSONParser>
class JSONExtractRawImpl;
/// Nodes of the extract tree. We need the extract tree to extract from JSON complex values containing array, tuples or nullables.
template <typename JSONParser>
struct JSONExtractTree
@ -856,12 +858,7 @@ struct JSONExtractTree
public:
bool insertResultToColumn(IColumn & dest, const Element & element) override
{
if (element.isString())
return JSONExtractStringImpl<JSONParser>::insertResultToColumn(dest, element, {});
else if (element.isNull())
return false;
else
return JSONExtractRawImpl<JSONParser>::insertResultToColumn(dest, element, {});
return JSONExtractStringImpl<JSONParser>::insertResultToColumn(dest, element, {});
}
};

View File

@ -1,2 +1,5 @@
('123','456','[7,8,9]')
\N
123
123

View File

@ -3,3 +3,7 @@
select JSONExtract('{"a": "123", "b": 456, "c": [7, 8, 9]}', 'Tuple(a String, b String, c String)');
with '{"string_value":null}' as json select JSONExtract(json, 'string_value', 'Nullable(String)');
select JSONExtractString('{"a": 123}', 'a');
select JSONExtractString('{"a": "123"}', 'a');
select JSONExtractString('{"a": null}', 'a');