diff options
author | vvvv <[email protected]> | 2024-11-07 12:29:36 +0300 |
---|---|---|
committer | vvvv <[email protected]> | 2024-11-07 13:49:47 +0300 |
commit | d4c258e9431675bab6745c8638df6e3dfd4dca6b (patch) | |
tree | b5efcfa11351152a4c872fccaea35749141c0b11 /yql/essentials/sql/v1/sql_select.h | |
parent | 13a4f274caef5cfdaf0263b24e4d6bdd5521472b (diff) |
Moved other yql/essentials libs YQL-19206
init
commit_hash:7d4c435602078407bbf20dd3c32f9c90d2bbcbc0
Diffstat (limited to 'yql/essentials/sql/v1/sql_select.h')
-rw-r--r-- | yql/essentials/sql/v1/sql_select.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/yql/essentials/sql/v1/sql_select.h b/yql/essentials/sql/v1/sql_select.h new file mode 100644 index 00000000000..fd6f0bece52 --- /dev/null +++ b/yql/essentials/sql/v1/sql_select.h @@ -0,0 +1,74 @@ +#pragma once + +#include "sql_translation.h" +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> + +namespace NSQLTranslationV1 { + +using namespace NSQLv1Generated; + +class TSqlSelect: public TSqlTranslation { +public: + TSqlSelect(TContext& ctx, NSQLTranslation::ESqlMode mode) + : TSqlTranslation(ctx, mode) + { + } + + TSourcePtr Build(const TRule_select_stmt& node, TPosition& selectPos); + TSourcePtr Build(const TRule_select_unparenthesized_stmt& node, TPosition& selectPos); + +private: + bool SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column& node); + bool ValidateSelectColumns(const TVector<TNodePtr>& terms); + bool ColumnName(TVector<TNodePtr>& keys, const TRule_column_name& node); + bool ColumnName(TVector<TNodePtr>& keys, const TRule_without_column_name& node); + template<typename TRule> + bool ColumnList(TVector<TNodePtr>& keys, const TRule& node); + bool NamedColumn(TVector<TNodePtr>& columnList, const TRule_named_column& node); + TSourcePtr SingleSource(const TRule_single_source& node, const TVector<TString>& derivedColumns, TPosition derivedColumnsPos, bool unorderedSubquery); + TSourcePtr NamedSingleSource(const TRule_named_single_source& node, bool unorderedSubquery); + bool FlattenByArg(const TString& sourceLabel, TVector<TNodePtr>& flattenByColumns, TVector<TNodePtr>& flattenByExprs, const TRule_flatten_by_arg& node); + TSourcePtr FlattenSource(const TRule_flatten_source& node); + TSourcePtr JoinSource(const TRule_join_source& node); + bool JoinOp(ISource* join, const TRule_join_source::TBlock3& block, TMaybe<TPosition> anyPos); + TNodePtr JoinExpr(ISource*, const TRule_join_constraint& node); + TSourcePtr ProcessCore(const TRule_process_core& node, const TWriteSettings& settings, TPosition& selectPos); + TSourcePtr ReduceCore(const TRule_reduce_core& node, const TWriteSettings& settings, TPosition& selectPos); + + struct TSelectKindPlacement { + bool IsFirstInSelectOp = false; + bool IsLastInSelectOp = false; + }; + + TSourcePtr SelectCore(const TRule_select_core& node, const TWriteSettings& settings, TPosition& selectPos, + TMaybe<TSelectKindPlacement> placement, TVector<TSortSpecificationPtr>& selectOpOrederBy, bool& selectOpAssumeOrderBy); + + bool WindowDefinition(const TRule_window_definition& node, TWinSpecs& winSpecs); + bool WindowClause(const TRule_window_clause& node, TWinSpecs& winSpecs); + + struct TSelectKindResult { + TSourcePtr Source; + TWriteSettings Settings; + + TVector<TSortSpecificationPtr> SelectOpOrderBy; + bool SelectOpAssumeOrderBy = false; + TNodePtr SelectOpSkipTake; + + inline explicit operator bool() const { + return static_cast<bool>(Source); + } + }; + + bool ValidateLimitOrderByWithSelectOp(TMaybe<TSelectKindPlacement> placement, TStringBuf what); + bool NeedPassLimitOrderByToUnderlyingSelect(TMaybe<TSelectKindPlacement> placement); + + template<typename TRule> + TSourcePtr Build(const TRule& node, TPosition pos, TSelectKindResult&& first); + + + TSelectKindResult SelectKind(const TRule_select_kind& node, TPosition& selectPos, TMaybe<TSelectKindPlacement> placement); + TSelectKindResult SelectKind(const TRule_select_kind_partial& node, TPosition& selectPos, TMaybe<TSelectKindPlacement> placement); + TSelectKindResult SelectKind(const TRule_select_kind_parenthesis& node, TPosition& selectPos, TMaybe<TSelectKindPlacement> placement); +}; + +} //namespace NSQLTranslationV1 |