Fix handling wrong JSONs.

This commit is contained in:
Vitaly Baranov 2019-05-16 15:16:21 +03:00
parent f4942007e1
commit 263fc16bd5
2 changed files with 26 additions and 25 deletions

View File

@ -1,7 +1,7 @@
#include <Functions/FunctionsJSON.h>
#include <Functions/DummyJSONParser.h>
#include <Functions/SimdJSONParser.h>
#include <Core/CpuId.h>
#include <Common/CpuId.h>
namespace DB

View File

@ -130,38 +130,39 @@ public:
{
bool ok = parser.parse(reinterpret_cast<const char *>(&chars[offsets[i - 1]]), offsets[i] - offsets[i - 1] - 1);
auto it = parser.getRoot();
for (const auto j : ext::range(0, moves.size()))
if (ok)
{
if (!ok)
break;
auto it = parser.getRoot();
/// Perform moves.
switch (moves[j].type)
for (size_t j = 0; (j != moves.size()) && ok; ++j)
{
case MoveType::ConstIndex:
ok = moveIteratorToElementByIndex(it, moves[j].index);
break;
case MoveType::ConstKey:
ok = moveIteratorToElementByKey(it, moves[j].key);
break;
case MoveType::Index:
switch (moves[j].type)
{
const Field field = (*block.getByPosition(arguments[j + 1]).column)[i];
ok = moveIteratorToElementByIndex(it, field.get<Int64>());
break;
}
case MoveType::Key:
{
const Field field = (*block.getByPosition(arguments[j + 1]).column)[i];
ok = moveIteratorToElementByKey(it, field.get<String>().data());
break;
case MoveType::ConstIndex:
ok = moveIteratorToElementByIndex(it, moves[j].index);
break;
case MoveType::ConstKey:
ok = moveIteratorToElementByKey(it, moves[j].key);
break;
case MoveType::Index:
{
const Field field = (*block.getByPosition(arguments[j + 1]).column)[i];
ok = moveIteratorToElementByIndex(it, field.get<Int64>());
break;
}
case MoveType::Key:
{
const Field field = (*block.getByPosition(arguments[j + 1]).column)[i];
ok = moveIteratorToElementByKey(it, field.get<String>().data());
break;
}
}
}
}
if (ok)
ok = impl.addValueToColumn(*to, it);
if (ok)
ok = impl.addValueToColumn(*to, it);
}
/// We add default value (=null or zero) if something goes wrong, we don't throw exceptions in these JSON functions.
if (!ok)