mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 09:02:00 +00:00
style: improve code aesthetics
This commit is contained in:
parent
a0693c3a84
commit
164fc3d296
@ -611,7 +611,7 @@ public:
|
|||||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||||
|
|
||||||
if (!isNativeNumber(arguments[1].type))
|
if (!isNativeNumber(arguments[1].type))
|
||||||
throw Exception("Second argument for function " + getName() + " (delta) must be number",
|
throw Exception("Second argument for function " + getName() + " (delta) must be a number",
|
||||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||||
|
|
||||||
if (arguments.size() == 2)
|
if (arguments.size() == 2)
|
||||||
@ -627,7 +627,7 @@ public:
|
|||||||
{
|
{
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Function " + getName() + " supports 2 or 3 arguments. The 1st argument "
|
"Function " + getName() + " supports 2 or 3 arguments. The 1st argument "
|
||||||
"must be of type Date or DateTime. The 2nd argument must be number. "
|
"must be of type Date or DateTime. The 2nd argument must be a number. "
|
||||||
"The 3rd argument (optional) must be "
|
"The 3rd argument (optional) must be "
|
||||||
"a constant string with timezone name. The timezone argument is allowed "
|
"a constant string with timezone name. The timezone argument is allowed "
|
||||||
"only when the 1st argument has the type DateTime",
|
"only when the 1st argument has the type DateTime",
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
||||||
{
|
{
|
||||||
if (!isNativeNumber(arguments.front()))
|
if (!isNativeNumber(arguments.front()))
|
||||||
throw Exception{"Argument for function " + getName() + " must be number", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
|
throw Exception{"Argument for function " + getName() + " must be a number", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
|
||||||
|
|
||||||
return std::make_shared<DataTypeUInt8>();
|
return std::make_shared<DataTypeUInt8>();
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ protected:
|
|||||||
DataTypePtr argument_type = arguments[i].type;
|
DataTypePtr argument_type = arguments[i].type;
|
||||||
if (!isNumber(argument_type))
|
if (!isNumber(argument_type))
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||||
"Argument '{}' for function {} must be number", std::string(argument_names[i]), getName());
|
"Argument '{}' for function {} must be a number", std::string(argument_names[i]), getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ public:
|
|||||||
const auto& fraction_argument = arguments[argument_names.size()];
|
const auto& fraction_argument = arguments[argument_names.size()];
|
||||||
if (!isNumber(fraction_argument.type))
|
if (!isNumber(fraction_argument.type))
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||||
"Argument 'fraction' for function {} must be number", getName());
|
"Argument 'fraction' for function {} must be a number", getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Optional precision argument
|
/// Optional precision argument
|
||||||
|
@ -26,22 +26,16 @@ class FunctionThrowIf : public IFunction
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static constexpr auto name = "throwIf";
|
static constexpr auto name = "throwIf";
|
||||||
|
|
||||||
static FunctionPtr create(ContextPtr)
|
static FunctionPtr create(ContextPtr)
|
||||||
{
|
{
|
||||||
return std::make_shared<FunctionThrowIf>();
|
return std::make_shared<FunctionThrowIf>();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getName() const override
|
String getName() const override { return name; }
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isVariadic() const override { return true; }
|
bool isVariadic() const override { return true; }
|
||||||
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
|
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
|
||||||
size_t getNumberOfArguments() const override
|
size_t getNumberOfArguments() const override { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
||||||
{
|
{
|
||||||
@ -55,12 +49,13 @@ public:
|
|||||||
|
|
||||||
if (!isNativeNumber(arguments[0]))
|
if (!isNativeNumber(arguments[0]))
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||||
"Argument for function {} must be number",
|
"First argument of function {} must be a number (passed: {})",
|
||||||
getName());
|
getName(),
|
||||||
|
arguments[0]->getName());
|
||||||
|
|
||||||
if (number_of_arguments > 1 && !isString(arguments[1]))
|
if (number_of_arguments > 1 && !isString(arguments[1]))
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||||
"Illegal type {} of argument of function {}",
|
"Second argument of function {} must be a string (passed: {})",
|
||||||
arguments[1]->getName(),
|
arguments[1]->getName(),
|
||||||
getName());
|
getName());
|
||||||
|
|
||||||
@ -86,9 +81,7 @@ public:
|
|||||||
{
|
{
|
||||||
const auto * message_column = checkAndGetColumnConst<ColumnString>(arguments[1].column.get());
|
const auto * message_column = checkAndGetColumnConst<ColumnString>(arguments[1].column.get());
|
||||||
if (!message_column)
|
if (!message_column)
|
||||||
throw Exception(ErrorCodes::ILLEGAL_COLUMN,
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Second argument for function {} must be constant String", getName());
|
||||||
"Second argument for function {} must be constant String",
|
|
||||||
getName());
|
|
||||||
|
|
||||||
custom_message = message_column->getValue<String>();
|
custom_message = message_column->getValue<String>();
|
||||||
}
|
}
|
||||||
@ -108,12 +101,13 @@ public:
|
|||||||
|| (res = execute<Float32>(in, custom_message))
|
|| (res = execute<Float32>(in, custom_message))
|
||||||
|| (res = execute<Float64>(in, custom_message))))
|
|| (res = execute<Float64>(in, custom_message))))
|
||||||
{
|
{
|
||||||
throw Exception{"Illegal column " + in->getName() + " of first argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN};
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of first argument of function {}", in->getName(), getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
ColumnPtr execute(const IColumn * in_untyped, const std::optional<String> & message) const
|
ColumnPtr execute(const IColumn * in_untyped, const std::optional<String> & message) const
|
||||||
{
|
{
|
||||||
@ -128,7 +122,7 @@ public:
|
|||||||
if (!memoryIsZero(in_data.data(), 0, in_data.size() * sizeof(in_data[0])))
|
if (!memoryIsZero(in_data.data(), 0, in_data.size() * sizeof(in_data[0])))
|
||||||
{
|
{
|
||||||
throw Exception(ErrorCodes::FUNCTION_THROW_IF_VALUE_IS_NON_ZERO,
|
throw Exception(ErrorCodes::FUNCTION_THROW_IF_VALUE_IS_NON_ZERO,
|
||||||
message.value_or("Value passed to '" + getName() + "' function is non zero"));
|
message.value_or("Value passed to '" + getName() + "' function is non-zero"));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t result_size = in_untyped->size();
|
size_t result_size = in_untyped->size();
|
||||||
|
@ -4,7 +4,7 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|||||||
# shellcheck source=../shell_config.sh
|
# shellcheck source=../shell_config.sh
|
||||||
. "$CURDIR"/../shell_config.sh
|
. "$CURDIR"/../shell_config.sh
|
||||||
|
|
||||||
default_exception_message="Value passed to 'throwIf' function is non zero"
|
default_exception_message="Value passed to 'throwIf' function is non-zero"
|
||||||
custom_exception_message="Number equals 1000000"
|
custom_exception_message="Number equals 1000000"
|
||||||
|
|
||||||
${CLICKHOUSE_CLIENT} --server_logs_file /dev/null --query="SELECT throwIf(number = 1000000) FROM system.numbers" 2>&1 | grep -cF "$default_exception_message"
|
${CLICKHOUSE_CLIENT} --server_logs_file /dev/null --query="SELECT throwIf(number = 1000000) FROM system.numbers" 2>&1 | grep -cF "$default_exception_message"
|
||||||
|
@ -10,6 +10,6 @@ $CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS check;"
|
|||||||
|
|
||||||
$CLICKHOUSE_CLIENT --query="CREATE TABLE check (x UInt64, y UInt64 DEFAULT throwIf(x > 1500000)) ENGINE = Memory;"
|
$CLICKHOUSE_CLIENT --query="CREATE TABLE check (x UInt64, y UInt64 DEFAULT throwIf(x > 1500000)) ENGINE = Memory;"
|
||||||
|
|
||||||
seq 1 2000000 | $CLICKHOUSE_CLIENT --query="INSERT INTO check(x) FORMAT TSV" 2>&1 | grep -q "Value passed to 'throwIf' function is non zero." && echo 'OK' || echo 'FAIL' ||:
|
seq 1 2000000 | $CLICKHOUSE_CLIENT --query="INSERT INTO check(x) FORMAT TSV" 2>&1 | grep -q "Value passed to 'throwIf' function is non-zero." && echo 'OK' || echo 'FAIL' ||:
|
||||||
|
|
||||||
$CLICKHOUSE_CLIENT --query="DROP TABLE check;"
|
$CLICKHOUSE_CLIENT --query="DROP TABLE check;"
|
||||||
|
Loading…
Reference in New Issue
Block a user