mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
JSONExtractString raw string support.
This commit is contained in:
parent
0b3926950d
commit
ddcf12c83b
@ -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, {});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,2 +1,5 @@
|
||||
('123','456','[7,8,9]')
|
||||
\N
|
||||
123
|
||||
123
|
||||
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user