mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Added ability to skip plain JSON arrays. [#METR-22801]
This commit is contained in:
parent
68dffa3970
commit
3c045e1545
@ -810,7 +810,7 @@ inline void skipWhitespaceIfAny(ReadBuffer & buf)
|
||||
++buf.position();
|
||||
}
|
||||
|
||||
/// Skip json value (except array and object).
|
||||
/// Skips json value. If the value contains objects (i.e. {...} sequence), an exception will be thrown.
|
||||
void skipJSONFieldPlain(ReadBuffer & buf, const String & name_of_filed = "");
|
||||
|
||||
|
||||
|
@ -595,11 +595,41 @@ void skipJSONFieldPlain(ReadBuffer & buf, const String & name_of_filed)
|
||||
{
|
||||
assertString("true", buf);
|
||||
}
|
||||
else if (*buf.position() == 'f')/// skip false
|
||||
else if (*buf.position() == 'f') /// skip false
|
||||
{
|
||||
assertString("false", buf);
|
||||
}
|
||||
else if (*buf.position() == '{' || *buf.position() == '[') /// fail on nested objects
|
||||
else if (*buf.position() == '[')
|
||||
{
|
||||
++buf.position();
|
||||
skipWhitespaceIfAny(buf);
|
||||
|
||||
if (!buf.eof() && *buf.position() == ']') /// skip empty array
|
||||
{
|
||||
++buf.position();
|
||||
return;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
skipJSONFieldPlain(buf, name_of_filed);
|
||||
skipWhitespaceIfAny(buf);
|
||||
|
||||
if (!buf.eof() && *buf.position() == ',')
|
||||
{
|
||||
++buf.position();
|
||||
skipWhitespaceIfAny(buf);
|
||||
}
|
||||
else if (!buf.eof() && *buf.position() == ']')
|
||||
{
|
||||
++buf.position();
|
||||
break;
|
||||
}
|
||||
else
|
||||
throw Exception("Unexpected symbol for key '" + name_of_filed + "'", ErrorCodes::INCORRECT_DATA);
|
||||
}
|
||||
}
|
||||
else if (*buf.position() == '{') /// fail on objects
|
||||
{
|
||||
throw Exception("Unexpected nested field for key '" + name_of_filed + "'", ErrorCodes::INCORRECT_DATA);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user