Merge pull request #33971 from Avogar/fix-ipv6

Fix parsing IPv6 from query parameter and fix IPv6 to string conversion
This commit is contained in:
Maksim Kita 2022-01-25 22:45:11 +01:00 committed by GitHub
commit bf768a94e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 2 deletions

View File

@ -1772,6 +1772,12 @@ private:
}
}
if constexpr (std::is_same_v<ToDataType, DataTypeString>)
{
if (from_type->getCustomSerialization())
return ConvertImplGenericToString<ColumnString>::execute(arguments, result_type, input_rows_count);
}
bool done;
if constexpr (to_string_or_fixed_string)
{
@ -3409,7 +3415,7 @@ private:
return false;
};
auto make_custom_serialization_wrapper = [&](const auto & types) -> bool
auto make_custom_serialization_wrapper = [&](const auto & types) -> bool
{
using Types = std::decay_t<decltype(types)>;
using ToDataType = typename Types::RightType;

View File

@ -69,7 +69,14 @@ void ReplaceQueryParameterVisitor::visitQueryParameter(ASTPtr & ast)
" because it isn't parsed completely: only {} of {} bytes was parsed: {}",
value, type_name, ast_param.name, read_buffer.count(), value.size(), value.substr(0, read_buffer.count()));
ast = addTypeConversionToAST(std::make_shared<ASTLiteral>(temp_column[0]), type_name);
Field literal;
/// If data type has custom serialization, we should use CAST from String,
/// because CAST from field may not work correctly (for example for type IPv6).
if (data_type->getCustomSerialization())
literal = value;
else
literal = temp_column[0];
ast = addTypeConversionToAST(std::make_shared<ASTLiteral>(literal), type_name);
/// Keep the original alias.
ast->setAlias(alias);

View File

@ -0,0 +1,2 @@
2001:db9:85a3::8a2e:370:7334
2001:db8:85a3::8a2e:370:7334

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Tags: no-parallel, no-fasttest
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
$CLICKHOUSE_CLIENT -q "select toString(toIPv6('2001:db9:85a3::8a2e:370:7334'))"
$CLICKHOUSE_CLIENT --param_var 2001:db8:85a3::8a2e:370:7334 -q "select {var:IPv6}"