提交 b843ea5b 编写于 作者: V Vitaliy Lyudvichenko 提交者: alexey-milovidov

Resolves #964. Fixed input_format_skip_unknown_fields for negative numbers. [#CLICKHOUSE-3]

上级 78921294
...@@ -11,15 +11,11 @@ ...@@ -11,15 +11,11 @@
#include <Poco/Util/XMLConfiguration.h> #include <Poco/Util/XMLConfiguration.h>
#include <Common/ZooKeeper/ZooKeeperNodeCache.h> #include <Common/ZooKeeper/ZooKeeperNodeCache.h>
#include <Common/StringUtils.h>
using namespace Poco::XML; using namespace Poco::XML;
static bool endsWith(const std::string & s, const std::string & suffix)
{
return s.size() >= suffix.size() && s.substr(s.size() - suffix.size()) == suffix;
}
/// Extracts from a string the first encountered number consisting of at least two digits. /// Extracts from a string the first encountered number consisting of at least two digits.
static std::string numberFromHost(const std::string & s) static std::string numberFromHost(const std::string & s)
{ {
...@@ -27,7 +23,7 @@ static std::string numberFromHost(const std::string & s) ...@@ -27,7 +23,7 @@ static std::string numberFromHost(const std::string & s)
{ {
std::string res; std::string res;
size_t j = i; size_t j = i;
while (j < s.size() && isdigit(s[j])) while (j < s.size() && isNumericASCII(s[j]))
res += s[j++]; res += s[j++];
if (res.size() >= 2) if (res.size() >= 2)
{ {
......
...@@ -587,7 +587,7 @@ struct ReplaceRegexpImpl ...@@ -587,7 +587,7 @@ struct ReplaceRegexpImpl
{ {
if (s[i] == '\\' && i + 1 < s.size()) if (s[i] == '\\' && i + 1 < s.size())
{ {
if (isdigit(s[i + 1])) /// Substitution if (isNumericASCII(s[i + 1])) /// Substitution
{ {
if (!now.empty()) if (!now.empty())
{ {
......
...@@ -683,7 +683,7 @@ void skipJSONFieldPlain(ReadBuffer & buf, const StringRef & name_of_filed) ...@@ -683,7 +683,7 @@ void skipJSONFieldPlain(ReadBuffer & buf, const StringRef & name_of_filed)
NullSink sink; NullSink sink;
readJSONStringInto(sink, buf); readJSONStringInto(sink, buf);
} }
else if (isNumericASCII(*buf.position())) /// skip number else if (isNumericASCII(*buf.position()) || *buf.position() == '-' || *buf.position() == '+') /// skip number
{ {
double v; double v;
if (!tryReadFloatText(v, buf)) if (!tryReadFloatText(v, buf))
...@@ -737,7 +737,7 @@ void skipJSONFieldPlain(ReadBuffer & buf, const StringRef & name_of_filed) ...@@ -737,7 +737,7 @@ void skipJSONFieldPlain(ReadBuffer & buf, const StringRef & name_of_filed)
} }
else else
{ {
throw Exception("Unexpected symbol for key '" + name_of_filed.toString() + "'", ErrorCodes::INCORRECT_DATA); throw Exception("Unexpected symbol '" + std::string(*buf.position(), 1) + "' for key '" + name_of_filed.toString() + "'", ErrorCodes::INCORRECT_DATA);
} }
} }
......
...@@ -1706,7 +1706,7 @@ static std::pair<String, DayNum_t> getMonthNameAndDayNum(const Field & partition ...@@ -1706,7 +1706,7 @@ static std::pair<String, DayNum_t> getMonthNameAndDayNum(const Field & partition
? toString(partition.get<UInt64>()) ? toString(partition.get<UInt64>())
: partition.safeGet<String>(); : partition.safeGet<String>();
if (month_name.size() != 6 || !std::all_of(month_name.begin(), month_name.end(), isdigit)) if (month_name.size() != 6 || !std::all_of(month_name.begin(), month_name.end(), isNumericASCII))
throw Exception("Invalid partition format: " + month_name + ". Partition should consist of 6 digits: YYYYMM", throw Exception("Invalid partition format: " + month_name + ". Partition should consist of 6 digits: YYYYMM",
ErrorCodes::INVALID_PARTITION_NAME); ErrorCodes::INVALID_PARTITION_NAME);
......
...@@ -52,7 +52,7 @@ static bool parseNumber(const String & description, size_t l, size_t r, size_t & ...@@ -52,7 +52,7 @@ static bool parseNumber(const String & description, size_t l, size_t r, size_t &
res = 0; res = 0;
for (size_t pos = l; pos < r; pos ++) for (size_t pos = l; pos < r; pos ++)
{ {
if (!isdigit(description[pos])) if (!isNumericASCII(description[pos]))
return false; return false;
res = res * 10 + description[pos] - '0'; res = res * 10 + description[pos] - '0';
if (res > 1e15) if (res > 1e15)
......
#!/usr/bin/env bash #!/usr/bin/env bash
clickhouse-client -n --query "DROP TABLE IF EXISTS test.json_noisy; CREATE TABLE test.json_noisy (d1 UInt8, d2 String) ENGINE = Memory" set -e
clickhouse-client -q "DROP TABLE IF EXISTS test.json_noisy"
clickhouse-client -q "CREATE TABLE test.json_noisy (d1 UInt8, d2 String) ENGINE = Memory"
echo '{"d1" : 1, "d2" : "ok"} echo '{"d1" : 1, "d2" : "ok"}
{ } { }
{"t1" : 0, "t2":true,"t3":false, "t4":null,"t5":[],"t6":"trash" } {"t1" : 0, "t2":true,"t3":false, "t4":null,"t5":[],"t6":"trash" }
{"d2":"ok","t1":[[[]],true, null, false, "1","2",9.03,101], "t2":[["1","2"]], "d1":"1"} {"d2":"ok","t1":[[[]],true, null, false, "1","2",9.03,101], "t2":[["1","2"]], "d1":"1"}
{"d2":"ok","t1":[[[]],true, null, false, "1","2", 0.03, 1], "d1":"1", "t2":["1","2"]}' \ {"d2":"ok","t1":[[[]],true, null, false, "1","2", 0.03, 1], "d1":"1", "t2":["1","2"]}
| clickhouse-client -n --query "SET input_format_skip_unknown_fields = 1; INSERT INTO test.json_noisy FORMAT JSONEachRow" {"t0" : -0.1, "t1" : +1, "t2" : 0, "t3" : [0.0, -0.1], "d2" : "ok", "d1" : 1}' \
| clickhouse-client --input_format_skip_unknown_fields=1 -q "INSERT INTO test.json_noisy FORMAT JSONEachRow"
clickhouse-client -n --query "SELECT * FROM test.json_noisy; DROP TABLE IF EXISTS test.json_noisy;" clickhouse-client --max_threads=1 -q "SELECT * FROM test.json_noisy"
clickhouse-client -q "DROP TABLE IF EXISTS test.json_noisy"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册