ClickHouse/dbms/src/Parsers/ASTWithAlias.h

39 lines
1.0 KiB
C++
Raw Normal View History

2014-07-03 22:39:13 +00:00
#pragma once
#include <Parsers/IAST.h>
2014-07-03 22:39:13 +00:00
namespace DB
{
2017-05-27 17:27:16 +00:00
/** Base class for AST, which can contain an alias (identifiers, literals, functions).
2014-07-03 22:39:13 +00:00
*/
class ASTWithAlias : public IAST
{
public:
2017-05-27 17:27:16 +00:00
/// The alias, if any, or an empty string.
String alias;
2014-07-03 22:39:13 +00:00
using IAST::IAST;
2014-07-03 22:39:13 +00:00
2017-07-26 01:21:19 +00:00
String getAliasOrColumnName() const override { return alias.empty() ? getColumnName() : alias; }
String tryGetAlias() const override { return alias; }
void setAlias(const String & to) override { alias = to; }
2015-08-06 04:28:59 +00:00
2017-05-27 17:27:16 +00:00
/// Calls formatImplWithoutAlias, and also outputs an alias. If necessary, encloses the entire expression in brackets.
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override final;
2015-08-06 04:28:59 +00:00
virtual void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const = 0;
2014-07-03 22:39:13 +00:00
};
/// helper for setting aliases and chaining result to other functions
inline ASTPtr setAlias(ASTPtr ast, const String & alias)
{
ast->setAlias(alias);
return ast;
};
2014-07-03 22:39:13 +00:00
}