mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
Merge pull request #33168 from ClickHouse/fix-clang-tidy
Fix clang-tidy
This commit is contained in:
commit
6c3b3bd0c5
@ -19,7 +19,13 @@ namespace ErrorCodes
|
|||||||
extern const int CANNOT_PARSE_BOOL;
|
extern const int CANNOT_PARSE_BOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const ColumnUInt8 * checkAndGetSerializeColumnType(const IColumn & column)
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
constexpr char str_true[5] = "true";
|
||||||
|
constexpr char str_false[6] = "false";
|
||||||
|
|
||||||
|
const ColumnUInt8 * checkAndGetSerializeColumnType(const IColumn & column)
|
||||||
{
|
{
|
||||||
const auto * col = checkAndGetColumn<ColumnUInt8>(&column);
|
const auto * col = checkAndGetColumn<ColumnUInt8>(&column);
|
||||||
if (!checkAndGetColumn<ColumnUInt8>(&column))
|
if (!checkAndGetColumn<ColumnUInt8>(&column))
|
||||||
@ -28,7 +34,7 @@ static const ColumnUInt8 * checkAndGetSerializeColumnType(const IColumn & column
|
|||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ColumnUInt8 * checkAndGetDeserializeColumnType(IColumn & column)
|
ColumnUInt8 * checkAndGetDeserializeColumnType(IColumn & column)
|
||||||
{
|
{
|
||||||
auto * col = typeid_cast<ColumnUInt8 *>(&column);
|
auto * col = typeid_cast<ColumnUInt8 *>(&column);
|
||||||
if (!checkAndGetColumn<ColumnUInt8>(&column))
|
if (!checkAndGetColumn<ColumnUInt8>(&column))
|
||||||
@ -37,6 +43,166 @@ static ColumnUInt8 * checkAndGetDeserializeColumnType(IColumn & column)
|
|||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serializeCustom(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings)
|
||||||
|
{
|
||||||
|
const auto * col = checkAndGetSerializeColumnType(column);
|
||||||
|
|
||||||
|
if (col->getData()[row_num])
|
||||||
|
{
|
||||||
|
writeString(settings.bool_true_representation, ostr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
writeString(settings.bool_false_representation, ostr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void serializeSimple(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &)
|
||||||
|
{
|
||||||
|
const auto * col = checkAndGetSerializeColumnType(column);
|
||||||
|
|
||||||
|
if (col->getData()[row_num])
|
||||||
|
ostr.write(str_true, sizeof(str_true) - 1);
|
||||||
|
else
|
||||||
|
ostr.write(str_false, sizeof(str_false) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tryDeserializeAllVariants(ColumnUInt8 * column, ReadBuffer & istr)
|
||||||
|
{
|
||||||
|
if (checkCharCaseInsensitive('1', istr))
|
||||||
|
{
|
||||||
|
column->insert(true);
|
||||||
|
}
|
||||||
|
else if (checkCharCaseInsensitive('0', istr))
|
||||||
|
{
|
||||||
|
column->insert(false);
|
||||||
|
}
|
||||||
|
/// 'True' and 'T'
|
||||||
|
else if (checkCharCaseInsensitive('t', istr))
|
||||||
|
{
|
||||||
|
/// Check if it's just short form `T` or full form `True`
|
||||||
|
if (checkCharCaseInsensitive('r', istr))
|
||||||
|
{
|
||||||
|
if (!checkStringCaseInsensitive("ue", istr))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
column->insert(true);
|
||||||
|
}
|
||||||
|
/// 'False' and 'F'
|
||||||
|
else if (checkCharCaseInsensitive('f', istr))
|
||||||
|
{
|
||||||
|
/// Check if it's just short form `F` or full form `False`
|
||||||
|
if (checkCharCaseInsensitive('a', istr))
|
||||||
|
{
|
||||||
|
if (!checkStringCaseInsensitive("lse", istr))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
column->insert(false);
|
||||||
|
}
|
||||||
|
/// 'Yes' and 'Y'
|
||||||
|
else if (checkCharCaseInsensitive('y', istr))
|
||||||
|
{
|
||||||
|
/// Check if it's just short form `Y` or full form `Yes`
|
||||||
|
if (checkCharCaseInsensitive('e', istr))
|
||||||
|
{
|
||||||
|
if (!checkCharCaseInsensitive('s', istr))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
column->insert(true);
|
||||||
|
}
|
||||||
|
/// 'No' and 'N'
|
||||||
|
else if (checkCharCaseInsensitive('n', istr))
|
||||||
|
{
|
||||||
|
/// Check if it's just short form `N` or full form `No`
|
||||||
|
checkCharCaseInsensitive('o', istr);
|
||||||
|
column->insert(false);
|
||||||
|
}
|
||||||
|
/// 'On' and 'Off'
|
||||||
|
else if (checkCharCaseInsensitive('o', istr))
|
||||||
|
{
|
||||||
|
if (checkCharCaseInsensitive('n', istr))
|
||||||
|
column->insert(true);
|
||||||
|
else if (checkStringCaseInsensitive("ff", istr))
|
||||||
|
{
|
||||||
|
column->insert(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// 'Enable' and 'Enabled'
|
||||||
|
else if (checkStringCaseInsensitive("enable", istr))
|
||||||
|
{
|
||||||
|
/// Check if it's 'enable' or 'enabled'
|
||||||
|
checkCharCaseInsensitive('d', istr);
|
||||||
|
column->insert(true);
|
||||||
|
}
|
||||||
|
/// 'Disable' and 'Disabled'
|
||||||
|
else if (checkStringCaseInsensitive("disable", istr))
|
||||||
|
{
|
||||||
|
/// Check if it's 'disable' or 'disabled'
|
||||||
|
checkCharCaseInsensitive('d', istr);
|
||||||
|
column->insert(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeImpl(
|
||||||
|
IColumn & column, ReadBuffer & istr, const FormatSettings & settings, std::function<bool(ReadBuffer &)> check_end_of_value)
|
||||||
|
{
|
||||||
|
ColumnUInt8 * col = checkAndGetDeserializeColumnType(column);
|
||||||
|
|
||||||
|
PeekableReadBuffer buf(istr);
|
||||||
|
buf.setCheckpoint();
|
||||||
|
if (checkString(settings.bool_true_representation, buf) && check_end_of_value(buf))
|
||||||
|
{
|
||||||
|
col->insert(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.rollbackToCheckpoint();
|
||||||
|
if (checkString(settings.bool_false_representation, buf) && check_end_of_value(buf))
|
||||||
|
{
|
||||||
|
col->insert(false);
|
||||||
|
buf.dropCheckpoint();
|
||||||
|
if (buf.hasUnreadData())
|
||||||
|
throw Exception(
|
||||||
|
ErrorCodes::CANNOT_PARSE_BOOL,
|
||||||
|
"Cannot continue parsing after parsed bool value because it will result in the loss of some data. It may happen if "
|
||||||
|
"bool_true_representation or bool_false_representation contains some delimiters of input format");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.rollbackToCheckpoint();
|
||||||
|
if (tryDeserializeAllVariants(col, buf) && check_end_of_value(buf))
|
||||||
|
{
|
||||||
|
buf.dropCheckpoint();
|
||||||
|
if (buf.hasUnreadData())
|
||||||
|
throw Exception(
|
||||||
|
ErrorCodes::CANNOT_PARSE_BOOL,
|
||||||
|
"Cannot continue parsing after parsed bool value because it will result in the loss of some data. It may happen if "
|
||||||
|
"bool_true_representation or bool_false_representation contains some delimiters of input format");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.makeContinuousMemoryFromCheckpointToPos();
|
||||||
|
buf.rollbackToCheckpoint();
|
||||||
|
throw Exception(
|
||||||
|
ErrorCodes::CANNOT_PARSE_BOOL,
|
||||||
|
"Cannot parse boolean value here: '{}', should be '{}' or '{}' controlled by setting bool_true_representation and "
|
||||||
|
"bool_false_representation or one of "
|
||||||
|
"True/False/T/F/Y/N/Yes/No/On/Off/Enable/Disable/Enabled/Disabled/1/0",
|
||||||
|
String(buf.position(), std::min(10lu, buf.available())),
|
||||||
|
settings.bool_true_representation, settings.bool_false_representation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SerializationBool::SerializationBool(const SerializationPtr &nested_)
|
SerializationBool::SerializationBool(const SerializationPtr &nested_)
|
||||||
: SerializationWrapper(nested_)
|
: SerializationWrapper(nested_)
|
||||||
{
|
{
|
||||||
@ -160,166 +326,9 @@ void SerializationBool::deserializeWholeText(IColumn & column, ReadBuffer & istr
|
|||||||
deserializeImpl(column, istr, settings, [&](ReadBuffer & buf){ return buf.eof(); });
|
deserializeImpl(column, istr, settings, [&](ReadBuffer & buf){ return buf.eof(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializationBool::serializeCustom(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
|
||||||
{
|
|
||||||
const auto * col = checkAndGetSerializeColumnType(column);
|
|
||||||
|
|
||||||
if (col->getData()[row_num])
|
|
||||||
{
|
|
||||||
writeString(settings.bool_true_representation, ostr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
writeString(settings.bool_false_representation, ostr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SerializationBool::serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
void SerializationBool::serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
||||||
{
|
{
|
||||||
serializeSimple(column, row_num, ostr, settings);
|
serializeSimple(column, row_num, ostr, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializationBool::serializeSimple(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const
|
|
||||||
{
|
|
||||||
const auto * col = checkAndGetSerializeColumnType(column);
|
|
||||||
|
|
||||||
if (col->getData()[row_num])
|
|
||||||
ostr.write(str_true, sizeof(str_true) - 1);
|
|
||||||
else
|
|
||||||
ostr.write(str_false, sizeof(str_false) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SerializationBool::deserializeImpl(
|
|
||||||
IColumn & column, ReadBuffer & istr, const FormatSettings & settings, std::function<bool(ReadBuffer &)> check_end_of_value) const
|
|
||||||
{
|
|
||||||
ColumnUInt8 * col = checkAndGetDeserializeColumnType(column);
|
|
||||||
|
|
||||||
PeekableReadBuffer buf(istr);
|
|
||||||
buf.setCheckpoint();
|
|
||||||
if (checkString(settings.bool_true_representation, buf) && check_end_of_value(buf))
|
|
||||||
{
|
|
||||||
col->insert(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.rollbackToCheckpoint();
|
|
||||||
if (checkString(settings.bool_false_representation, buf) && check_end_of_value(buf))
|
|
||||||
{
|
|
||||||
col->insert(false);
|
|
||||||
buf.dropCheckpoint();
|
|
||||||
if (buf.hasUnreadData())
|
|
||||||
throw Exception(
|
|
||||||
ErrorCodes::CANNOT_PARSE_BOOL,
|
|
||||||
"Cannot continue parsing after parsed bool value because it will result in the loss of some data. It may happen if "
|
|
||||||
"bool_true_representation or bool_false_representation contains some delimiters of input format");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.rollbackToCheckpoint();
|
|
||||||
if (tryDeserializeAllVariants(col, buf) && check_end_of_value(buf))
|
|
||||||
{
|
|
||||||
buf.dropCheckpoint();
|
|
||||||
if (buf.hasUnreadData())
|
|
||||||
throw Exception(
|
|
||||||
ErrorCodes::CANNOT_PARSE_BOOL,
|
|
||||||
"Cannot continue parsing after parsed bool value because it will result in the loss of some data. It may happen if "
|
|
||||||
"bool_true_representation or bool_false_representation contains some delimiters of input format");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.makeContinuousMemoryFromCheckpointToPos();
|
|
||||||
buf.rollbackToCheckpoint();
|
|
||||||
throw Exception(
|
|
||||||
ErrorCodes::CANNOT_PARSE_BOOL,
|
|
||||||
"Cannot parse boolean value here: '{}', should be '{}' or '{}' controlled by setting bool_true_representation and "
|
|
||||||
"bool_false_representation or one of "
|
|
||||||
"True/False/T/F/Y/N/Yes/No/On/Off/Enable/Disable/Enabled/Disabled/1/0",
|
|
||||||
String(buf.position(), std::min(10lu, buf.available())),
|
|
||||||
settings.bool_true_representation, settings.bool_false_representation);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SerializationBool::tryDeserializeAllVariants(ColumnUInt8 * column, ReadBuffer & istr) const
|
|
||||||
{
|
|
||||||
if (checkCharCaseInsensitive('1', istr))
|
|
||||||
{
|
|
||||||
column->insert(true);
|
|
||||||
}
|
|
||||||
else if (checkCharCaseInsensitive('0', istr))
|
|
||||||
{
|
|
||||||
column->insert(false);
|
|
||||||
}
|
|
||||||
/// 'True' and 'T'
|
|
||||||
else if (checkCharCaseInsensitive('t', istr))
|
|
||||||
{
|
|
||||||
/// Check if it's just short form `T` or full form `True`
|
|
||||||
if (checkCharCaseInsensitive('r', istr))
|
|
||||||
{
|
|
||||||
if (!checkStringCaseInsensitive("ue", istr))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
column->insert(true);
|
|
||||||
}
|
|
||||||
/// 'False' and 'F'
|
|
||||||
else if (checkCharCaseInsensitive('f', istr))
|
|
||||||
{
|
|
||||||
/// Check if it's just short form `F` or full form `False`
|
|
||||||
if (checkCharCaseInsensitive('a', istr))
|
|
||||||
{
|
|
||||||
if (!checkStringCaseInsensitive("lse", istr))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
column->insert(false);
|
|
||||||
}
|
|
||||||
/// 'Yes' and 'Y'
|
|
||||||
else if (checkCharCaseInsensitive('y', istr))
|
|
||||||
{
|
|
||||||
/// Check if it's just short form `Y` or full form `Yes`
|
|
||||||
if (checkCharCaseInsensitive('e', istr))
|
|
||||||
{
|
|
||||||
if (!checkCharCaseInsensitive('s', istr))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
column->insert(true);
|
|
||||||
}
|
|
||||||
/// 'No' and 'N'
|
|
||||||
else if (checkCharCaseInsensitive('n', istr))
|
|
||||||
{
|
|
||||||
/// Check if it's just short form `N` or full form `No`
|
|
||||||
checkCharCaseInsensitive('o', istr);
|
|
||||||
column->insert(false);
|
|
||||||
}
|
|
||||||
/// 'On' and 'Off'
|
|
||||||
else if (checkCharCaseInsensitive('o', istr))
|
|
||||||
{
|
|
||||||
if (checkCharCaseInsensitive('n', istr))
|
|
||||||
column->insert(true);
|
|
||||||
else if (checkStringCaseInsensitive("ff", istr))
|
|
||||||
{
|
|
||||||
column->insert(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/// 'Enable' and 'Enabled'
|
|
||||||
else if (checkStringCaseInsensitive("enable", istr))
|
|
||||||
{
|
|
||||||
/// Check if it's 'enable' or 'enabled'
|
|
||||||
checkCharCaseInsensitive('d', istr);
|
|
||||||
column->insert(true);
|
|
||||||
}
|
|
||||||
/// 'Disable' and 'Disabled'
|
|
||||||
else if (checkStringCaseInsensitive("disable", istr))
|
|
||||||
{
|
|
||||||
/// Check if it's 'disable' or 'disabled'
|
|
||||||
checkCharCaseInsensitive('d', istr);
|
|
||||||
column->insert(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,6 @@ namespace DB
|
|||||||
|
|
||||||
class SerializationBool final : public SerializationWrapper
|
class SerializationBool final : public SerializationWrapper
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
static constexpr char str_true[5] = "true";
|
|
||||||
static constexpr char str_false[6] = "false";
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SerializationBool(const SerializationPtr & nested_);
|
SerializationBool(const SerializationPtr & nested_);
|
||||||
|
|
||||||
@ -36,12 +32,6 @@ public:
|
|||||||
void deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override;
|
void deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override;
|
||||||
|
|
||||||
void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override;
|
void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override;
|
||||||
|
|
||||||
protected:
|
|
||||||
void serializeCustom(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const;
|
|
||||||
void serializeSimple(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const;
|
|
||||||
void deserializeImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings, std::function<bool(ReadBuffer & buf)> check_end_of_value) const;
|
|
||||||
bool tryDeserializeAllVariants(ColumnUInt8 * column, ReadBuffer & istr) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user