提交 101276e5 编写于 作者: A Alexey Milovidov

Allowed to switch between 'basic' and 'best effort' methods of parsing DateTime from text #1710

上级 2152b932
......@@ -55,6 +55,7 @@ BlockInputStreamPtr FormatFactory::getInput(const String & name, ReadBuffer & bu
format_settings.csv.delimiter = settings.format_csv_delimiter;
format_settings.values.interpret_expressions = settings.input_format_values_interpret_expressions;
format_settings.skip_unknown_fields = settings.input_format_skip_unknown_fields;
format_settings.date_time_input_format = settings.date_time_input_format;
auto wrap_row_stream = [&](auto && row_stream)
{
......
......@@ -262,6 +262,8 @@ struct Settings
M(SettingUInt64, max_network_bandwidth_for_all_users, 0, "The maximum speed of data exchange over the network in bytes per second for all concurrently running queries. Zero means unlimited.") \
M(SettingChar, format_csv_delimiter, ',', "The character to be considered as a delimiter in CSV data. If setting with a string, a string has to have a length of 1.") \
M(SettingUInt64, enable_conditional_computation, 0, "Enable conditional computations") \
\
M(SettingDateTimeInputFormat, date_time_input_format, FormatSettings::DateTimeInputFormat::Basic, "Method to read DateTime from text input formats. Possible values: 'basic' and 'best_effort'.") \
#define DECLARE(TYPE, NAME, DEFAULT, DESCRIPTION) \
TYPE NAME {DEFAULT};
......
......@@ -23,6 +23,7 @@ namespace ErrorCodes
extern const int UNKNOWN_DISTRIBUTED_PRODUCT_MODE;
extern const int UNKNOWN_GLOBAL_SUBQUERIES_METHOD;
extern const int SIZE_OF_FIXED_STRING_DOESNT_MATCH;
extern const int BAD_ARGUMENTS;
}
template <typename IntType>
......@@ -580,4 +581,49 @@ void SettingChar::write(WriteBuffer & buf) const
writeBinary(toString(), buf);
}
SettingDateTimeInputFormat::Value SettingDateTimeInputFormat::getValue(const String & s)
{
if (s == "basic") return Value::Basic;
if (s == "best_effort") return Value::BestEffort;
throw Exception("Unknown DateTime input format: '" + s + "', must be one of 'basic', 'best_effort'", ErrorCodes::BAD_ARGUMENTS);
}
String SettingDateTimeInputFormat::toString() const
{
const char * strings[] = {"basic", "best_effort"};
if (value < Value::Basic || value > Value::BestEffort)
throw Exception("Unknown DateTime input format", ErrorCodes::BAD_ARGUMENTS);
return strings[static_cast<size_t>(value)];
}
void SettingDateTimeInputFormat::set(Value x)
{
value = x;
changed = true;
}
void SettingDateTimeInputFormat::set(const Field & x)
{
set(safeGet<const String &>(x));
}
void SettingDateTimeInputFormat::set(const String & x)
{
set(getValue(x));
}
void SettingDateTimeInputFormat::set(ReadBuffer & buf)
{
String x;
readBinary(x, buf);
set(x);
}
void SettingDateTimeInputFormat::write(WriteBuffer & buf) const
{
writeBinary(toString(), buf);
}
}
......@@ -2,6 +2,7 @@
#include <Poco/Timespan.h>
#include <DataStreams/SizeLimits.h>
#include <DataTypes/FormatSettings.h>
#include <IO/CompressedStream.h>
#include <Core/Types.h>
......@@ -348,4 +349,28 @@ public:
void write(WriteBuffer & buf) const;
};
struct SettingDateTimeInputFormat
{
using Value = FormatSettings::DateTimeInputFormat;
Value value;
bool changed = false;
SettingDateTimeInputFormat(Value x) : value(x) {}
operator Value() const { return value; }
SettingDateTimeInputFormat & operator= (Value x) { set(x); return *this; }
static Value getValue(const String & s);
String toString() const;
void set(Value x);
void set(const Field & x);
void set(const String & x);
void set(ReadBuffer & buf);
void write(WriteBuffer & buf) const;
};
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册