style: improve code aesthetics

This commit is contained in:
Robert Schulze 2022-08-17 19:09:56 +00:00
parent a0693c3a84
commit 164fc3d296
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
6 changed files with 18 additions and 24 deletions

View File

@ -611,7 +611,7 @@ public:
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
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);
if (arguments.size() == 2)
@ -627,7 +627,7 @@ public:
{
throw Exception(
"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 "
"a constant string with timezone name. The timezone argument is allowed "
"only when the 1st argument has the type DateTime",

View File

@ -46,7 +46,7 @@ public:
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
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>();
}

View File

@ -62,7 +62,7 @@ protected:
DataTypePtr argument_type = arguments[i].type;
if (!isNumber(argument_type))
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()];
if (!isNumber(fraction_argument.type))
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

View File

@ -26,22 +26,16 @@ class FunctionThrowIf : public IFunction
{
public:
static constexpr auto name = "throwIf";
static FunctionPtr create(ContextPtr)
{
return std::make_shared<FunctionThrowIf>();
}
String getName() const override
{
return name;
}
String getName() const override { return name; }
bool isVariadic() const override { return true; }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
size_t getNumberOfArguments() const override
{
return 0;
}
size_t getNumberOfArguments() const override { return 0; }
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
@ -55,12 +49,13 @@ public:
if (!isNativeNumber(arguments[0]))
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Argument for function {} must be number",
getName());
"First argument of function {} must be a number (passed: {})",
getName(),
arguments[0]->getName());
if (number_of_arguments > 1 && !isString(arguments[1]))
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(),
getName());
@ -86,9 +81,7 @@ public:
{
const auto * message_column = checkAndGetColumnConst<ColumnString>(arguments[1].column.get());
if (!message_column)
throw Exception(ErrorCodes::ILLEGAL_COLUMN,
"Second argument for function {} must be constant String",
getName());
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Second argument for function {} must be constant String", getName());
custom_message = message_column->getValue<String>();
}
@ -108,12 +101,13 @@ public:
|| (res = execute<Float32>(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;
}
private:
template <typename T>
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])))
{
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();

View File

@ -4,7 +4,7 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../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"
${CLICKHOUSE_CLIENT} --server_logs_file /dev/null --query="SELECT throwIf(number = 1000000) FROM system.numbers" 2>&1 | grep -cF "$default_exception_message"

View File

@ -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;"
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;"