diff options
Diffstat (limited to 'yql/essentials/sql/v1/select.cpp')
| -rw-r--r-- | yql/essentials/sql/v1/select.cpp | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/yql/essentials/sql/v1/select.cpp b/yql/essentials/sql/v1/select.cpp index 8219a8d8fa4..e1fa0fbf3d7 100644 --- a/yql/essentials/sql/v1/select.cpp +++ b/yql/essentials/sql/v1/select.cpp @@ -38,6 +38,9 @@ public: bool DoInit(TContext& ctx, ISource* src) override { YQL_ENSURE(!src, "Source not expected for subquery node"); Source_->UseAsInner(); + if (PreserveSort_) { + Source_->PreserveSort(); + } if (!Source_->Init(ctx, nullptr)) { return false; } @@ -189,6 +192,9 @@ public: if (AsInner_) { Source_->UseAsInner(); } + if (PreserveSort_) { + Source_->PreserveSort(); + } if (!Source_->Init(ctx, src)) { return false; @@ -702,6 +708,9 @@ public: bool DoInit(TContext& ctx, ISource* src) override { // independent subquery should not connect source Subquery_->UseAsInner(); + if (PreserveSort_) { + Subquery_->PreserveSort(); + } if (!Subquery_->Init(ctx, nullptr)) { return false; } @@ -845,6 +854,96 @@ bool IsYqlSubqueryRef(const TNodePtr& source) { return dynamic_cast<const TYqlSubqueryRefNode*>(source.Get()) != nullptr; } +class TMaterializeNode: public INode { +public: + TMaterializeNode(TPosition pos, TSourcePtr source, TString service, TNodePtr cluster, TTableHints hints, TString alias, TScopedStatePtr scoped) + : INode(pos) + , Source_(std::move(source)) + , Service_(std::move(service)) + , ClusterNode_(std::move(cluster)) + , Hints_(std::move(hints)) + , Alias_(std::move(alias)) + , Scoped_(std::move(scoped)) + { + } + + bool DoInit(TContext& ctx, ISource* src) override { + Y_UNUSED(src); + + if (!ctx.EnsureAvailable(GetPos(), NYql::NFeature::Materialize)) { + return false; + } + + Source_->UseAsInner(); + Source_->PreserveSort(); + + if (!Source_->Init(ctx, nullptr)) { + return false; + } + + TTableList tableList; + Source_->GetInputTables(tableList); + + auto tables = BuildInputTables(Pos_, tableList, false, Scoped_); + if (!tables->Init(ctx, Source_.Get())) { + return false; + } + + auto sourceData = Source_->Build(ctx); + if (!sourceData) { + return false; + } + + if (!ClusterNode_->Init(ctx, nullptr)) { + return false; + } + + auto datasink = Y("DataSink", BuildQuotedAtom(Pos_, Service_), ClusterNode_); + + TNodePtr options = BuildInputOptions(Pos_, Hints_); + if (!options) { + options = Q(Y()); + } + + Node_ = Y("let", Alias_, Y("block", Q(L(tables, Y("return", Y("Materialize!", "world", datasink, sourceData, options)))))); + IsUsed_ = true; + + return true; + } + + TAstNode* Translate(TContext& ctx) const final { + return Node_->Translate(ctx); + } + + TNodePtr DoClone() const final { + return new TMaterializeNode(GetPos(), Source_->CloneSource(), Service_, ClusterNode_->Clone(), Hints_, Alias_, Scoped_); + } + + // Is used at the TYqlProgramNode + const TString* SubqueryAlias() const final { + return &Alias_; + } + + // Is used at the TYqlProgramNode + bool UsedSubquery() const final { + return IsUsed_; + } + +private: + TSourcePtr Source_; + TString Service_; + TNodePtr ClusterNode_; + TTableHints Hints_; + TString Alias_; + TScopedStatePtr Scoped_; + bool IsUsed_ = false; + TNodePtr Node_; +}; + +TNodePtr BuildMaterialize(TPosition pos, TSourcePtr source, const TString& serviceId, TNodePtr cluster, TTableHints hints, TString alias, TScopedStatePtr scoped) { + return new TMaterializeNode(pos, std::move(source), serviceId, std::move(cluster), std::move(hints), std::move(alias), std::move(scoped)); +} + class TInvalidSubqueryRefNode: public ISource { public: explicit TInvalidSubqueryRefNode(TPosition pos) @@ -1072,6 +1171,9 @@ public: source->SetLabel(Label_); if (!NewSource_) { Node_->UseAsInner(); + if (PreserveSort_) { + Node_->PreserveSort(); + } if (!Node_->Init(ctx, nullptr)) { return false; } @@ -3344,7 +3446,7 @@ public: protected: bool IgnoreSort() const { - return AsInner_ && !SkipTake_ && EOrderKind::Sort == Source_->GetOrderKind(); + return AsInner_ && !PreserveSort_ && !SkipTake_ && EOrderKind::Sort == Source_->GetOrderKind(); } TSourcePtr Source_; |
