Merge pull request #25452 from amosbird/jsonextractrawstring

JSONExtract String or Raw
This commit is contained in:
alexey-milovidov 2021-07-09 06:17:13 +03:00 committed by GitHub
commit eafce775c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 3 deletions

View File

@ -607,6 +607,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. /// Nodes of the extract tree. We need the extract tree to extract from JSON complex values containing array, tuples or nullables.
template <typename JSONParser> template <typename JSONParser>
@ -691,7 +693,10 @@ struct JSONExtractTree
public: public:
bool insertResultToColumn(IColumn & dest, const Element & element) override bool insertResultToColumn(IColumn & dest, const Element & element) override
{ {
if (element.isString())
return JSONExtractStringImpl<JSONParser>::insertResultToColumn(dest, element, {}); return JSONExtractStringImpl<JSONParser>::insertResultToColumn(dest, element, {});
else
return JSONExtractRawImpl<JSONParser>::insertResultToColumn(dest, element, {});
} }
}; };

View File

@ -67,7 +67,7 @@ hello
1234567890.12345677879616925706 (1234567890.12345677879616925706,'test') 1234567890.12345677879616925706 (1234567890.12345677879616925706,'test')
1234567890.123456695758468374595199311875 (1234567890.123456695758468374595199311875,'test') 1234567890.123456695758468374595199311875 (1234567890.123456695758468374595199311875,'test')
--JSONExtractKeysAndValues-- --JSONExtractKeysAndValues--
[('a','hello')] [('a','hello'),('b','[-100,200,300]')]
[('b',[-100,200,300])] [('b',[-100,200,300])]
[('a','hello'),('b','world')] [('a','hello'),('b','world')]
[('a',5),('b',7),('c',11)] [('a',5),('b',7),('c',11)]
@ -170,7 +170,7 @@ Friday
(3,5) (3,5)
(3,0) (3,0)
--JSONExtractKeysAndValues-- --JSONExtractKeysAndValues--
[('a','hello')] [('a','hello'),('b','[-100,200,300]')]
[('b',[-100,200,300])] [('b',[-100,200,300])]
[('a','hello'),('b','world')] [('a','hello'),('b','world')]
[('a',5),('b',7),('c',11)] [('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)');