ClickHouse/src/Interpreters/addTypeConversionToAST.cpp

27 lines
643 B
C++
Raw Normal View History

2019-06-14 19:39:56 +00:00
#include "addTypeConversionToAST.h"
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTExpressionList.h>
#include <Parsers/ASTWithAlias.h>
namespace DB
{
ASTPtr addTypeConversionToAST(ASTPtr && ast, const String & type_name)
{
2019-06-16 16:47:47 +00:00
auto func = makeASTFunction("CAST", ast, std::make_shared<ASTLiteral>(type_name));
2019-06-14 19:39:56 +00:00
2019-06-16 16:47:47 +00:00
if (ASTWithAlias * ast_with_alias = dynamic_cast<ASTWithAlias *>(ast.get()))
2019-06-14 19:39:56 +00:00
{
func->alias = ast_with_alias->alias;
func->prefer_alias_to_column_name = ast_with_alias->prefer_alias_to_column_name;
ast_with_alias->alias.clear();
}
2019-06-16 16:47:47 +00:00
return func;
2019-06-14 19:39:56 +00:00
}
}