未验证 提交 2b124c5a 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #6718 from vitlibar/fix-extract-tuple-from-json

Fix extracting a Tuple from JSON
......@@ -733,16 +733,15 @@ struct JSONExtractTree
if (!JSONParser::firstArrayElement(it2))
return false;
size_t index = 0;
do
for (size_t index = 0; index != nested.size(); ++index)
{
if (nested[index]->addValueToColumn(tuple.getColumn(index), it2))
were_valid_elements = true;
else
tuple.getColumn(index).insertDefault();
++index;
if (!JSONParser::nextArrayElement(it2))
break;
}
while (JSONParser::nextArrayElement(it2));
set_size(old_size + static_cast<size_t>(were_valid_elements));
return were_valid_elements;
......@@ -756,16 +755,15 @@ struct JSONExtractTree
if (!JSONParser::firstObjectMember(it2))
return false;
size_t index = 0;
do
for (size_t index = 0; index != nested.size(); ++index)
{
if (nested[index]->addValueToColumn(tuple.getColumn(index), it2))
were_valid_elements = true;
else
tuple.getColumn(index).insertDefault();
++index;
if (!JSONParser::nextObjectMember(it2))
break;
}
while (JSONParser::nextObjectMember(it2));
}
else
{
......
......@@ -46,6 +46,13 @@ hello
1
Thursday
Friday
(3,5)
(7,3)
(5,0)
(3,5)
(3,0)
(3,5)
(3,0)
--JSONExtractKeysAndValues--
[('a','hello')]
[('b',[-100,200,300])]
......@@ -121,6 +128,13 @@ hello
1
Thursday
Friday
(3,5)
(7,3)
(5,0)
(3,5)
(3,0)
(3,5)
(3,0)
--JSONExtractKeysAndValues--
[('a','hello')]
[('b',[-100,200,300])]
......
......@@ -54,6 +54,13 @@ SELECT JSONExtract('{"a": "hello", "b": [-100, 200.0, 300]}', 'b', 4, 'Nullable(
SELECT JSONExtract('{"passed": true}', 'passed', 'UInt8');
SELECT JSONExtract('{"day": "Thursday"}', 'day', 'Enum8(\'Sunday\' = 0, \'Monday\' = 1, \'Tuesday\' = 2, \'Wednesday\' = 3, \'Thursday\' = 4, \'Friday\' = 5, \'Saturday\' = 6)');
SELECT JSONExtract('{"day": 5}', 'day', 'Enum8(\'Sunday\' = 0, \'Monday\' = 1, \'Tuesday\' = 2, \'Wednesday\' = 3, \'Thursday\' = 4, \'Friday\' = 5, \'Saturday\' = 6)');
SELECT JSONExtract('{"a":3,"b":5,"c":7}', 'Tuple(a Int, b Int)');
SELECT JSONExtract('{"a":3,"b":5,"c":7}', 'Tuple(c Int, a Int)');
SELECT JSONExtract('{"a":3,"b":5,"c":7}', 'Tuple(b Int, d Int)');
SELECT JSONExtract('{"a":3,"b":5,"c":7}', 'Tuple(Int, Int)');
SELECT JSONExtract('{"a":3}', 'Tuple(Int, Int)');
SELECT JSONExtract('[3,5,7]', 'Tuple(Int, Int)');
SELECT JSONExtract('[3]', 'Tuple(Int, Int)');
SELECT '--JSONExtractKeysAndValues--';
SELECT JSONExtractKeysAndValues('{"a": "hello", "b": [-100, 200.0, 300]}', 'String');
......@@ -138,6 +145,13 @@ SELECT JSONExtract('{"a": "hello", "b": [-100, 200.0, 300]}', 'b', 4, 'Nullable(
SELECT JSONExtract('{"passed": true}', 'passed', 'UInt8');
SELECT JSONExtract('{"day": "Thursday"}', 'day', 'Enum8(\'Sunday\' = 0, \'Monday\' = 1, \'Tuesday\' = 2, \'Wednesday\' = 3, \'Thursday\' = 4, \'Friday\' = 5, \'Saturday\' = 6)');
SELECT JSONExtract('{"day": 5}', 'day', 'Enum8(\'Sunday\' = 0, \'Monday\' = 1, \'Tuesday\' = 2, \'Wednesday\' = 3, \'Thursday\' = 4, \'Friday\' = 5, \'Saturday\' = 6)');
SELECT JSONExtract('{"a":3,"b":5,"c":7}', 'Tuple(a Int, b Int)');
SELECT JSONExtract('{"a":3,"b":5,"c":7}', 'Tuple(c Int, a Int)');
SELECT JSONExtract('{"a":3,"b":5,"c":7}', 'Tuple(b Int, d Int)');
SELECT JSONExtract('{"a":3,"b":5,"c":7}', 'Tuple(Int, Int)');
SELECT JSONExtract('{"a":3}', 'Tuple(Int, Int)');
SELECT JSONExtract('[3,5,7]', 'Tuple(Int, Int)');
SELECT JSONExtract('[3]', 'Tuple(Int, Int)');
SELECT '--JSONExtractKeysAndValues--';
SELECT JSONExtractKeysAndValues('{"a": "hello", "b": [-100, 200.0, 300]}', 'String');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册