ClickHouse/src/Parsers/ASTTablesInSelectQuery.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

136 lines
4.3 KiB
C++
Raw Normal View History

2016-07-23 20:54:22 +00:00
#pragma once
2021-10-02 07:13:14 +00:00
#include <base/EnumReflection.h>
2016-07-23 20:54:22 +00:00
2022-07-29 16:30:50 +00:00
#include <Core/Joins.h>
#include <Parsers/IAST.h>
2016-07-23 20:54:22 +00:00
namespace DB
{
/** List of zero, single or multiple JOIN-ed tables or subqueries in SELECT query, with ARRAY JOINs and SAMPLE, FINAL modifiers.
*
* Table expression is:
* [database_name.]table_name
* or
* table_function(params)
* or
* (subquery)
*
2019-01-22 19:56:53 +00:00
* Optionally with alias (correlation name):
2016-07-23 20:54:22 +00:00
* [AS] alias
*
* Table may contain FINAL and SAMPLE modifiers:
* FINAL
* SAMPLE 1 / 10
* SAMPLE 0.1
* SAMPLE 1000000
*
* Table expressions may be combined with JOINs of following kinds:
2019-12-02 18:07:27 +00:00
* [GLOBAL] [ANY|ALL|ASOF|SEMI] [INNER|LEFT|RIGHT|FULL] [OUTER] JOIN table_expr
2016-07-23 20:54:22 +00:00
* CROSS JOIN
* , (comma)
*
* In all kinds except cross and comma, there are join condition in one of following forms:
* USING (a, b, c)
2016-07-23 20:54:22 +00:00
* USING a, b, c
* ON expr...
*
* Also, tables may be ARRAY JOIN-ed with one or more arrays or nested columns:
* [LEFT|INNER|] ARRAY JOIN name [AS alias], ...
*/
/// Table expression, optionally with alias.
struct ASTTableExpression : public IAST
{
/// One of fields is non-nullptr.
ASTPtr database_and_table_name;
ASTPtr table_function;
ASTPtr subquery;
2016-07-23 20:54:22 +00:00
/// Modifiers
bool final = false;
ASTPtr sample_size;
ASTPtr sample_offset;
2016-07-23 20:54:22 +00:00
using IAST::IAST;
String getID(char) const override { return "TableExpression"; }
2016-07-23 20:54:22 +00:00
ASTPtr clone() const override;
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
2023-11-10 12:15:23 +00:00
void updateTreeHashImpl(SipHash & hash_state, bool ignore_aliases) const override;
2016-07-23 20:54:22 +00:00
};
/// How to JOIN another table.
struct ASTTableJoin : public IAST
{
2022-07-29 16:30:50 +00:00
JoinLocality locality = JoinLocality::Unspecified;
JoinStrictness strictness = JoinStrictness::Unspecified;
JoinKind kind = JoinKind::Inner;
2016-07-23 20:54:22 +00:00
/// Condition. One of fields is non-nullptr.
ASTPtr using_expression_list;
ASTPtr on_expression;
2016-07-23 20:54:22 +00:00
using IAST::IAST;
String getID(char) const override { return "TableJoin"; }
2016-07-23 20:54:22 +00:00
ASTPtr clone() const override;
2016-07-23 20:54:22 +00:00
void formatImplBeforeTable(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const;
void formatImplAfterTable(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const;
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
2023-11-10 12:15:23 +00:00
void updateTreeHashImpl(SipHash & hash_state, bool ignore_aliases) const override;
2016-07-23 20:54:22 +00:00
};
/// Specification of ARRAY JOIN.
struct ASTArrayJoin : public IAST
{
enum class Kind
{
2017-06-26 08:33:56 +00:00
Inner, /// If array is empty, row will not present (default).
2016-07-23 20:54:22 +00:00
Left, /// If array is empty, leave row with default values instead of array elements.
};
Kind kind = Kind::Inner;
/// List of array or nested names to JOIN, possible with aliases.
ASTPtr expression_list;
using IAST::IAST;
String getID(char) const override { return "ArrayJoin"; }
2016-07-23 20:54:22 +00:00
ASTPtr clone() const override;
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
2023-11-10 12:15:23 +00:00
void updateTreeHashImpl(SipHash & hash_state, bool ignore_aliases) const override;
2016-07-23 20:54:22 +00:00
};
/// Element of list.
struct ASTTablesInSelectQueryElement : public IAST
{
/** For first element of list, either table_expression or array_join element could be non-nullptr.
* For former elements, either table_join and table_expression are both non-nullptr, or array_join is non-nullptr.
*/
2017-06-26 08:33:56 +00:00
ASTPtr table_join; /// How to JOIN a table, if table_expression is non-nullptr.
ASTPtr table_expression; /// Table.
ASTPtr array_join; /// Arrays to JOIN.
2016-07-23 20:54:22 +00:00
using IAST::IAST;
String getID(char) const override { return "TablesInSelectQueryElement"; }
2016-07-23 20:54:22 +00:00
ASTPtr clone() const override;
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
};
/// The list. Elements are in 'children' field.
struct ASTTablesInSelectQuery : public IAST
{
using IAST::IAST;
String getID(char) const override { return "TablesInSelectQuery"; }
2016-07-23 20:54:22 +00:00
ASTPtr clone() const override;
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
};
}