json extract string or raw

This commit is contained in:
Amos Bird 2021-06-18 15:09:04 +08:00
parent 2b62a09aa3
commit 0adad2425a
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
4 changed files with 10 additions and 3 deletions

View File

@ -600,6 +600,8 @@ 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>
@ -630,7 +632,10 @@ struct JSONExtractTree
public:
bool insertResultToColumn(IColumn & dest, const Element & element) override
{
return JSONExtractStringImpl<JSONParser>::insertResultToColumn(dest, element, {});
if (element.isString())
return JSONExtractStringImpl<JSONParser>::insertResultToColumn(dest, element, {});
else
return JSONExtractRawImpl<JSONParser>::insertResultToColumn(dest, element, {});
}
};

View File

@ -58,7 +58,7 @@ Friday
(3,5)
(3,0)
--JSONExtractKeysAndValues--
[('a','hello')]
[('a','hello'),('b','[-100,200,300]')]
[('b',[-100,200,300])]
[('a','hello'),('b','world')]
[('a',5),('b',7),('c',11)]
@ -160,7 +160,7 @@ Friday
(3,5)
(3,0)
--JSONExtractKeysAndValues--
[('a','hello')]
[('a','hello'),('b','[-100,200,300]')]
[('b',[-100,200,300])]
[('a','hello'),('b','world')]
[('a',5),('b',7),('c',11)]

View File

@ -0,0 +1 @@
('123','456','[7,8,9]')

View File

@ -0,0 +1 @@
select JSONExtract('{"a": "123", "b": 456, "c": [7, 8, 9]}', 'Tuple(a String, b String, c String)');