2023-11-27 03:50:34 +00:00
|
|
|
#include <Storages/ReplaceAliasByExpressionVisitor.h>
|
|
|
|
|
2023-11-25 15:17:48 +00:00
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Parsers/ASTLiteral.h>
|
|
|
|
#include <Storages/ColumnsDescription.h>
|
|
|
|
#include <Common/typeid_cast.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2023-11-27 03:50:34 +00:00
|
|
|
void ReplaceAliasByExpressionMatcher::visit(ASTPtr & ast, Data & data)
|
2023-11-25 15:17:48 +00:00
|
|
|
{
|
|
|
|
if (auto * identifier = ast->as<ASTIdentifier>())
|
|
|
|
{
|
|
|
|
visit(*identifier, ast, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 03:50:34 +00:00
|
|
|
void ReplaceAliasByExpressionMatcher::visit(const ASTIdentifier & column, ASTPtr & ast, Data & data)
|
2023-11-25 15:17:48 +00:00
|
|
|
{
|
|
|
|
const auto & column_name = column.name();
|
|
|
|
if (data.columns.hasAlias(column_name))
|
|
|
|
{
|
|
|
|
/// Alias expr is saved in default expr.
|
|
|
|
if (auto col_default = data.columns.getDefault(column_name))
|
|
|
|
{
|
|
|
|
ast = col_default->expression->clone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|