Merge pull request #11916 from ClickHouse/query-parameters-keep-alias

Keep aliases for substitutions in query.
This commit is contained in:
alexey-milovidov 2020-06-24 20:27:15 +03:00 committed by GitHub
commit 2ce2588770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View File

@ -49,6 +49,7 @@ void ReplaceQueryParameterVisitor::visitQueryParameter(ASTPtr & ast)
const auto & ast_param = ast->as<ASTQueryParameter &>();
const String & value = getParamValue(ast_param.name);
const String & type_name = ast_param.type;
String alias = ast_param.alias;
const auto data_type = DataTypeFactory::instance().get(type_name);
auto temp_column_ptr = data_type->createColumn();
@ -63,6 +64,7 @@ void ReplaceQueryParameterVisitor::visitQueryParameter(ASTPtr & ast)
+ value.substr(0, read_buffer.count()), ErrorCodes::BAD_QUERY_PARAMETER);
ast = addTypeConversionToAST(std::make_shared<ASTLiteral>(temp_column[0]), type_name);
ast->setAlias(alias);
}
}

View File

@ -0,0 +1,3 @@
a
Nullable(Nothing)
\N

View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
$CLICKHOUSE_CLIENT --param_x '\N' --query 'SELECT {x:Nullable(Nothing)} as a' --format TSVWithNamesAndTypes