Fix style, fix typo and remove extra code

This commit is contained in:
Alexey Milovidov 2021-05-23 03:18:24 +03:00
parent e330fe4bb5
commit 0da00f6497

View File

@ -59,44 +59,30 @@ void registerCodecDensity(CompressionCodecFactory & factory)
[&](const ASTPtr & arguments) -> CompressionCodecPtr [&](const ASTPtr & arguments) -> CompressionCodecPtr
{ {
DENSITY_ALGORITHM algo = CompressionCodecDensity::DENSITY_DEFAULT_ALGO; DENSITY_ALGORITHM algo = CompressionCodecDensity::DENSITY_DEFAULT_ALGO;
//std::cerr << arguments << std::endl;
if (arguments && !arguments->children.empty()) if (arguments && !arguments->children.empty())
{ {
if (arguments->children.size() != 1) if (arguments->children.size() != 1)
throw Exception( throw Exception(
"Deisnty codec must have 1 parameter, given " + std::to_string(arguments->children.size()), "Density codec must have only one parameter, given " + std::to_string(arguments->children.size()),
ErrorCodes::ILLEGAL_SYNTAX_FOR_CODEC_TYPE); ErrorCodes::ILLEGAL_SYNTAX_FOR_CODEC_TYPE);
const auto children = arguments->children; const auto children = arguments->children;
const auto * algo_literal = children[0]->as<ASTLiteral>(); const auto * algo_literal = children[0]->as<ASTLiteral>();
if (!algo_literal) if (!algo_literal || algo_literal->value.getType() != Field::Types::String)
throw Exception("Density codec argument must be string (algorithm)", ErrorCodes::ILLEGAL_CODEC_PARAMETER); throw Exception("Density codec argument must be string (algorithm), one of: 'lion', 'chameleon', 'cheetah'",
ErrorCodes::ILLEGAL_CODEC_PARAMETER);
const auto algorithm = algo_literal->value.safeGet<std::string>();
if (algo_literal->value.getType() == Field::Types::Which::UInt64) { if (algorithm == "lion")
const auto algorithm = algo_literal->value.safeGet<UInt64>(); algo = DENSITY_ALGORITHM_LION;
if (algorithm == 3) { else if (algorithm == "chameleon")
algo = DENSITY_ALGORITHM_LION; algo = DENSITY_ALGORITHM_CHAMELEON;
} else if (algorithm == 2) { else if (algorithm == "cheetah")
algo = DENSITY_ALGORITHM_CHEETAH; algo = DENSITY_ALGORITHM_CHEETAH;
} else if (algorithm == 1) { else
algo = DENSITY_ALGORITHM_CHAMELEON; throw Exception("Density codec argument may be one of: 'lion', 'chameleon', 'cheetah'", ErrorCodes::ILLEGAL_CODEC_PARAMETER);
} else {
throw Exception("Density codec argument may be LION, CHAMELEON, CHEETAH", ErrorCodes::ILLEGAL_CODEC_PARAMETER);
}
} else {
const auto algorithm = algo_literal->value.safeGet<std::string>();
if (algorithm == "LION") {
algo = DENSITY_ALGORITHM_LION;
} else if (algorithm == "CHAMELEON") {
algo = DENSITY_ALGORITHM_CHAMELEON;
} else if (algorithm == "CHEETAH") {
algo = DENSITY_ALGORITHM_CHEETAH;
} else {
throw Exception("Density codec argument may be LION, CHAMELEON, CHEETAH", ErrorCodes::ILLEGAL_CODEC_PARAMETER);
}
}
} }
return std::make_shared<CompressionCodecDensity>(algo); return std::make_shared<CompressionCodecDensity>(algo);