ClickHouse/src/Parsers/ASTProjectionSelectQuery.h
Amos Bird 9bbc9f97b4
Implement antlr parser for projections (#24245)
* implement projection grammer for antlr parser

* Add comment
2021-06-02 18:09:55 +03:00

57 lines
1.4 KiB
C++

#pragma once
#include <Core/Names.h>
#include <Parsers/IAST.h>
namespace DB
{
/** PROJECTION SELECT query
*/
class ASTProjectionSelectQuery : public IAST
{
public:
enum class Expression : uint8_t
{
WITH,
SELECT,
GROUP_BY,
ORDER_BY,
};
/** Get the text that identifies this element. */
String getID(char) const override { return "ProjectionSelectQuery"; }
ASTPtr clone() const override;
ASTPtr & refSelect() { return getExpression(Expression::SELECT); }
const ASTPtr with() const { return getExpression(Expression::WITH); }
const ASTPtr select() const { return getExpression(Expression::SELECT); }
const ASTPtr groupBy() const { return getExpression(Expression::GROUP_BY); }
const ASTPtr orderBy() const { return getExpression(Expression::ORDER_BY); }
/// Set/Reset/Remove expression.
void setExpression(Expression expr, ASTPtr && ast);
ASTPtr getExpression(Expression expr, bool clone = false) const
{
auto it = positions.find(expr);
if (it != positions.end())
return clone ? children[it->second]->clone() : children[it->second];
return {};
}
ASTPtr cloneToASTSelect() const;
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
private:
std::unordered_map<Expression, size_t> positions;
ASTPtr & getExpression(Expression expr);
};
}