aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-romanov <Anton.Romanov@ydb.tech>2023-08-15 15:23:58 +0300
committera-romanov <Anton.Romanov@ydb.tech>2023-08-15 16:47:02 +0300
commitfd3978102761adff1a29e7f0376e378b5f294985 (patch)
tree295cc46f1e25464b8a4cc7d15f3aa6f2735be83c
parentbd4e4740d96a4d79f791576a730e251eb36db67c (diff)
downloadydb-fd3978102761adff1a29e7f0376e378b5f294985.tar.gz
YQL-15435 Refactoring: Internal interface for constraints with fields.
-rw-r--r--ydb/library/yql/ast/yql_constraint.cpp240
-rw-r--r--ydb/library/yql/ast/yql_constraint.h171
-rw-r--r--ydb/library/yql/core/common_opt/yql_co_simple1.cpp4
-rw-r--r--ydb/library/yql/core/yql_expr_constraint.cpp128
-rw-r--r--ydb/library/yql/core/yql_join.cpp2
-rw-r--r--ydb/library/yql/core/yql_opt_utils.cpp10
-rw-r--r--ydb/library/yql/providers/dq/provider/yql_dq_datasink_constraints.cpp4
-rw-r--r--ydb/library/yql/providers/yt/lib/row_spec/yql_row_spec.cpp20
-rw-r--r--ydb/library/yql/providers/yt/provider/yql_yt_datasink_constraints.cpp8
-rw-r--r--ydb/library/yql/providers/yt/provider/yql_yt_datasource_constraints.cpp2
-rw-r--r--ydb/library/yql/providers/yt/provider/yql_yt_join_impl.cpp9
-rw-r--r--ydb/library/yql/providers/yt/provider/yql_yt_logical_optimize.cpp2
-rw-r--r--ydb/library/yql/providers/yt/provider/yql_yt_physical_finalizing.cpp4
-rw-r--r--ydb/library/yql/providers/yt/provider/yql_yt_table.cpp4
14 files changed, 350 insertions, 258 deletions
diff --git a/ydb/library/yql/ast/yql_constraint.cpp b/ydb/library/yql/ast/yql_constraint.cpp
index 8cb981552c..e8372ec97a 100644
--- a/ydb/library/yql/ast/yql_constraint.cpp
+++ b/ydb/library/yql/ast/yql_constraint.cpp
@@ -29,7 +29,17 @@ void TConstraintNode::Out(IOutputStream& out) const {
out.Write(Name_);
}
-const TTypeAnnotationNode* TConstraintNode::GetSubTypeByPath(const TPathType& path, const TTypeAnnotationNode& type) {
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+TPartOfConstraintBase::TPartOfConstraintBase(TExprContext& ctx, std::string_view name)
+ : TConstraintNode(ctx, name)
+{}
+
+TConstraintWithFieldsNode::TConstraintWithFieldsNode(TExprContext& ctx, std::string_view name)
+ : TPartOfConstraintBase(ctx, name)
+{}
+
+const TTypeAnnotationNode* TPartOfConstraintBase::GetSubTypeByPath(const TPathType& path, const TTypeAnnotationNode& type) {
if (path.empty() && ETypeAnnotationKind::Optional != type.GetKind())
return &type;
@@ -73,7 +83,7 @@ const TTypeAnnotationNode* TConstraintNode::GetSubTypeByPath(const TPathType& pa
return nullptr;
}
-bool TConstraintNode::HasDuplicates(const TSetOfSetsType& sets) {
+bool TPartOfConstraintBase::HasDuplicates(const TSetOfSetsType& sets) {
for (auto ot = sets.cbegin(); sets.cend() != ot; ++ot) {
for (auto it = sets.cbegin(); sets.cend() != it; ++it) {
if (ot->size() < it->size() && std::all_of(ot->cbegin(), ot->cend(), [it](const TPathType& path) { return it->contains(path); }))
@@ -193,11 +203,11 @@ std::deque<std::string_view> GetAllItemTypeFields(const TTypeAnnotationNode* typ
return fields;
}
-TConstraintNode::TSetOfSetsType MakeFullSet(const TConstraintNode::TSetType& keys) {
- TConstraintNode::TSetOfSetsType sets;
+TPartOfConstraintBase::TSetOfSetsType MakeFullSet(const TPartOfConstraintBase::TSetType& keys) {
+ TPartOfConstraintBase::TSetOfSetsType sets;
sets.reserve(sets.size());
for (const auto& key : keys)
- sets.insert_unique(TConstraintNode::TSetType{key});
+ sets.insert_unique(TPartOfConstraintBase::TSetType{key});
return sets;
}
@@ -206,7 +216,7 @@ TConstraintNode::TSetOfSetsType MakeFullSet(const TConstraintNode::TSetType& key
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
TSortedConstraintNode::TSortedConstraintNode(TExprContext& ctx, TContainerType&& content)
- : TConstraintNode(ctx, Name()), Content_(std::move(content))
+ : TConstraintWithFieldsT(ctx, Name()), Content_(std::move(content))
{
YQL_ENSURE(!Content_.empty());
for (const auto& c : Content_) {
@@ -300,7 +310,7 @@ bool TSortedConstraintNode::StartsWith(const TSetType& prefix) const {
return set.empty();
}
-TConstraintNode::TSetType TSortedConstraintNode::GetFullSet() const {
+TPartOfConstraintBase::TSetType TSortedConstraintNode::GetFullSet() const {
TSetType set;
set.reserve(Content_.size());
for (const auto& key : Content_)
@@ -408,7 +418,7 @@ const TSortedConstraintNode* TSortedConstraintNode::CutPrefix(size_t newPrefixLe
return ctx.MakeConstraint<TSortedConstraintNode>(std::move(content));
}
-const TSortedConstraintNode* TSortedConstraintNode::FilterFields(TExprContext& ctx, const TPathFilter& filter) const {
+const TConstraintWithFieldsNode* TSortedConstraintNode::DoFilterFields(TExprContext& ctx, const TPathFilter& filter) const {
if (!filter)
return this;
@@ -430,7 +440,7 @@ const TSortedConstraintNode* TSortedConstraintNode::FilterFields(TExprContext& c
return sorted.empty() ? nullptr : ctx.MakeConstraint<TSortedConstraintNode>(std::move(sorted));
}
-const TSortedConstraintNode* TSortedConstraintNode::RenameFields(TExprContext& ctx, const TPathReduce& reduce) const {
+const TConstraintWithFieldsNode* TSortedConstraintNode::DoRenameFields(TExprContext& ctx, const TPathReduce& reduce) const {
if (!reduce)
return this;
@@ -460,11 +470,11 @@ bool TSortedConstraintNode::IsApplicableToType(const TTypeAnnotationNode& type)
}
const TConstraintNode* TSortedConstraintNode::OnlySimpleColumns(TExprContext& ctx) const {
- return FilterFields(ctx, std::bind(std::equal_to<TPathType::size_type>(), std::bind(&TPathType::size, std::placeholders::_1), 1ULL));
+ return DoFilterFields(ctx, std::bind(std::equal_to<TPathType::size_type>(), std::bind(&TPathType::size, std::placeholders::_1), 1ULL));
}
-const TSortedConstraintNode*
-TSortedConstraintNode::GetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
+const TConstraintWithFieldsNode*
+TSortedConstraintNode::DoGetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
const auto& rowType = GetSeqItemType(type);
bool changed = false;
auto content = Content_;
@@ -499,13 +509,13 @@ TSortedConstraintNode::GetComplicatedForType(const TTypeAnnotationNode& type, TE
return changed ? ctx.MakeConstraint<TSortedConstraintNode>(std::move(content)) : this;
}
-const TSortedConstraintNode*
-TSortedConstraintNode::GetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
+const TConstraintWithFieldsNode*
+TSortedConstraintNode::DoGetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
if (Content_.size() == 1U && Content_.front().first.size() == 1U && Content_.front().first.front().size() == 1U && Content_.front().first.front().front().empty())
- return GetComplicatedForType(type, ctx);
+ return DoGetComplicatedForType(type, ctx);
const auto& rowType = GetSeqItemType(type);
- const auto getPrefix = [](TConstraintNode::TPathType path) {
+ const auto getPrefix = [](TPartOfConstraintBase::TPathType path) {
path.pop_back();
return path;
};
@@ -525,7 +535,7 @@ TSortedConstraintNode::GetSimplifiedForType(const TTypeAnnotationNode& type, TEx
++it;
if (ssize_t(GetElementsCount(subType)) == std::distance(from, it)) {
- *from++ = std::make_pair(TConstraintNode::TSetType{std::move(prefix)}, from->second);
+ *from++ = std::make_pair(TPartOfConstraintBase::TSetType{std::move(prefix)}, from->second);
it = content.erase(from, it);
changed = setChanged = true;
}
@@ -541,7 +551,7 @@ TSortedConstraintNode::GetSimplifiedForType(const TTypeAnnotationNode& type, TEx
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
TChoppedConstraintNode::TChoppedConstraintNode(TExprContext& ctx, TSetOfSetsType&& sets)
- : TConstraintNode(ctx, Name()), Sets_(std::move(sets))
+ : TConstraintWithFieldsT(ctx, Name()), Sets_(std::move(sets))
{
YQL_ENSURE(!Sets_.empty());
YQL_ENSURE(!HasDuplicates(Sets_));
@@ -560,7 +570,7 @@ TChoppedConstraintNode::TChoppedConstraintNode(TExprContext& ctx, const TSetType
TChoppedConstraintNode::TChoppedConstraintNode(TChoppedConstraintNode&& constr) = default;
-TConstraintNode::TSetType TChoppedConstraintNode::GetFullSet() const {
+TPartOfConstraintBase::TSetType TChoppedConstraintNode::GetFullSet() const {
TSetType set;
set.reserve(Sets_.size());
for (const auto& key : Sets_)
@@ -692,8 +702,8 @@ const TChoppedConstraintNode* TChoppedConstraintNode::MakeCommon(const std::vect
return sets.empty() ? nullptr : ctx.MakeConstraint<TChoppedConstraintNode>(std::move(sets));
}
-const TChoppedConstraintNode*
-TChoppedConstraintNode::FilterFields(TExprContext& ctx, const TPathFilter& predicate) const {
+const TConstraintWithFieldsNode*
+TChoppedConstraintNode::DoFilterFields(TExprContext& ctx, const TPathFilter& predicate) const {
if (!predicate)
return this;
@@ -716,8 +726,8 @@ TChoppedConstraintNode::FilterFields(TExprContext& ctx, const TPathFilter& predi
return ctx.MakeConstraint<TChoppedConstraintNode>(std::move(chopped));
}
-const TChoppedConstraintNode*
-TChoppedConstraintNode::RenameFields(TExprContext& ctx, const TPathReduce& reduce) const {
+const TConstraintWithFieldsNode*
+TChoppedConstraintNode::DoRenameFields(TExprContext& ctx, const TPathReduce& reduce) const {
if (!reduce)
return this;
@@ -763,11 +773,11 @@ bool TChoppedConstraintNode::IsApplicableToType(const TTypeAnnotationNode& type)
}
const TConstraintNode* TChoppedConstraintNode::OnlySimpleColumns(TExprContext& ctx) const {
- return FilterFields(ctx, std::bind(std::equal_to<typename TPathType::size_type>(), std::bind(&TPathType::size, std::placeholders::_1), 1ULL));
+ return DoFilterFields(ctx, std::bind(std::equal_to<typename TPathType::size_type>(), std::bind(&TPathType::size, std::placeholders::_1), 1ULL));
}
-const TChoppedConstraintNode*
-TChoppedConstraintNode::GetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
+const TConstraintWithFieldsNode*
+TChoppedConstraintNode::DoGetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
const auto& rowType = GetSeqItemType(type);
bool changed = false;
auto sets = Sets_;
@@ -799,13 +809,13 @@ TChoppedConstraintNode::GetComplicatedForType(const TTypeAnnotationNode& type, T
return changed ? ctx.MakeConstraint<TChoppedConstraintNode>(std::move(sets)) : this;
}
-const TChoppedConstraintNode*
-TChoppedConstraintNode::GetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
+const TConstraintWithFieldsNode*
+TChoppedConstraintNode::DoGetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
if (Sets_.size() == 1U && Sets_.front().size() == 1U && Sets_.front().front().empty())
- return GetComplicatedForType(type, ctx);
+ return DoGetComplicatedForType(type, ctx);
const auto& rowType = GetSeqItemType(type);
- const auto getPrefix = [](TConstraintNode::TPathType path) {
+ const auto getPrefix = [](TPartOfConstraintBase::TPathType path) {
path.pop_back();
return path;
};
@@ -824,7 +834,7 @@ TChoppedConstraintNode::GetSimplifiedForType(const TTypeAnnotationNode& type, TE
++it;
if (ssize_t(GetElementsCount(GetSubTypeByPath(prefix, rowType))) == std::distance(from, it)) {
- *from++ = TConstraintNode::TSetType{std::move(prefix)};
+ *from++ = TPartOfConstraintBase::TSetType{std::move(prefix)};
it = sets.erase(from, it);
changed = setChanged = true;
}
@@ -838,12 +848,12 @@ TChoppedConstraintNode::GetSimplifiedForType(const TTypeAnnotationNode& type, TE
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<bool Distinct>
-TConstraintNode::TSetOfSetsType
+TConstraintWithFieldsNode::TSetOfSetsType
TUniqueConstraintNodeBase<Distinct>::ColumnsListToSets(const std::vector<std::string_view>& columns) {
YQL_ENSURE(!columns.empty());
- TSetOfSetsType sets;
+ TConstraintWithFieldsNode::TSetOfSetsType sets;
sets.reserve(columns.size());
- std::for_each(columns.cbegin(), columns.cend(), [&sets](const std::string_view& column) { sets.insert_unique(TSetType{column.empty() ? TPathType() : TPathType(1U, column)}); });
+ std::for_each(columns.cbegin(), columns.cend(), [&sets](const std::string_view& column) { sets.insert_unique(TConstraintWithFieldsNode::TSetType{column.empty() ? TConstraintWithFieldsNode::TPathType() : TConstraintWithFieldsNode::TPathType(1U, column)}); });
return sets;
}
@@ -854,7 +864,7 @@ TUniqueConstraintNodeBase<Distinct>::DedupSets(TContentType&& sets) {
found = false;
for (auto ot = sets.cbegin(); !found && sets.cend() != ot; ++ot) {
for (auto it = sets.cbegin(); sets.cend() != it;) {
- if (ot->size() < it->size() && std::all_of(ot->cbegin(), ot->cend(), [it](const TSetType& set) { return it->contains(set); })) {
+ if (ot->size() < it->size() && std::all_of(ot->cbegin(), ot->cend(), [it](const TConstraintWithFieldsNode::TSetType& set) { return it->contains(set); })) {
it = sets.erase(it);
found = true;
} else
@@ -874,11 +884,11 @@ TUniqueConstraintNodeBase<Distinct>::MakeCommonContent(const TContentType& one,
for (const auto& setsOne : one) {
for (const auto& setsTwo : two) {
if (setsOne.size() == setsTwo.size()) {
- TSetOfSetsType sets;
+ TConstraintWithFieldsNode::TSetOfSetsType sets;
sets.reserve(setsTwo.size());
for (const auto& setOne : setsOne) {
for (const auto& setTwo : setsTwo) {
- TSetType set;
+ TConstraintWithFieldsNode::TSetType set;
set.reserve(std::min(setOne.size(), setTwo.size()));
std::set_intersection(setOne.cbegin(), setOne.cend(), setTwo.cbegin(), setTwo.cend(), std::back_inserter(set));
if (!set.empty())
@@ -895,34 +905,34 @@ TUniqueConstraintNodeBase<Distinct>::MakeCommonContent(const TContentType& one,
template<bool Distinct>
TUniqueConstraintNodeBase<Distinct>::TUniqueConstraintNodeBase(TExprContext& ctx, TContentType&& sets)
- : TConstraintNode(ctx, Name()), Content_(DedupSets(std::move(sets)))
+ : TBase(ctx, Name()), Content_(DedupSets(std::move(sets)))
{
YQL_ENSURE(!Content_.empty());
const auto size = Content_.size();
- Hash_ = MurmurHash<ui64>(&size, sizeof(size), Hash_);
+ TBase::Hash_ = MurmurHash<ui64>(&size, sizeof(size), TBase::Hash_);
for (const auto& sets : Content_) {
YQL_ENSURE(!sets.empty());
- YQL_ENSURE(!HasDuplicates(sets));
+ YQL_ENSURE(!TConstraintWithFieldsNode::HasDuplicates(sets));
for (const auto& set : sets) {
YQL_ENSURE(!set.empty());
for (const auto& path : set)
- Hash_ = std::accumulate(path.cbegin(), path.cend(), Hash_, [](ui64 hash, const std::string_view& field) { return MurmurHash<ui64>(field.data(), field.size(), hash); });
+ TBase::Hash_ = std::accumulate(path.cbegin(), path.cend(), TBase::Hash_, [](ui64 hash, const std::string_view& field) { return MurmurHash<ui64>(field.data(), field.size(), hash); });
}
}
}
template<bool Distinct>
TUniqueConstraintNodeBase<Distinct>::TUniqueConstraintNodeBase(TExprContext& ctx, const std::vector<std::string_view>& columns)
- : TUniqueConstraintNodeBase(ctx, TContentType{TSetOfSetsType{ColumnsListToSets(columns)}})
+ : TUniqueConstraintNodeBase(ctx, TContentType{TPartOfConstraintBase::TSetOfSetsType{ColumnsListToSets(columns)}})
{}
template<bool Distinct>
TUniqueConstraintNodeBase<Distinct>::TUniqueConstraintNodeBase(TUniqueConstraintNodeBase&& constr) = default;
template<bool Distinct>
-TConstraintNode::TSetType
+TPartOfConstraintBase::TSetType
TUniqueConstraintNodeBase<Distinct>::GetFullSet() const {
- TSetType set;
+ TPartOfConstraintBase::TSetType set;
set.reserve(Content_.size());
for (const auto& sets : Content_)
for (const auto& key : sets)
@@ -935,7 +945,7 @@ bool TUniqueConstraintNodeBase<Distinct>::Equals(const TConstraintNode& node) co
if (this == &node) {
return true;
}
- if (GetHash() != node.GetHash()) {
+ if (TBase::GetHash() != node.GetHash()) {
return false;
}
if (const auto c = dynamic_cast<const TUniqueConstraintNodeBase*>(&node)) {
@@ -950,10 +960,10 @@ bool TUniqueConstraintNodeBase<Distinct>::Includes(const TConstraintNode& node)
return true;
if (const auto c = dynamic_cast<const TUniqueConstraintNodeBase*>(&node)) {
- return std::all_of(c->Content_.cbegin(), c->Content_.cend(), [&] (const TSetOfSetsType& oldSets) {
- return std::any_of(Content_.cbegin(), Content_.cend(), [&] (const TSetOfSetsType& newSets) {
- return oldSets.size() == newSets.size() && std::all_of(oldSets.cbegin(), oldSets.cend(), [&] (const TSetType& oldSet) {
- return std::any_of(newSets.cbegin(), newSets.cend(), [&] (const TSetType& newSet) {
+ return std::all_of(c->Content_.cbegin(), c->Content_.cend(), [&] (const TConstraintWithFieldsNode::TSetOfSetsType& oldSets) {
+ return std::any_of(Content_.cbegin(), Content_.cend(), [&] (const TConstraintWithFieldsNode::TSetOfSetsType& newSets) {
+ return oldSets.size() == newSets.size() && std::all_of(oldSets.cbegin(), oldSets.cend(), [&] (const TConstraintWithFieldsNode::TSetType& oldSet) {
+ return std::any_of(newSets.cbegin(), newSets.cend(), [&] (const TConstraintWithFieldsNode::TSetType& newSet) {
return std::includes(newSet.cbegin(), newSet.cend(), oldSet.cbegin(), oldSet.cend());
});
});
@@ -1033,18 +1043,20 @@ const TUniqueConstraintNodeBase<Distinct>* TUniqueConstraintNodeBase<Distinct>::
template<bool Distinct>
bool TUniqueConstraintNodeBase<Distinct>::IsOrderBy(const TSortedConstraintNode& sorted) const {
- TSetType ordered;
- TSetOfSetsType columns;
+ TConstraintWithFieldsNode::TSetType ordered;
+ TConstraintWithFieldsNode::TSetOfSetsType columns;
for (const auto& key : sorted.GetContent()) {
ordered.insert_unique(key.first.cbegin(), key.first.cend());
columns.insert_unique(key.first);
}
for (const auto& sets : Content_) {
- if (std::all_of(sets.cbegin(), sets.cend(), [&ordered](const TSetType& set) { return std::any_of(set.cbegin(), set.cend(), [&ordered](const TPathType& path) { return ordered.contains(path); }); })) {
- std::for_each(sets.cbegin(), sets.cend(), [&columns](const TSetType& set) {
- std::for_each(set.cbegin(), set.cend(), [&columns](const TPathType& path) {
- if (const auto it = std::find_if(columns.cbegin(), columns.cend(), [&path](const TSetType& s) { return s.contains(path); }); columns.cend() != it)
+ if (std::all_of(sets.cbegin(), sets.cend(), [&ordered](const TConstraintWithFieldsNode::TSetType& set) {
+ return std::any_of(set.cbegin(), set.cend(), [&ordered](const TConstraintWithFieldsNode::TPathType& path) { return ordered.contains(path); });
+ })) {
+ std::for_each(sets.cbegin(), sets.cend(), [&columns](const TConstraintWithFieldsNode::TSetType& set) {
+ std::for_each(set.cbegin(), set.cend(), [&columns](const TConstraintWithFieldsNode::TPathType& path) {
+ if (const auto it = std::find_if(columns.cbegin(), columns.cend(), [&path](const TConstraintWithFieldsNode::TSetType& s) { return s.contains(path); }); columns.cend() != it)
columns.erase(it);
});
});
@@ -1063,8 +1075,8 @@ bool TUniqueConstraintNodeBase<Distinct>::ContainsCompleteSet(const std::vector<
const std::unordered_set<std::string_view> ordered(columns.cbegin(), columns.cend());
for (const auto& sets : Content_) {
- if (std::all_of(sets.cbegin(), sets.cend(), [&ordered](const TSetType& set) {
- return std::any_of(set.cbegin(), set.cend(), [&ordered](const TPathType& path) { return !path.empty() && ordered.contains(path.front()); });
+ if (std::all_of(sets.cbegin(), sets.cend(), [&ordered](const TConstraintWithFieldsNode::TSetType& set) {
+ return std::any_of(set.cbegin(), set.cend(), [&ordered](const TConstraintWithFieldsNode::TPathType& path) { return !path.empty() && ordered.contains(path.front()); });
}))
return true;
}
@@ -1072,13 +1084,13 @@ bool TUniqueConstraintNodeBase<Distinct>::ContainsCompleteSet(const std::vector<
}
template<bool Distinct>
-void TUniqueConstraintNodeBase<Distinct>::FilterUncompleteReferences(TSetType& references) const {
- TSetType input(std::move(references));
+void TUniqueConstraintNodeBase<Distinct>::FilterUncompleteReferences(TPartOfConstraintBase::TSetType& references) const {
+ TPartOfConstraintBase::TSetType input(std::move(references));
references.clear();
references.reserve(input.size());
for (const auto& sets : Content_) {
- if (std::all_of(sets.cbegin(), sets.cend(), [&input] (const TSetType& set) { return std::any_of(set.cbegin(), set.cend(), std::bind(&TSetType::contains<TPathType>, std::cref(input), std::placeholders::_1)); }))
- std::for_each(sets.cbegin(), sets.cend(), [&] (const TSetType& set) { std::for_each(set.cbegin(), set.cend(), [&] (const TPathType& path) {
+ if (std::all_of(sets.cbegin(), sets.cend(), [&input] (const TPartOfConstraintBase::TSetType& set) { return std::any_of(set.cbegin(), set.cend(), std::bind(&TPartOfConstraintBase::TSetType::contains<TPartOfConstraintBase::TPathType>, std::cref(input), std::placeholders::_1)); }))
+ std::for_each(sets.cbegin(), sets.cend(), [&] (const TPartOfConstraintBase::TSetType& set) { std::for_each(set.cbegin(), set.cend(), [&] (const TPartOfConstraintBase::TPathType& path) {
if (input.contains(path))
references.insert_unique(path);
}); });
@@ -1086,19 +1098,19 @@ void TUniqueConstraintNodeBase<Distinct>::FilterUncompleteReferences(TSetType& r
}
template<bool Distinct>
-const TUniqueConstraintNodeBase<Distinct>*
-TUniqueConstraintNodeBase<Distinct>::FilterFields(TExprContext& ctx, const TPathFilter& predicate) const {
+const TConstraintWithFieldsNode*
+TUniqueConstraintNodeBase<Distinct>::DoFilterFields(TExprContext& ctx, const TPartOfConstraintBase::TPathFilter& predicate) const {
if (!predicate)
return this;
TContentType content;
content.reserve(Content_.size());
for (const auto& sets : Content_) {
- if (std::all_of(sets.cbegin(), sets.cend(), [&predicate](const TSetType& set) { return std::any_of(set.cbegin(), set.cend(), predicate); })) {
- TSetOfSetsType newSets;
+ if (std::all_of(sets.cbegin(), sets.cend(), [&predicate](const TPartOfConstraintBase::TSetType& set) { return std::any_of(set.cbegin(), set.cend(), predicate); })) {
+ TPartOfConstraintBase::TSetOfSetsType newSets;
newSets.reserve(sets.size());
- std::for_each(sets.cbegin(), sets.cend(), [&](const TSetType& set) {
- TSetType newSet;
+ std::for_each(sets.cbegin(), sets.cend(), [&](const TPartOfConstraintBase::TSetType& set) {
+ TPartOfConstraintBase::TSetType newSet;
newSet.reserve(set.size());
std::copy_if(set.cbegin(), set.cend(), std::back_inserter(newSet), predicate);
newSets.insert_unique(std::move(newSet));
@@ -1110,18 +1122,18 @@ TUniqueConstraintNodeBase<Distinct>::FilterFields(TExprContext& ctx, const TPath
}
template<bool Distinct>
-const TUniqueConstraintNodeBase<Distinct>*
-TUniqueConstraintNodeBase<Distinct>::RenameFields(TExprContext& ctx, const TPathReduce& reduce) const {
+const TConstraintWithFieldsNode*
+TUniqueConstraintNodeBase<Distinct>::DoRenameFields(TExprContext& ctx, const TPartOfConstraintBase::TPathReduce& reduce) const {
if (!reduce)
return this;
TContentType content;
content.reserve(Content_.size());
for (const auto& sets : Content_) {
- TSetOfSetsType newSets;
+ TPartOfConstraintBase::TSetOfSetsType newSets;
newSets.reserve(sets.size());
for (const auto& set : sets) {
- TSetType newSet;
+ TPartOfConstraintBase::TSetType newSet;
newSet.reserve(set.size());
for (const auto& path : set) {
const auto newPaths = reduce(path);
@@ -1162,16 +1174,16 @@ const TUniqueConstraintNodeBase<Distinct>* TUniqueConstraintNodeBase<Distinct>::
}
template<bool Distinct>
-const TUniqueConstraintNodeBase<Distinct>*
-TUniqueConstraintNodeBase<Distinct>::GetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
+const TConstraintWithFieldsNode*
+TUniqueConstraintNodeBase<Distinct>::DoGetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
const auto& rowType = GetSeqItemType(type);
bool changed = false;
auto content = Content_;
for (auto& sets : content) {
for (auto it = sets.begin(); sets.end() != it;) {
- auto fields = GetAllItemTypeFields(GetSubTypeByPath(it->front(), rowType), ctx);
+ auto fields = GetAllItemTypeFields(TBase::GetSubTypeByPath(it->front(), rowType), ctx);
for (auto j = it->cbegin(); it->cend() != ++j;) {
- if (const auto& copy = GetAllItemTypeFields(GetSubTypeByPath(*j, rowType), ctx); copy != fields) {
+ if (const auto& copy = GetAllItemTypeFields(TBase::GetSubTypeByPath(*j, rowType), ctx); copy != fields) {
fields.clear();
break;
}
@@ -1198,13 +1210,13 @@ TUniqueConstraintNodeBase<Distinct>::GetComplicatedForType(const TTypeAnnotation
}
template<bool Distinct>
-const TUniqueConstraintNodeBase<Distinct>*
-TUniqueConstraintNodeBase<Distinct>::GetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
+const TConstraintWithFieldsNode*
+TUniqueConstraintNodeBase<Distinct>::DoGetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
if (Content_.size() == 1U && Content_.front().size() == 1U && Content_.front().front().size() == 1U && Content_.front().front().front().empty())
- return GetComplicatedForType(type, ctx);
+ return DoGetComplicatedForType(type, ctx);
const auto& rowType = GetSeqItemType(type);
- const auto getPrefix = [](TConstraintNode::TPathType path) {
+ const auto getPrefix = [](TPartOfConstraintBase::TPathType path) {
path.pop_back();
return path;
};
@@ -1223,8 +1235,8 @@ TUniqueConstraintNodeBase<Distinct>::GetSimplifiedForType(const TTypeAnnotationN
while (sets.cend() != it && it->size() == 1U && it->front().size() > 1U && prefix == getPrefix(it->front()))
++it;
- if (ssize_t(GetElementsCount(GetSubTypeByPath(prefix, rowType))) == std::distance(from, it)) {
- *from++ = TConstraintNode::TSetType{std::move(prefix)};
+ if (ssize_t(GetElementsCount(TBase::GetSubTypeByPath(prefix, rowType))) == std::distance(from, it)) {
+ *from++ = TPartOfConstraintBase::TSetType{std::move(prefix)};
it = sets.erase(from, it);
changed = setChanged = true;
}
@@ -1241,16 +1253,16 @@ bool TUniqueConstraintNodeBase<Distinct>::IsApplicableToType(const TTypeAnnotati
if (ETypeAnnotationKind::Dict == type.GetKind())
return true; // TODO: check for dict.
const auto& itemType = GetSeqItemType(type);
- return std::all_of(Content_.cbegin(), Content_.cend(), [&itemType](const TSetOfSetsType& sets) {
- return std::all_of(sets.cbegin(), sets.cend(), [&itemType](const TSetType& set) {
- return std::all_of(set.cbegin(), set.cend(), std::bind(&GetSubTypeByPath, std::placeholders::_1, std::cref(itemType)));
+ return std::all_of(Content_.cbegin(), Content_.cend(), [&itemType](const TConstraintWithFieldsNode::TSetOfSetsType& sets) {
+ return std::all_of(sets.cbegin(), sets.cend(), [&itemType](const TConstraintWithFieldsNode::TSetType& set) {
+ return std::all_of(set.cbegin(), set.cend(), std::bind(&TConstraintWithFieldsNode::GetSubTypeByPath, std::placeholders::_1, std::cref(itemType)));
});
});
}
template<bool Distinct>
const TConstraintNode* TUniqueConstraintNodeBase<Distinct>::OnlySimpleColumns(TExprContext& ctx) const {
- return FilterFields(ctx, std::bind(std::equal_to<typename TPathType::size_type>(), std::bind(&TPathType::size, std::placeholders::_1), 1ULL));
+ return DoFilterFields(ctx, std::bind(std::equal_to<typename TConstraintWithFieldsNode::TPathType::size_type>(), std::bind(&TConstraintWithFieldsNode::TPathType::size, std::placeholders::_1), 1ULL));
}
template class TUniqueConstraintNodeBase<false>;
@@ -1260,16 +1272,16 @@ template class TUniqueConstraintNodeBase<true>;
template<class TOriginalConstraintNode>
TPartOfConstraintNode<TOriginalConstraintNode>::TPartOfConstraintNode(TExprContext& ctx, TMapType&& mapping)
- : TConstraintNode(ctx, Name()), Mapping_(std::move(mapping))
+ : TBase(ctx, Name()), Mapping_(std::move(mapping))
{
YQL_ENSURE(!Mapping_.empty());
for (const auto& part : Mapping_) {
YQL_ENSURE(!part.second.empty());
const auto hash = part.first->GetHash();
- Hash_ = MurmurHash<ui64>(&hash, sizeof(hash), Hash_);
+ TBase::Hash_ = MurmurHash<ui64>(&hash, sizeof(hash), TBase::Hash_);
for (const auto& item: part.second) {
- Hash_ = std::accumulate(item.first.cbegin(), item.first.cend(), Hash_, [](ui64 hash, const std::string_view& field) { return MurmurHash<ui64>(field.data(), field.size(), hash); });
- Hash_ = std::accumulate(item.second.cbegin(), item.second.cend(), Hash_, [](ui64 hash, const std::string_view& field) { return MurmurHash<ui64>(field.data(), field.size(), hash); });
+ TBase::Hash_ = std::accumulate(item.first.cbegin(), item.first.cend(), TBase::Hash_, [](ui64 hash, const std::string_view& field) { return MurmurHash<ui64>(field.data(), field.size(), hash); });
+ TBase::Hash_ = std::accumulate(item.second.cbegin(), item.second.cend(), TBase::Hash_, [](ui64 hash, const std::string_view& field) { return MurmurHash<ui64>(field.data(), field.size(), hash); });
}
}
}
@@ -1282,7 +1294,7 @@ bool TPartOfConstraintNode<TOriginalConstraintNode>::Equals(const TConstraintNod
if (this == &node) {
return true;
}
- if (GetHash() != node.GetHash()) {
+ if (TBase::GetHash() != node.GetHash()) {
return false;
}
if (const auto c = dynamic_cast<const TPartOfConstraintNode*>(&node)) {
@@ -1348,7 +1360,7 @@ const TPartOfConstraintNode<TOriginalConstraintNode>*
TPartOfConstraintNode<TOriginalConstraintNode>::ExtractField(TExprContext& ctx, const std::string_view& field) const {
TMapType passtrought;
for (const auto& part : Mapping_) {
- auto it = part.second.lower_bound(TPathType(1U, field));
+ auto it = part.second.lower_bound(TPartOfConstraintBase::TPathType(1U, field));
if (part.second.cend() == it || it->first.front() != field)
continue;
@@ -1368,8 +1380,8 @@ TPartOfConstraintNode<TOriginalConstraintNode>::ExtractField(TExprContext& ctx,
}
template<class TOriginalConstraintNode>
-const TPartOfConstraintNode<TOriginalConstraintNode>*
-TPartOfConstraintNode<TOriginalConstraintNode>::FilterFields(TExprContext& ctx, const TPathFilter& predicate) const {
+const TPartOfConstraintBase*
+TPartOfConstraintNode<TOriginalConstraintNode>::DoFilterFields(TExprContext& ctx, const TPartOfConstraintBase::TPathFilter& predicate) const {
if (!predicate)
return this;
@@ -1391,8 +1403,8 @@ TPartOfConstraintNode<TOriginalConstraintNode>::FilterFields(TExprContext& ctx,
}
template<class TOriginalConstraintNode>
-const TPartOfConstraintNode<TOriginalConstraintNode>*
-TPartOfConstraintNode<TOriginalConstraintNode>::RenameFields(TExprContext& ctx, const TPathReduce& rename) const {
+const TPartOfConstraintBase*
+TPartOfConstraintNode<TOriginalConstraintNode>::DoRenameFields(TExprContext& ctx, const TPartOfConstraintBase::TPathReduce& rename) const {
if (!rename)
return this;
@@ -1419,9 +1431,9 @@ TPartOfConstraintNode<TOriginalConstraintNode>::CompleteOnly(TExprContext& ctx)
TMapType mapping(Mapping_);
for (auto it = mapping.begin(); mapping.end() != it;) {
- TSetType set;
+ TPartOfConstraintBase::TSetType set;
set.reserve(it->second.size());
- std::for_each(it->second.cbegin(), it->second.cend(), [&](const TPartType::value_type& pair) { set.insert_unique(pair.second); });
+ std::for_each(it->second.cbegin(), it->second.cend(), [&](const typename TPartType::value_type& pair) { set.insert_unique(pair.second); });
it->first->FilterUncompleteReferences(set);
@@ -1501,7 +1513,7 @@ TPartOfConstraintNode<TOriginalConstraintNode>::MakeCommon(const std::vector<con
it->second.cbegin(), it->second.cend(),
nextMapping.second.cbegin(), nextMapping.second.cend(),
std::back_inserter(result),
- [] (const TPartOfConstraintNode<TOriginalConstraintNode>::TPartType::value_type& c1, const TPartOfConstraintNode<TOriginalConstraintNode>::TPartType::value_type& c2) {
+ [] (const typename TPartType::value_type& c1, const typename TPartType::value_type& c2) {
return c1 < c2;
}
);
@@ -1535,7 +1547,7 @@ TPartOfConstraintNode<TOriginalConstraintNode>::GetCommonMapping(const TOriginal
mapping.erase(complete);
if (!field.empty()) {
for (auto& part : mapping) {
- std::for_each(part.second.begin(), part.second.end(), [&field](TPartType::value_type& map) { map.first.push_front(field); });
+ std::for_each(part.second.begin(), part.second.end(), [&field](typename TPartType::value_type& map) { map.first.push_front(field); });
}
}
}
@@ -1570,7 +1582,7 @@ typename TPartOfConstraintNode<TOriginalConstraintNode>::TMapType
TPartOfConstraintNode<TOriginalConstraintNode>::ExtractField(const TMapType& mapping, const std::string_view& field) {
TMapType parts;
for (const auto& part : mapping) {
- auto it = part.second.lower_bound(TPathType(1U, field));
+ auto it = part.second.lower_bound(TPartOfConstraintBase::TPathType(1U, field));
if (part.second.cend() == it || it->first.empty() || it->first.front() != field)
continue;
@@ -1598,11 +1610,11 @@ TPartOfConstraintNode<TOriginalConstraintNode>::MakeComplete(TExprContext& ctx,
for (const auto& map : it->second)
reverseMap[map.second].insert_unique(map.first);
- const auto rename = [&](const TPathType& path) {
+ const auto rename = [&](const TPartOfConstraintBase::TPathType& path) {
const auto& set = reverseMap[path];
- std::vector<TPathType> out(set.cbegin(), set.cend());
+ std::vector<TPartOfConstraintBase::TPathType> out(set.cbegin(), set.cend());
if (!field.empty())
- std::for_each(out.begin(), out.end(), [&field](TPathType& path) { path.emplace_front(field); });
+ std::for_each(out.begin(), out.end(), [&field](TPartOfConstraintBase::TPathType& path) { path.emplace_front(field); });
return out;
};
@@ -1629,7 +1641,7 @@ bool TPartOfConstraintNode<TOriginalConstraintNode>::IsApplicableToType(const TT
const auto itemType = GetSeqItemType(&type);
const auto& actualType = itemType ? *itemType : type;
return std::all_of(Mapping_.cbegin(), Mapping_.cend(), [&actualType](const typename TMapType::value_type& pair) {
- return std::all_of(pair.second.cbegin(), pair.second.cend(), [&actualType](const typename TPartType::value_type& part) { return bool(GetSubTypeByPath(part.first, actualType)); });
+ return std::all_of(pair.second.cbegin(), pair.second.cend(), [&actualType](const typename TPartType::value_type& part) { return bool(TPartOfConstraintBase::GetSubTypeByPath(part.first, actualType)); });
});
}
@@ -1641,7 +1653,7 @@ template class TPartOfConstraintNode<TDistinctConstraintNode>;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
TPassthroughConstraintNode::TPassthroughConstraintNode(TExprContext& ctx, TMapType&& mapping)
- : TConstraintNode(ctx, Name()), Mapping_(std::move(mapping))
+ : TPartOfConstraintBaseT(ctx, Name()), Mapping_(std::move(mapping))
{
YQL_ENSURE(!Mapping_.empty());
if (const auto original = Mapping_.cbegin()->first;
@@ -1663,7 +1675,7 @@ TPassthroughConstraintNode::TPassthroughConstraintNode(TExprContext& ctx, TMapTy
}
TPassthroughConstraintNode::TPassthroughConstraintNode(TExprContext& ctx, const TStructExprType& itemType)
- : TConstraintNode(ctx, Name())
+ : TPartOfConstraintBaseT(ctx, Name())
{
auto& mapping = Mapping_[nullptr];
for (const auto& item: itemType.GetItems()) {
@@ -1677,7 +1689,7 @@ TPassthroughConstraintNode::TPassthroughConstraintNode(TExprContext& ctx, const
}
TPassthroughConstraintNode::TPassthroughConstraintNode(TExprContext& ctx, const ui32 width)
- : TConstraintNode(ctx, Name())
+ : TPartOfConstraintBaseT(ctx, Name())
{
auto& mapping = Mapping_[nullptr];
for (ui32 i = 0U; i < width; ++i) {
@@ -1792,8 +1804,8 @@ const TPassthroughConstraintNode* TPassthroughConstraintNode::ExtractField(TExpr
return passtrought.empty() ? nullptr : ctx.MakeConstraint<TPassthroughConstraintNode>(std::move(passtrought));
}
-const TPassthroughConstraintNode*
-TPassthroughConstraintNode::FilterFields(TExprContext& ctx, const TPathFilter& predicate) const {
+const TPartOfConstraintBase*
+TPassthroughConstraintNode::DoFilterFields(TExprContext& ctx, const TPathFilter& predicate) const {
if (!predicate)
return this;
@@ -1814,8 +1826,8 @@ TPassthroughConstraintNode::FilterFields(TExprContext& ctx, const TPathFilter& p
return passtrought.empty() ? nullptr : ctx.MakeConstraint<TPassthroughConstraintNode>(std::move(passtrought));
}
-const TPassthroughConstraintNode*
-TPassthroughConstraintNode::RenameFields(TExprContext& ctx, const TPathReduce& rename) const {
+const TPartOfConstraintBase*
+TPassthroughConstraintNode::DoRenameFields(TExprContext& ctx, const TPathReduce& rename) const {
if (!rename)
return this;
@@ -2369,7 +2381,7 @@ const TConstraintNode* TMultiConstraintNode::OnlySimpleColumns(TExprContext& ctx
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
-void Out<NYql::TConstraintNode::TPathType>(IOutputStream& out, const NYql::TConstraintNode::TPathType& path) {
+void Out<NYql::TPartOfConstraintBase::TPathType>(IOutputStream& out, const NYql::TPartOfConstraintBase::TPathType& path) {
if (path.empty())
out.Write('/');
else {
@@ -2385,7 +2397,7 @@ void Out<NYql::TConstraintNode::TPathType>(IOutputStream& out, const NYql::TCons
}
template<>
-void Out<NYql::TConstraintNode::TSetType>(IOutputStream& out, const NYql::TConstraintNode::TSetType& c) {
+void Out<NYql::TPartOfConstraintBase::TSetType>(IOutputStream& out, const NYql::TPartOfConstraintBase::TSetType& c) {
out.Write('{');
bool first = true;
for (const auto& path : c) {
@@ -2399,7 +2411,7 @@ void Out<NYql::TConstraintNode::TSetType>(IOutputStream& out, const NYql::TConst
}
template<>
-void Out<NYql::TConstraintNode::TSetOfSetsType>(IOutputStream& out, const NYql::TConstraintNode::TSetOfSetsType& c) {
+void Out<NYql::TPartOfConstraintBase::TSetOfSetsType>(IOutputStream& out, const NYql::TPartOfConstraintBase::TSetOfSetsType& c) {
out.Write('{');
bool first = true;
for (const auto& path : c) {
diff --git a/ydb/library/yql/ast/yql_constraint.h b/ydb/library/yql/ast/yql_constraint.h
index a42ab307ea..ed587dbe6a 100644
--- a/ydb/library/yql/ast/yql_constraint.h
+++ b/ydb/library/yql/ast/yql_constraint.h
@@ -23,12 +23,7 @@ protected:
TConstraintNode(TExprContext& ctx, std::string_view name);
TConstraintNode(TConstraintNode&& constr);
public:
- using TPathType = std::deque<std::string_view>;
- using TSetType = NSorted::TSimpleSet<TPathType>;
- using TSetOfSetsType = NSorted::TSimpleSet<TSetType>;
using TListType = std::vector<const TConstraintNode*>;
- using TPathFilter = std::function<bool(const TPathType&)>;
- using TPathReduce = std::function<std::vector<TPathType>(const TPathType&)>;
struct THash {
size_t operator()(const TConstraintNode* node) const {
@@ -85,13 +80,96 @@ public:
const std::string_view& GetName() const {
return Name_;
}
+protected:
+ ui64 Hash_;
+ std::string_view Name_;
+};
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+class TPartOfConstraintBase : public TConstraintNode {
+protected:
+ TPartOfConstraintBase(TExprContext& ctx, std::string_view name);
+ TPartOfConstraintBase(TPartOfConstraintBase&& constr) = default;
+public:
+ // Path to constraint components through nested static containers (Struct/Tuple/Multi).
+ // All elements is struct member name or tuple element index.
+ // Empty deque means root.
+ using TPathType = std::deque<std::string_view>;
+
+ using TSetType = NSorted::TSimpleSet<TPathType>;
+ using TSetOfSetsType = NSorted::TSimpleSet<TSetType>;
+
+ using TPathFilter = std::function<bool(const TPathType&)>;
+ using TPathReduce = std::function<std::vector<TPathType>(const TPathType&)>;
+
+ virtual const TConstraintNode* OnlySimpleColumns(TExprContext&) const { return this; }
static const TTypeAnnotationNode* GetSubTypeByPath(const TPathType& path, const TTypeAnnotationNode& type);
protected:
+ virtual const TPartOfConstraintBase* DoFilterFields(TExprContext& ctx, const TPathFilter& predicate) const = 0;
+ virtual const TPartOfConstraintBase* DoRenameFields(TExprContext& ctx, const TPathReduce& reduce) const = 0;
+
static bool HasDuplicates(const TSetOfSetsType& sets);
+};
- ui64 Hash_;
- std::string_view Name_;
+class TConstraintWithFieldsNode : public TPartOfConstraintBase {
+protected:
+ TConstraintWithFieldsNode(TExprContext& ctx, std::string_view name);
+ TConstraintWithFieldsNode(TConstraintWithFieldsNode&& constr) = default;
+
+ // Split fields with static containers (Struct/Tuple/Multi) on separeted list of all components.
+ // As example (/tuple_of_two_elements) -> (/tuple_of_two_elements/0,/tuple_of_two_elements/1)
+ virtual const TConstraintWithFieldsNode* DoGetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const = 0;
+
+ // Combine list of separeted fields of static containers (Struct/Tuple/Multi) in single path if possible.
+ // As example (/tuple_of_two_elements/0,/tuple_of_two_elements/1) -> (/tuple_of_two_elements)
+ virtual const TConstraintWithFieldsNode* DoGetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const = 0;
+public:
+ // Leaves in the set of references only those that currently contain some complete constraint. Basically all or nothing.
+ virtual void FilterUncompleteReferences(TPartOfConstraintBase::TSetType& references) const = 0;
+};
+
+template<class TTnheritConstraint>
+class TPartOfConstraintBaseT : public TPartOfConstraintBase {
+protected:
+ TPartOfConstraintBaseT(TExprContext& ctx, std::string_view name)
+ : TPartOfConstraintBase(ctx, name)
+ {}
+ TPartOfConstraintBaseT(TPartOfConstraintBaseT&& constr) = default;
+public:
+ const TTnheritConstraint* FilterFields(TExprContext& ctx, const TPathFilter& predicate) const {
+ return static_cast<const TTnheritConstraint*>(DoFilterFields(ctx, predicate));
+ }
+
+ const TTnheritConstraint* RenameFields(TExprContext& ctx, const TPathReduce& reduce) const {
+ return static_cast<const TTnheritConstraint*>(DoRenameFields(ctx, reduce));
+ }
+};
+
+template<class TTnheritConstraint>
+class TConstraintWithFieldsT : public TConstraintWithFieldsNode {
+protected:
+ TConstraintWithFieldsT(TExprContext& ctx, std::string_view name)
+ : TConstraintWithFieldsNode(ctx, name)
+ {}
+ TConstraintWithFieldsT(TConstraintWithFieldsT&& constr) = default;
+public:
+ const TTnheritConstraint* FilterFields(TExprContext& ctx, const TPathFilter& predicate) const {
+ return static_cast<const TTnheritConstraint*>(DoFilterFields(ctx, predicate));
+ }
+
+ const TTnheritConstraint* RenameFields(TExprContext& ctx, const TPathReduce& reduce) const {
+ return static_cast<const TTnheritConstraint*>(DoRenameFields(ctx, reduce));
+ }
+
+ const TTnheritConstraint* GetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
+ return static_cast<const TTnheritConstraint*>(DoGetComplicatedForType(type, ctx));
+ }
+
+ const TTnheritConstraint* GetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const {
+ return static_cast<const TTnheritConstraint*>(DoGetSimplifiedForType(type, ctx));
+ }
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -152,7 +230,7 @@ private:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-class TSortedConstraintNode final: public TConstraintNode {
+class TSortedConstraintNode final: public TConstraintWithFieldsT<TSortedConstraintNode> {
public:
using TContainerType = TSmallVec<std::pair<TSetType, bool>>;
private:
@@ -181,24 +259,24 @@ public:
const TSortedConstraintNode* CutPrefix(size_t newPrefixLength, TExprContext& ctx) const;
- void FilterUncompleteReferences(TSetType& references) const;
+ void FilterUncompleteReferences(TSetType& references) const final;
static const TSortedConstraintNode* MakeCommon(const std::vector<const TConstraintSet*>& constraints, TExprContext& ctx);
const TSortedConstraintNode* MakeCommon(const TSortedConstraintNode* other, TExprContext& ctx) const;
- const TSortedConstraintNode* FilterFields(TExprContext& ctx, const TPathFilter& predicate) const;
- const TSortedConstraintNode* RenameFields(TExprContext& ctx, const TPathReduce& reduce) const;
-
bool IsApplicableToType(const TTypeAnnotationNode& type) const override;
const TConstraintNode* OnlySimpleColumns(TExprContext& ctx) const override;
-
- const TSortedConstraintNode* GetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const;
- const TSortedConstraintNode* GetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const;
private:
+ const TConstraintWithFieldsNode* DoFilterFields(TExprContext& ctx, const TPathFilter& predicate) const final;
+ const TConstraintWithFieldsNode* DoRenameFields(TExprContext& ctx, const TPathReduce& reduce) const final;
+
+ const TConstraintWithFieldsNode* DoGetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const final;
+ const TConstraintWithFieldsNode* DoGetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const final;
+
TContainerType Content_;
};
-class TChoppedConstraintNode final: public TConstraintNode {
+class TChoppedConstraintNode final: public TConstraintWithFieldsT<TChoppedConstraintNode> {
private:
friend struct TExprContext;
@@ -221,27 +299,28 @@ public:
bool Equals(const TSetType& prefix) const;
- void FilterUncompleteReferences(TSetType& references) const;
+ void FilterUncompleteReferences(TSetType& references) const final;
static const TChoppedConstraintNode* MakeCommon(const std::vector<const TConstraintSet*>& constraints, TExprContext& ctx);
const TChoppedConstraintNode* MakeCommon(const TChoppedConstraintNode* other, TExprContext& ctx) const;
- const TChoppedConstraintNode* FilterFields(TExprContext& ctx, const TPathFilter& predicate) const;
- const TChoppedConstraintNode* RenameFields(TExprContext& ctx, const TPathReduce& reduce) const;
-
bool IsApplicableToType(const TTypeAnnotationNode& type) const override;
const TConstraintNode* OnlySimpleColumns(TExprContext& ctx) const override;
-
- const TChoppedConstraintNode* GetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const;
- const TChoppedConstraintNode* GetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const;
private:
+ const TConstraintWithFieldsNode* DoFilterFields(TExprContext& ctx, const TPathFilter& predicate) const final;
+ const TConstraintWithFieldsNode* DoRenameFields(TExprContext& ctx, const TPathReduce& reduce) const final;
+
+ const TConstraintWithFieldsNode* DoGetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const final;
+ const TConstraintWithFieldsNode* DoGetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const final;
+
TSetOfSetsType Sets_;
};
template<bool Distinct>
-class TUniqueConstraintNodeBase final: public TConstraintNode {
+class TUniqueConstraintNodeBase final: public TConstraintWithFieldsT<TUniqueConstraintNodeBase<Distinct>> {
public:
- using TContentType = NSorted::TSimpleSet<TSetOfSetsType>;
+ using TBase = TConstraintWithFieldsT<TUniqueConstraintNodeBase<Distinct>>;
+ using TContentType = NSorted::TSimpleSet<TConstraintWithFieldsNode::TSetOfSetsType>;
protected:
friend struct TExprContext;
@@ -255,7 +334,7 @@ public:
const TContentType& GetContent() const { return Content_; }
- TSetType GetFullSet() const;
+ TPartOfConstraintBase::TSetType GetFullSet() const;
bool Equals(const TConstraintNode& node) const override;
bool Includes(const TConstraintNode& node) const override;
@@ -265,22 +344,24 @@ public:
bool IsOrderBy(const TSortedConstraintNode& sorted) const;
bool ContainsCompleteSet(const std::vector<std::string_view>& columns) const;
- void FilterUncompleteReferences(TSetType& references) const;
+ void FilterUncompleteReferences(TPartOfConstraintBase::TSetType& references) const final;
static const TUniqueConstraintNodeBase* MakeCommon(const std::vector<const TConstraintSet*>& constraints, TExprContext& ctx);
- const TUniqueConstraintNodeBase* FilterFields(TExprContext& ctx, const TPathFilter& predicate) const;
- const TUniqueConstraintNodeBase* RenameFields(TExprContext& ctx, const TPathReduce& reduce) const;
+
const TUniqueConstraintNodeBase* MakeCommon(const TUniqueConstraintNodeBase* other, TExprContext& ctx) const;
static const TUniqueConstraintNodeBase* Merge(const TUniqueConstraintNodeBase* one, const TUniqueConstraintNodeBase* two, TExprContext& ctx);
- const TUniqueConstraintNodeBase* GetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const;
- const TUniqueConstraintNodeBase* GetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const;
-
bool IsApplicableToType(const TTypeAnnotationNode& type) const override;
const TConstraintNode* OnlySimpleColumns(TExprContext& ctx) const override;
private:
- static TSetOfSetsType ColumnsListToSets(const std::vector<std::string_view>& columns);
+ const TConstraintWithFieldsNode* DoFilterFields(TExprContext& ctx, const TPartOfConstraintBase::TPathFilter& predicate) const final;
+ const TConstraintWithFieldsNode* DoRenameFields(TExprContext& ctx, const TPartOfConstraintBase::TPathReduce& reduce) const final;
+
+ const TConstraintWithFieldsNode* DoGetComplicatedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const final;
+ const TConstraintWithFieldsNode* DoGetSimplifiedForType(const TTypeAnnotationNode& type, TExprContext& ctx) const final;
+
+ static TConstraintWithFieldsNode::TSetOfSetsType ColumnsListToSets(const std::vector<std::string_view>& columns);
static TContentType DedupSets(TContentType&& sets);
static TContentType MakeCommonContent(const TContentType& one, const TContentType& two);
@@ -291,11 +372,12 @@ using TUniqueConstraintNode = TUniqueConstraintNodeBase<false>;
using TDistinctConstraintNode = TUniqueConstraintNodeBase<true>;
template<class TOriginalConstraintNode>
-class TPartOfConstraintNode : public TConstraintNode {
+class TPartOfConstraintNode final: public TPartOfConstraintBaseT<TPartOfConstraintNode<TOriginalConstraintNode>> {
public:
+ using TBase = TPartOfConstraintBaseT<TPartOfConstraintNode<TOriginalConstraintNode>>;
using TMainConstraint = TOriginalConstraintNode;
- using TPartType = NSorted::TSimpleMap<TPathType, TPathType>;
- using TReversePartType = NSorted::TSimpleMap<TPathType, NSorted::TSimpleSet<TPathType>>;
+ using TPartType = NSorted::TSimpleMap<typename TBase::TPathType, typename TBase::TPathType>;
+ using TReversePartType = NSorted::TSimpleMap<typename TBase::TPathType, NSorted::TSimpleSet<typename TBase::TPathType>>;
using TMapType = std::unordered_map<const TMainConstraint*, TPartType>;
private:
friend struct TExprContext;
@@ -315,8 +397,6 @@ public:
void ToJson(NJson::TJsonWriter& out) const override;
const TPartOfConstraintNode* ExtractField(TExprContext& ctx, const std::string_view& field) const;
- const TPartOfConstraintNode* FilterFields(TExprContext& ctx, const TPathFilter& predicate) const;
- const TPartOfConstraintNode* RenameFields(TExprContext& ctx, const TPathReduce& reduce) const;
const TPartOfConstraintNode* CompleteOnly(TExprContext& ctx) const;
static const TPartOfConstraintNode* MakeCommon(const std::vector<const TConstraintSet*>& constraints, TExprContext& ctx);
@@ -330,6 +410,9 @@ public:
bool IsApplicableToType(const TTypeAnnotationNode& type) const override;
private:
+ const TPartOfConstraintBase* DoFilterFields(TExprContext& ctx, const TPartOfConstraintBase::TPathFilter& predicate) const final;
+ const TPartOfConstraintBase* DoRenameFields(TExprContext& ctx, const TPartOfConstraintBase::TPathReduce& reduce) const final;
+
TMapType Mapping_;
};
@@ -358,9 +441,9 @@ constexpr std::string_view TPartOfDistinctConstraintNode::Name() {
return "PartOfDistinct";
}
-class TPassthroughConstraintNode final: public TConstraintNode {
+class TPassthroughConstraintNode final: public TPartOfConstraintBaseT<TPassthroughConstraintNode> {
public:
- using TPartType = NSorted::TSimpleMap<TPathType, std::string_view>;
+ using TPartType = NSorted::TSimpleMap<TPartOfConstraintBase::TPathType, std::string_view>;
using TMapType = std::unordered_map<const TPassthroughConstraintNode*, TPartType>;
using TReverseMapType = NSorted::TSimpleMap<std::string_view, std::string_view>;
private:
@@ -388,12 +471,13 @@ public:
static void UniqueMerge(TMapType& output, TMapType&& input);
const TPassthroughConstraintNode* ExtractField(TExprContext& ctx, const std::string_view& field) const;
- const TPassthroughConstraintNode* FilterFields(TExprContext& ctx, const TPathFilter& predicate) const;
- const TPassthroughConstraintNode* RenameFields(TExprContext& ctx, const TPathReduce& reduce) const;
static const TPassthroughConstraintNode* MakeCommon(const std::vector<const TConstraintSet*>& constraints, TExprContext& ctx);
const TPassthroughConstraintNode* MakeCommon(const TPassthroughConstraintNode* other, TExprContext& ctx) const;
private:
+ const TPartOfConstraintBase* DoFilterFields(TExprContext& ctx, const TPathFilter& predicate) const final;
+ const TPartOfConstraintBase* DoRenameFields(TExprContext& ctx, const TPathReduce& reduce) const final;
+
TMapType Mapping_;
};
@@ -426,7 +510,6 @@ protected:
TVarIndexConstraintNode(TExprContext& ctx, const TVariantExprType& itemType);
TVarIndexConstraintNode(TExprContext& ctx, size_t mapItemsCount);
TVarIndexConstraintNode(TVarIndexConstraintNode&& constr);
-
public:
static constexpr std::string_view Name() {
return "VarIndex";
@@ -454,12 +537,10 @@ private:
class TMultiConstraintNode final: public TConstraintNode {
public:
using TMapType = NSorted::TSimpleMap<ui32, TConstraintSet>;
-
public:
TMultiConstraintNode(TExprContext& ctx, const TMapType& items);
TMultiConstraintNode(TExprContext& ctx, ui32 index, const TConstraintSet& constraints);
TMultiConstraintNode(TMultiConstraintNode&& constr);
-
public:
static constexpr std::string_view Name() {
return "Multi";
diff --git a/ydb/library/yql/core/common_opt/yql_co_simple1.cpp b/ydb/library/yql/core/common_opt/yql_co_simple1.cpp
index 4214724b1d..e0ab0c6540 100644
--- a/ydb/library/yql/core/common_opt/yql_co_simple1.cpp
+++ b/ydb/library/yql/core/common_opt/yql_co_simple1.cpp
@@ -3105,10 +3105,10 @@ std::unordered_set<ui32> GetUselessSortedJoinInputs(const TCoEquiJoin& equiJoin)
joinTreeNodes.emplace_back(joinTree->Child(2));
if (!joinTree->Head().IsAtom("Cross")) {
- std::unordered_map<std::string_view, TConstraintNode::TSetType> tableJoinKeys;
+ std::unordered_map<std::string_view, TPartOfConstraintBase::TSetType> tableJoinKeys;
for (const auto keys : {joinTree->Child(3), joinTree->Child(4)})
for (ui32 i = 0U; i < keys->ChildrenSize(); ++i)
- tableJoinKeys[keys->Child(i)->Content()].insert_unique(TConstraintNode::TPathType(1U, keys->Child(++i)->Content()));
+ tableJoinKeys[keys->Child(i)->Content()].insert_unique(TPartOfConstraintBase::TPathType(1U, keys->Child(++i)->Content()));
for (const auto& [label, joinKeys]: tableJoinKeys) {
if (const auto it = sorteds.find(label); sorteds.cend() != it) {
diff --git a/ydb/library/yql/core/yql_expr_constraint.cpp b/ydb/library/yql/core/yql_expr_constraint.cpp
index fc5dacc8bb..6f7da14347 100644
--- a/ydb/library/yql/core/yql_expr_constraint.cpp
+++ b/ydb/library/yql/core/yql_expr_constraint.cpp
@@ -353,7 +353,7 @@ private:
for (const auto& item : input->Tail().Children()) {
if (item->Tail().IsCallable("Bool"))
- sorted.emplace_back(std::make_pair(TConstraintNode::TSetType{TConstraintNode::TPathType(1U, item->Head().Content())}, FromString<bool>(item->Tail().Tail().Content())));
+ sorted.emplace_back(std::make_pair(TPartOfConstraintBase::TSetType{TPartOfConstraintBase::TPathType(1U, item->Head().Content())}, FromString<bool>(item->Tail().Tail().Content())));
else
break;
}
@@ -382,19 +382,19 @@ private:
TStatus AssumeUniqueWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const {
typename TUniqueConstraintNodeBase<Distinct>::TContentType content;
for (auto i = 1U; i < input->ChildrenSize(); ++i) {
- TConstraintNode::TSetOfSetsType sets;
+ TPartOfConstraintBase::TSetOfSetsType sets;
sets.reserve(input->Child(i)->ChildrenSize());
for (const auto& list : input->Child(i)->Children()) {
if (list->IsAtom())
- sets.insert_unique(TConstraintNode::TSetType{TConstraintNode::TPathType(1U, list->Content())});
+ sets.insert_unique(TPartOfConstraintBase::TSetType{TPartOfConstraintBase::TPathType(1U, list->Content())});
else if (list->IsList()) {
- TConstraintNode::TSetType columns;
+ TPartOfConstraintBase::TSetType columns;
columns.reserve(list->ChildrenSize());
for (const auto& column: list->Children()) {
if (column->IsAtom())
- columns.insert_unique(TConstraintNode::TPathType(1U, column->Content()));
+ columns.insert_unique(TPartOfConstraintBase::TPathType(1U, column->Content()));
else if (column->IsList()) {
- TConstraintNode::TPathType path(column->ChildrenSize());
+ TPartOfConstraintBase::TPathType path(column->ChildrenSize());
std::transform(column->Children().cbegin(), column->Children().cend(), path.begin(), [](const TExprNode::TPtr& atom) { return atom->Content(); } );
columns.insert_unique(std::move(path));
}
@@ -406,7 +406,7 @@ private:
}
if (content.empty())
- content.insert_unique(TConstraintNode::TSetOfSetsType{TConstraintNode::TSetType{TConstraintNode::TPathType()}});
+ content.insert_unique(TPartOfConstraintBase::TSetOfSetsType{TPartOfConstraintBase::TSetType{TPartOfConstraintBase::TPathType()}});
auto constraint = ctx.MakeConstraint<TUniqueConstraintNodeBase<Distinct>>(std::move(content));
if (!constraint->IsApplicableToType(*input->GetTypeAnn())) {
@@ -428,15 +428,15 @@ private:
}
TStatus AssumeChoppedWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const {
- TConstraintNode::TSetOfSetsType sets;
+ TPartOfConstraintBase::TSetOfSetsType sets;
for (auto i = 1U; i < input->ChildrenSize(); ++i) {
- TConstraintNode::TSetType columns;
+ TPartOfConstraintBase::TSetType columns;
columns.reserve(input->Child(i)->ChildrenSize());
for (const auto& column: input->Child(i)->Children()) {
if (column->IsAtom())
- columns.insert_unique(TConstraintNode::TPathType(1U, column->Content()));
+ columns.insert_unique(TPartOfConstraintBase::TPathType(1U, column->Content()));
else if (column->IsList()) {
- TConstraintNode::TPathType path(column->ChildrenSize());
+ TPartOfConstraintBase::TPathType path(column->ChildrenSize());
std::transform(column->Children().cbegin(), column->Children().cend(), path.begin(), [](const TExprNode::TPtr& atom) { return atom->Content(); } );
columns.insert_unique(std::move(path));
}
@@ -478,7 +478,7 @@ private:
}
template<class TConstraint>
- static void FilterFromHead(const TExprNode& input, TConstraintSet& constraints, const TConstraintNode::TPathFilter& filter, TExprContext& ctx) {
+ static void FilterFromHead(const TExprNode& input, TConstraintSet& constraints, const TPartOfConstraintBase::TPathFilter& filter, TExprContext& ctx) {
if (const auto source = input.Head().GetConstraint<TConstraint>()) {
if (const auto filtered = source->FilterFields(ctx, filter)) {
constraints.AddConstraint(filtered);
@@ -487,7 +487,7 @@ private:
}
template<class TConstraint, bool Simplify = false>
- static void ReduceFromHead(const TExprNode::TPtr& input, const TConstraintNode::TPathReduce& reduce, TExprContext& ctx) {
+ static void ReduceFromHead(const TExprNode::TPtr& input, const TPartOfConstraintBase::TPathReduce& reduce, TExprContext& ctx) {
if (const auto source = input->Head().GetConstraint<TConstraint>()) {
if (const auto filtered = source->RenameFields(ctx, reduce)) {
if constexpr (Simplify)
@@ -499,7 +499,7 @@ private:
}
template<class TConstraint, bool Simplify = false>
- static void FilterFromHead(const TExprNode::TPtr& input, const TConstraintNode::TPathFilter& filter, TExprContext& ctx) {
+ static void FilterFromHead(const TExprNode::TPtr& input, const TPartOfConstraintBase::TPathFilter& filter, TExprContext& ctx) {
if (const auto source = input->Head().GetConstraint<TConstraint>()) {
if (const auto filtered = source->FilterFields(ctx, filter)) {
if constexpr (Simplify)
@@ -511,7 +511,7 @@ private:
}
template<class TConstraint>
- static void FilterFromHeadIfMissed(const TExprNode::TPtr& input, const TConstraintNode::TPathFilter& filter, TExprContext& ctx) {
+ static void FilterFromHeadIfMissed(const TExprNode::TPtr& input, const TPartOfConstraintBase::TPathFilter& filter, TExprContext& ctx) {
if (!input->GetConstraint<TConstraint>())
FilterFromHead<TConstraint>(input, filter, ctx);
}
@@ -556,8 +556,8 @@ private:
}
}
else if (outItemType->GetKind() == ETypeAnnotationKind::Struct) {
- const auto filter = [outItemType](const TConstraintNode::TPathType& path) {
- return !path.empty() && TConstraintNode::GetSubTypeByPath(path, *outItemType);
+ const auto filter = [outItemType](const TPartOfConstraintBase::TPathType& path) {
+ return !path.empty() && TPartOfConstraintBase::GetSubTypeByPath(path, *outItemType);
};
FilterFromHead<TPassthroughConstraintNode>(input, filter, ctx);
@@ -574,19 +574,19 @@ private:
TStatus CastWrap(const TExprNode::TPtr& input, TExprNode::TPtr& /*output*/, TExprContext& ctx) const {
const auto outItemType = input->GetTypeAnn();
const auto inItemType = input->Head().GetTypeAnn();
- const auto filter = [inItemType, outItemType](const TConstraintNode::TPathType& path) {
- if (const auto outType = TConstraintNode::GetSubTypeByPath(path, *outItemType))
- return IsSameAnnotation(*outType, *TConstraintNode::GetSubTypeByPath(path, *inItemType));
+ const auto filter = [inItemType, outItemType](const TPartOfConstraintBase::TPathType& path) {
+ if (const auto outType = TPartOfConstraintBase::GetSubTypeByPath(path, *outItemType))
+ return IsSameAnnotation(*outType, *TPartOfConstraintBase::GetSubTypeByPath(path, *inItemType));
return false;
};
- const auto filterForUnique = [inItemType, outItemType](const TConstraintNode::TPathType& path) {
- const auto castResult = CastResult<Strict>(TConstraintNode::GetSubTypeByPath(path, *inItemType), TConstraintNode::GetSubTypeByPath(path, *outItemType));
+ const auto filterForUnique = [inItemType, outItemType](const TPartOfConstraintBase::TPathType& path) {
+ const auto castResult = CastResult<Strict>(TPartOfConstraintBase::GetSubTypeByPath(path, *inItemType), TPartOfConstraintBase::GetSubTypeByPath(path, *outItemType));
return NUdf::ECastOptions::Complete == castResult || NUdf::ECastOptions::MayFail == castResult;
};
- const auto filterForDistinct = [inItemType, outItemType](const TConstraintNode::TPathType& path) {
- return NUdf::ECastOptions::Complete == CastResult<Strict>(TConstraintNode::GetSubTypeByPath(path, *inItemType), TConstraintNode::GetSubTypeByPath(path, *outItemType));
+ const auto filterForDistinct = [inItemType, outItemType](const TPartOfConstraintBase::TPathType& path) {
+ return NUdf::ECastOptions::Complete == CastResult<Strict>(TPartOfConstraintBase::GetSubTypeByPath(path, *inItemType), TPartOfConstraintBase::GetSubTypeByPath(path, *outItemType));
};
FilterFromHead<TPassthroughConstraintNode>(input, filter, ctx);
@@ -603,7 +603,7 @@ private:
TStatus DivePrefixMembersWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const {
const auto prefixes = input->Tail().Children();
- const auto rename = [&prefixes](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ const auto rename = [&prefixes](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
if (path.empty())
return {};
@@ -628,7 +628,7 @@ private:
TStatus ExtractMembersWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const {
const auto outItemType = GetSeqItemType(*input->GetTypeAnn()).Cast<TStructExprType>();
- const auto filter = [outItemType](const TConstraintNode::TPathType& path) { return !path.empty() && outItemType->FindItem(path.front()); };
+ const auto filter = [outItemType](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && outItemType->FindItem(path.front()); };
FilterFromHead<TPassthroughConstraintNode>(input, filter, ctx);
FilterFromHead<TSortedConstraintNode>(input, filter, ctx);
FilterFromHead<TChoppedConstraintNode>(input, filter, ctx);
@@ -649,7 +649,7 @@ private:
if (outItemType->GetKind() == ETypeAnnotationKind::Struct) {
const auto outStructType = outItemType->Cast<TStructExprType>();
- const auto filter = [outStructType](const TConstraintNode::TPathType& path) { return !path.empty() && outStructType->FindItem(path.front()); };
+ const auto filter = [outStructType](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && outStructType->FindItem(path.front()); };
FilterFromHead<TPassthroughConstraintNode>(input, filter, ctx);
FilterFromHead<TPartOfSortedConstraintNode>(input, filter, ctx);
FilterFromHead<TPartOfChoppedConstraintNode>(input, filter, ctx);
@@ -665,7 +665,7 @@ private:
auto& constr = multiItems[item.first];
const auto outStructType = tupleUnderType->GetItems()[item.first]->Cast<TStructExprType>();
- const auto filter = [outStructType](const TConstraintNode::TPathType& path) { return !path.empty() && outStructType->FindItem(path.front()); };
+ const auto filter = [outStructType](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && outStructType->FindItem(path.front()); };
FilterFromHead<TPassthroughConstraintNode>(*input, constr, filter, ctx);
FilterFromHead<TPartOfSortedConstraintNode>(*input, constr, filter, ctx);
FilterFromHead<TPartOfChoppedConstraintNode>(*input, constr, filter, ctx);
@@ -728,9 +728,9 @@ private:
return std::nullopt;
}
- static std::optional<TConstraintNode::TPathType> GetPathToKey(const TExprNode& body, const TExprNode& arg) {
+ static std::optional<TPartOfConstraintBase::TPathType> GetPathToKey(const TExprNode& body, const TExprNode& arg) {
if (&body == &arg)
- return TConstraintNode::TPathType();
+ return TPartOfConstraintBase::TPathType();
if (body.IsCallable({"Member","Nth"})) {
if (auto path = GetPathToKey(body.Head(), arg)) {
@@ -751,19 +751,19 @@ private:
return std::nullopt;
}
- static std::vector<std::pair<TConstraintNode::TPathType, bool>>
+ static std::vector<std::pair<TPartOfConstraintBase::TPathType, bool>>
ExtractSimpleSortTraits(const TExprNode& sortDirections, const TExprNode& keySelectorLambda) {
const auto& keySelectorBody = keySelectorLambda.Tail();
const auto& keySelectorArg = keySelectorLambda.Head().Head();
- std::vector<std::pair<TConstraintNode::TPathType, bool>> columns;
+ std::vector<std::pair<TPartOfConstraintBase::TPathType, bool>> columns;
if (const auto dir = GetDirection(sortDirections))
- columns.emplace_back(TConstraintNode::TPathType(), *dir);
+ columns.emplace_back(TPartOfConstraintBase::TPathType(), *dir);
else if (sortDirections.IsList())
if (const auto size = keySelectorBody.ChildrenSize()) {
columns.reserve(size);
for (auto i = 0U; i < size; ++i)
if (const auto dir = GetDirection(*sortDirections.Child(i)))
- columns.emplace_back(TConstraintNode::TPathType(), *dir);
+ columns.emplace_back(TPartOfConstraintBase::TPathType(), *dir);
else
return {};
} else
@@ -773,9 +773,9 @@ private:
if (keySelectorBody.IsList())
if (const auto size = keySelectorBody.ChildrenSize()) {
- TConstraintNode::TSetType set;
+ TPartOfConstraintBase::TSetType set;
set.reserve(size);
- columns.resize(size, std::make_pair(TConstraintNode::TPathType(), columns.back().second));
+ columns.resize(size, std::make_pair(TPartOfConstraintBase::TPathType(), columns.back().second));
auto it = columns.begin();
for (auto i = 0U; i < size; ++i) {
if (auto path = GetPathToKey(*keySelectorBody.Child(i), keySelectorArg)) {
@@ -1143,7 +1143,7 @@ private:
if (const auto lambdaEmpty = GetConstraintFromLambda<TEmptyConstraintNode, WideOutput>(input->Tail(), ctx)) {
input->AddConstraint(lambdaEmpty);
- const auto& filter = std::bind(&TConstraintNode::GetSubTypeByPath, std::placeholders::_1, std::cref(GetSeqItemType(*input->GetTypeAnn())));
+ const auto& filter = std::bind(&TPartOfConstraintBase::GetSubTypeByPath, std::placeholders::_1, std::cref(GetSeqItemType(*input->GetTypeAnn())));
FilterFromHeadIfMissed<TUniqueConstraintNode>(input, filter, ctx);
FilterFromHeadIfMissed<TDistinctConstraintNode>(input, filter, ctx);
if constexpr (Ordered) {
@@ -1253,11 +1253,11 @@ private:
auto content = sort->GetContent();
for (auto i = 0U; i < content.size(); ++i) {
for (auto it = content[i].first.cbegin(); content[i].first.cend() != it;) {
- const auto resultItemSubType = TConstraintNode::GetSubTypeByPath(*it, *resultItemType);
+ const auto resultItemSubType = TPartOfConstraintBase::GetSubTypeByPath(*it, *resultItemType);
YQL_ENSURE(resultItemSubType, "Missing " << *it << " in result type");
auto childNdx = 0U;
while (childNdx < input->ChildrenSize()) {
- if (const auto inputItemSubType = TConstraintNode::GetSubTypeByPath(*it, *inputs[childNdx])) {
+ if (const auto inputItemSubType = TPartOfConstraintBase::GetSubTypeByPath(*it, *inputs[childNdx])) {
if (IsSameAnnotation(*inputItemSubType, *resultItemSubType)) {
++childNdx;
continue;
@@ -1518,7 +1518,7 @@ private:
typename TPartOfConstraint::TMapType sorted;
const auto& name = input->Child(1)->Content();
if (const auto part = input->Head().GetConstraint<TPartOfConstraint>()) {
- if (const auto filtered = part->FilterFields(ctx, [&name](const TConstraintNode::TPathType& path) { return !path.empty() && path.front() != name; })) {
+ if (const auto filtered = part->FilterFields(ctx, [&name](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && path.front() != name; })) {
sorted = filtered->GetColumnMapping();
}
}
@@ -1576,7 +1576,7 @@ private:
TStatus RemoveMemberWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const {
const auto& name = input->Tail().Content();
- const auto filter = [&name](const TConstraintNode::TPathType& path) { return !path.empty() && path.front() != name; };
+ const auto filter = [&name](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && path.front() != name; };
FilterFromHead<TPassthroughConstraintNode>(input, filter, ctx);
FilterFromHead<TPartOfSortedConstraintNode>(input, filter, ctx);
FilterFromHead<TPartOfChoppedConstraintNode>(input, filter, ctx);
@@ -1592,7 +1592,7 @@ private:
if (const auto structPassthrough = input->Head().GetConstraint<TPassthroughConstraintNode>(), fieldPasstrought = input->Tail().GetConstraint<TPassthroughConstraintNode>();
structPassthrough || fieldPasstrought) {
- const auto filtered = structPassthrough ? structPassthrough->FilterFields(ctx, [&name](const TConstraintNode::TPathType& path) { return !path.empty() && path.front() != name; }) : nullptr;
+ const auto filtered = structPassthrough ? structPassthrough->FilterFields(ctx, [&name](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && path.front() != name; }) : nullptr;
auto mapping = filtered ? filtered->GetColumnMapping() : TPassthroughConstraintNode::TMapType();
if (fieldPasstrought) {
for (const auto& part : fieldPasstrought->GetColumnMapping()) {
@@ -1831,7 +1831,7 @@ private:
TStatus ReverseWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const {
if (const auto sorted = input->Head().GetConstraint<TSortedConstraintNode>()) {
auto content = sorted->GetContent();
- std::for_each(content.begin(), content.end(), [](std::pair<TConstraintNode::TSetType, bool>& pair) { pair.second = !pair.second; });
+ std::for_each(content.begin(), content.end(), [](std::pair<TPartOfConstraintBase::TSetType, bool>& pair) { pair.second = !pair.second; });
input->AddConstraint(ctx.MakeConstraint<TSortedConstraintNode>(std::move(content)));
}
return FromFirst<TPassthroughConstraintNode, TEmptyConstraintNode, TChoppedConstraintNode, TPartOfChoppedConstraintNode, TUniqueConstraintNode, TPartOfUniqueConstraintNode, TDistinctConstraintNode, TPartOfDistinctConstraintNode, TVarIndexConstraintNode, TMultiConstraintNode>(input, output, ctx);
@@ -2292,7 +2292,7 @@ private:
}
if (const auto renames = LoadJoinRenameMap(input->Tail()); !renames.empty() && (unique || distinct)) {
- const auto rename = [&renames](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ const auto rename = [&renames](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
if (path.empty())
return {};
@@ -2302,7 +2302,7 @@ private:
if (it->second.empty())
return {};
- std::vector<TConstraintNode::TPathType> res(it->second.size());
+ std::vector<TPartOfConstraintBase::TPathType> res(it->second.size());
std::transform(it->second.cbegin(), it->second.cend(), res.begin(), [&path](const std::string_view& newName) {
auto newPath = path;
newPath.front() = newName;
@@ -2333,11 +2333,11 @@ private:
}
template<bool ForDict = false>
- static TConstraintNode::TPathReduce GetRenames(const TExprNode& renames) {
+ static TPartOfConstraintBase::TPathReduce GetRenames(const TExprNode& renames) {
std::unordered_map<std::string_view, std::string_view> map(renames.ChildrenSize() >> 1U);
for (auto i = 0U; i < renames.ChildrenSize(); ++++i)
map.emplace(renames.Child(i)->Content(), renames.Child(i + 1U)->Content());
- return [map](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ return [map](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
if constexpr (ForDict) {
if (path.size() > 1U && path.front() == "1"sv) {
auto out = path;
@@ -2505,7 +2505,7 @@ private:
template<bool Distinct>
static const TUniqueConstraintNodeBase<Distinct>* GetForPayload(const TExprNode& input, TExprContext& ctx) {
if (const auto constraint = input.GetConstraint<TUniqueConstraintNodeBase<Distinct>>()) {
- return constraint->RenameFields(ctx, [&ctx](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ return constraint->RenameFields(ctx, [&ctx](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
if (path.empty() || path.front() != ctx.GetIndexAsString(1U))
return {};
auto copy = path;
@@ -2559,9 +2559,9 @@ private:
input->AddConstraint(rDistinct);
}
} else if (lOneRow || rOneRow) {
- const auto rename = [](const std::string_view& prefix, TConstraintNode::TPathType path) {
+ const auto rename = [](const std::string_view& prefix, TPartOfConstraintBase::TPathType path) {
path.emplace_front(prefix);
- return std::vector<TConstraintNode::TPathType>(1U, std::move(path));
+ return std::vector<TPartOfConstraintBase::TPathType>(1U, std::move(path));
};
const auto leftRename = std::bind(rename, ctx.GetIndexAsString(0U), std::placeholders::_1);
const auto rightRename = std::bind(rename, ctx.GetIndexAsString(1U), std::placeholders::_1);
@@ -2622,11 +2622,11 @@ private:
ythrow yexception() << "Member '" << member.Content() << "' not found in literal struct.";
}
- static std::optional<std::pair<TConstraintNode::TPathType, ui32>> GetPathToKey(const TExprNode& body, const TExprNode::TChildrenType& args) {
+ static std::optional<std::pair<TPartOfConstraintBase::TPathType, ui32>> GetPathToKey(const TExprNode& body, const TExprNode::TChildrenType& args) {
if (body.IsArgument()) {
for (auto i = 0U; i < args.size(); ++i)
if (&body == args[i].Get())
- return std::make_pair(TConstraintNode::TPathType(), i);
+ return std::make_pair(TPartOfConstraintBase::TPathType(), i);
} else if (body.IsCallable({"Member","Nth"})) {
if (auto path = GetPathToKey(body.Head(), args)) {
path->first.emplace_back(body.Tail().Content());
@@ -2644,8 +2644,8 @@ private:
}
template<bool Wide>
- static TConstraintNode::TSetType GetSimpleKeys(const TExprNode& body, const TExprNode::TChildrenType& args, TExprContext& ctx) {
- TConstraintNode::TSetType keys;
+ static TPartOfConstraintBase::TSetType GetSimpleKeys(const TExprNode& body, const TExprNode::TChildrenType& args, TExprContext& ctx) {
+ TPartOfConstraintBase::TSetType keys;
if (body.IsCallable("AggrNotEquals")) {
if (body.Head().IsList() && body.Tail().IsList() && body.Head().ChildrenSize() == body.Tail().ChildrenSize()) {
keys.reserve(body.Tail().ChildrenSize());
@@ -2680,8 +2680,8 @@ private:
return keys;
}
- static TConstraintNode::TSetType GetSimpleKeys(const TExprNode& body, const TExprNode& arg) {
- TConstraintNode::TSetType keys;
+ static TPartOfConstraintBase::TSetType GetSimpleKeys(const TExprNode& body, const TExprNode& arg) {
+ TPartOfConstraintBase::TSetType keys;
if (body.IsList()) {
if (const auto size = body.ChildrenSize()) {
keys.reserve(size);
@@ -2699,7 +2699,7 @@ private:
}
template<bool Wide>
- static TConstraintNode::TSetType GetSimpleKeys(const TExprNode& selector, TExprContext& ctx) {
+ static TPartOfConstraintBase::TSetType GetSimpleKeys(const TExprNode& selector, TExprContext& ctx) {
YQL_ENSURE(selector.IsLambda() && 2U == selector.ChildrenSize());
const auto& body = selector.Tail();
if constexpr (!Wide) {
@@ -2707,7 +2707,7 @@ private:
const TCoIsKeySwitch keySwitch(&body);
const auto& i = GetSimpleKeys(keySwitch.ItemKeyExtractor().Body().Ref(), keySwitch.ItemKeyExtractor().Args().Arg(0).Ref());
const auto& s = GetSimpleKeys(keySwitch.StateKeyExtractor().Body().Ref(), keySwitch.StateKeyExtractor().Args().Arg(0).Ref());
- return i == s ? i : TConstraintNode::TSetType();
+ return i == s ? i : TPartOfConstraintBase::TSetType();
}
}
@@ -2772,10 +2772,10 @@ private:
if (sorted || chopped) {
if (const auto& keys = GetSimpleKeys<Wide>(*FuseInitLambda(*initLambda, *switchLambda, ctx), ctx); !keys.empty()) {
if (sorted && sorted->StartsWith(keys) || chopped && chopped->Equals(keys)) {
- TConstraintNode::TSetOfSetsType sets;
+ TPartOfConstraintBase::TSetOfSetsType sets;
sets.reserve(keys.size());
for (const auto& key : keys)
- sets.insert_unique(TConstraintNode::TSetType{key});
+ sets.insert_unique(TPartOfConstraintBase::TSetType{key});
unique = ctx.MakeConstraint<TUniqueConstraintNode>(TUniqueConstraintNode::TContentType{sets});
distinct = ctx.MakeConstraint<TDistinctConstraintNode>(TDistinctConstraintNode::TContentType{sets});
if constexpr (Wide) {
@@ -2864,7 +2864,7 @@ private:
template<bool Distinct>
static void GetUniquesForPayloads(const TExprNode::TPtr& input, TExprContext& ctx) {
- typename TUniqueConstraintNodeBase<Distinct>::TContentType content{TConstraintNode::TSetOfSetsType{TConstraintNode::TSetType{TConstraintNode::TPathType{ctx.GetIndexAsString(0U)}}}};
+ typename TUniqueConstraintNodeBase<Distinct>::TContentType content{TPartOfConstraintBase::TSetOfSetsType{TPartOfConstraintBase::TSetType{TPartOfConstraintBase::TPathType{ctx.GetIndexAsString(0U)}}}};
if (const auto lambda = GetConstraintFromLambda<TPartOfConstraintNode<TUniqueConstraintNodeBase<Distinct>>, false>(*input->Child(2), ctx)) {
if (const auto original = GetDetailed(input->Head().GetConstraint<TUniqueConstraintNodeBase<Distinct>>(), *input->Head().GetTypeAnn(), ctx)) {
if (const auto complete = TPartOfConstraintNode<TUniqueConstraintNodeBase<Distinct>>::MakeComplete(ctx, lambda->GetColumnMapping(), original, ctx.GetIndexAsString(1U))) {
@@ -2909,7 +2909,7 @@ private:
template<bool Keys>
TStatus DictHalfWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const {
const auto& side = ctx.GetIndexAsString(Keys ? 0U : 1U);
- const auto reduce = [&side](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ const auto reduce = [&side](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
if (path.empty() || path.front() != side)
return {};
@@ -2934,7 +2934,7 @@ private:
return status;
}
- TConstraintNode::TSetType keys;
+ TPartOfConstraintBase::TSetType keys;
if constexpr (Partitions) {
keys = GetSimpleKeys(input->Child(TCoBase::idx_KeySelectorLambda)->Tail(), input->Child(TCoBase::idx_KeySelectorLambda)->Head().Head());
if (const auto sortKeySelector = input->Child(TCoBase::idx_SortKeySelectorLambda); sortKeySelector->IsLambda()) {
@@ -3204,7 +3204,7 @@ private:
static const TSortedConstraintNode* DeduceSortConstraint(const TExprNode& directions, const TExprNode& keyExtractor, TExprContext& ctx) {
if (const auto& columns = ExtractSimpleSortTraits(directions, keyExtractor); !columns.empty()) {
TSortedConstraintNode::TContainerType content(columns.size());
- std::transform(columns.cbegin(), columns.cend(), content.begin(), [](const std::pair<TConstraintNode::TPathType, bool>& item) {
+ std::transform(columns.cbegin(), columns.cend(), content.begin(), [](const std::pair<TPartOfConstraintBase::TPathType, bool>& item) {
return std::make_pair(TSortedConstraintNode::TSetType{item.first}, item.second);
});
return ctx.MakeConstraint<TSortedConstraintNode>(std::move(content));
diff --git a/ydb/library/yql/core/yql_join.cpp b/ydb/library/yql/core/yql_join.cpp
index 6ad248c80b..7e1a77bebe 100644
--- a/ydb/library/yql/core/yql_join.cpp
+++ b/ydb/library/yql/core/yql_join.cpp
@@ -123,7 +123,7 @@ namespace {
scope.insert(x);
}
- const auto rename = [&](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ const auto rename = [&](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
if (path.empty())
return {};
auto newPath = path;
diff --git a/ydb/library/yql/core/yql_opt_utils.cpp b/ydb/library/yql/core/yql_opt_utils.cpp
index 2dfaf1d446..4e834b9201 100644
--- a/ydb/library/yql/core/yql_opt_utils.cpp
+++ b/ydb/library/yql/core/yql_opt_utils.cpp
@@ -71,7 +71,7 @@ TExprNode::TPtr KeepChoppedConstraint(TExprNode::TPtr node, const TExprNode& src
return node;
}
-TExprNodeBuilder GetterBuilder(TExprNodeBuilder parent, ui32 index, TConstraintNode::TPathType path) {
+TExprNodeBuilder GetterBuilder(TExprNodeBuilder parent, ui32 index, TPartOfConstraintBase::TPathType path) {
if (path.empty())
return parent.Arg(index, "item");
@@ -159,7 +159,7 @@ bool IsListReorder(const TExprNode& node) {
// Check if the flat map is a simple rename flat map
bool IsRenameFlatMap(const NNodes::TCoFlatMapBase& node, TExprNode::TPtr& structNode) {
-
+
auto lambda = node.Lambda();
if (!IsJustOrSingleAsList(lambda.Body().Ref())) {
return false;
@@ -173,7 +173,7 @@ bool IsRenameFlatMap(const NNodes::TCoFlatMapBase& node, TExprNode::TPtr& struct
}
for (auto child : asStruct.Cast<TCoAsStruct>()) {
-
+
if (!child.Item(1).Maybe<TCoMember>()) {
return false;
}
@@ -188,9 +188,9 @@ bool IsRenameFlatMap(const NNodes::TCoFlatMapBase& node, TExprNode::TPtr& struct
}
// Check if the flat map is a simple rename flat map and compute the mapping from new names to original ones
-bool IsRenameFlatMapWithMapping(const NNodes::TCoFlatMapBase& node, TExprNode::TPtr& structNode,
+bool IsRenameFlatMapWithMapping(const NNodes::TCoFlatMapBase& node, TExprNode::TPtr& structNode,
THashMap<TString, TString> & mapping) {
-
+
auto lambda = node.Lambda();
if (!IsJustOrSingleAsList(lambda.Body().Ref())) {
return false;
diff --git a/ydb/library/yql/providers/dq/provider/yql_dq_datasink_constraints.cpp b/ydb/library/yql/providers/dq/provider/yql_dq_datasink_constraints.cpp
index 90fd45c61b..f1f0b51a66 100644
--- a/ydb/library/yql/providers/dq/provider/yql_dq_datasink_constraints.cpp
+++ b/ydb/library/yql/providers/dq/provider/yql_dq_datasink_constraints.cpp
@@ -188,10 +188,10 @@ public:
const bool lOneRow = leftAny || lUnique && lUnique->ContainsCompleteSet(leftJoinKeys);
const bool rOneRow = rightAny || rUnique && rUnique->ContainsCompleteSet(rightJoinKeys);
- const auto makeRename = [&ctx](const TExprBase& label) -> TConstraintNode::TPathReduce {
+ const auto makeRename = [&ctx](const TExprBase& label) -> TPartOfConstraintBase::TPathReduce {
if (label.Ref().IsAtom()) {
const auto table = label.Cast<TCoAtom>().Value();
- return [table, &ctx](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ return [table, &ctx](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
if (path.empty())
return {path};
auto out = path;
diff --git a/ydb/library/yql/providers/yt/lib/row_spec/yql_row_spec.cpp b/ydb/library/yql/providers/yt/lib/row_spec/yql_row_spec.cpp
index 04e62d580d..a312e07c33 100644
--- a/ydb/library/yql/providers/yt/lib/row_spec/yql_row_spec.cpp
+++ b/ydb/library/yql/providers/yt/lib/row_spec/yql_row_spec.cpp
@@ -503,7 +503,7 @@ NYT::TNode TYqlRowSpecInfo::GetConstraintsNode() const {
auto map = NYT::TNode::CreateMap();
- const auto pathToNode = [](const TConstraintNode::TPathType& path) -> NYT::TNode {
+ const auto pathToNode = [](const TPartOfConstraintBase::TPathType& path) -> NYT::TNode {
if (1U == path.size())
return TStringBuf(path.front());
@@ -513,7 +513,7 @@ NYT::TNode TYqlRowSpecInfo::GetConstraintsNode() const {
return list;
};
- const auto setToNode = [pathToNode](const TConstraintNode::TSetType& set) -> NYT::TNode {
+ const auto setToNode = [pathToNode](const TPartOfConstraintBase::TSetType& set) -> NYT::TNode {
if (1U == set.size() && 1U == set.front().size())
return TStringBuf(set.front().front());
@@ -572,9 +572,9 @@ void TYqlRowSpecInfo::ParseConstraintsNode(TExprContext& ctx) {
try {
const auto nodeToPath = [&ctx](const NYT::TNode& node) {
if (node.IsString())
- return TConstraintNode::TPathType{ctx.AppendString(node.AsString())};
+ return TPartOfConstraintBase::TPathType{ctx.AppendString(node.AsString())};
- TConstraintNode::TPathType path;
+ TPartOfConstraintBase::TPathType path;
for (const auto& col : node.AsList())
path.emplace_back(ctx.AppendString(col.AsString()));
return path;
@@ -582,9 +582,9 @@ void TYqlRowSpecInfo::ParseConstraintsNode(TExprContext& ctx) {
const auto nodeToSet = [&ctx, nodeToPath](const NYT::TNode& node) {
if (node.IsString())
- return TConstraintNode::TSetType{TConstraintNode::TPathType(1U, ctx.AppendString(node.AsString()))};
+ return TPartOfConstraintBase::TSetType{TPartOfConstraintBase::TPathType(1U, ctx.AppendString(node.AsString()))};
- TConstraintNode::TSetType set;
+ TPartOfConstraintBase::TSetType set;
for (const auto& col : node.AsList())
set.insert_unique(nodeToPath(col));
return set;
@@ -595,7 +595,7 @@ void TYqlRowSpecInfo::ParseConstraintsNode(TExprContext& ctx) {
if (const auto it = constraints.find(TSortedConstraintNode::Name()); constraints.cend() != it) {
TSortedConstraintNode::TContainerType sorted;
for (const auto& pair : it->second.AsList()) {
- TSortedConstraintNode::TSetType set;
+ TPartOfConstraintBase::TSetType set;
for (const auto& path : pair.AsList().front().AsList())
set.insert_unique(nodeToPath(path));
sorted.emplace_back(std::move(set), pair.AsList().back().AsBool());
@@ -606,7 +606,7 @@ void TYqlRowSpecInfo::ParseConstraintsNode(TExprContext& ctx) {
if (const auto it = constraints.find(TUniqueConstraintNode::Name()); constraints.cend() != it) {
TUniqueConstraintNode::TContentType content;
for (const auto& item : it->second.AsList()) {
- TConstraintNode::TSetOfSetsType sets;
+ TPartOfConstraintBase::TSetOfSetsType sets;
for (const auto& part : item.AsList())
sets.insert_unique(nodeToSet(part));
content.insert_unique(std::move(sets));
@@ -617,7 +617,7 @@ void TYqlRowSpecInfo::ParseConstraintsNode(TExprContext& ctx) {
if (const auto it = constraints.find(TDistinctConstraintNode::Name()); constraints.cend() != it) {
TDistinctConstraintNode::TContentType content;
for (const auto& item : it->second.AsList()) {
- TConstraintNode::TSetOfSetsType sets;
+ TPartOfConstraintBase::TSetOfSetsType sets;
for (const auto& part : item.AsList())
sets.insert_unique(nodeToSet(part));
content.insert_unique(std::move(sets));
@@ -1598,7 +1598,7 @@ const TSortedConstraintNode* TYqlRowSpecInfo::MakeSortConstraint(TExprContext& c
TSortedConstraintNode::TContainerType sorted;
for (auto i = 0U; i < SortMembers.size(); ++i) {
const auto column = ctx.AppendString(SortMembers[i]);
- sorted.emplace_back(TSortedConstraintNode::TSetType{TConstraintNode::TPathType{column}}, i >= SortDirections.size() || SortDirections[i]);
+ sorted.emplace_back(TPartOfConstraintBase::TSetType{TPartOfConstraintBase::TPathType{column}}, i >= SortDirections.size() || SortDirections[i]);
}
return ctx.MakeConstraint<TSortedConstraintNode>(std::move(sorted));
}
diff --git a/ydb/library/yql/providers/yt/provider/yql_yt_datasink_constraints.cpp b/ydb/library/yql/providers/yt/provider/yql_yt_datasink_constraints.cpp
index af6ff96473..5481d3700d 100644
--- a/ydb/library/yql/providers/yt/provider/yql_yt_datasink_constraints.cpp
+++ b/ydb/library/yql/providers/yt/provider/yql_yt_datasink_constraints.cpp
@@ -153,9 +153,9 @@ private:
argConstraints = set.GetAllConstraints();
if (singleLambda) {
if (const auto& reduceBy = NYql::GetSettingAsColumnList(op.Settings().Ref(), EYtSettingType::ReduceBy); !reduceBy.empty()) {
- TConstraintNode::TSetOfSetsType sets;
+ TPartOfConstraintBase::TSetOfSetsType sets;
sets.reserve(reduceBy.size());
- std::transform(reduceBy.cbegin(), reduceBy.cend(), std::back_inserter(sets), [&ctx](const TString& column) { return TConstraintNode::TSetType{TConstraintNode::TPathType(1U, ctx.AppendString(column))}; });
+ std::transform(reduceBy.cbegin(), reduceBy.cend(), std::back_inserter(sets), [&ctx](const TString& column) { return TPartOfConstraintBase::TSetType{TPartOfConstraintBase::TPathType(1U, ctx.AppendString(column))}; });
argConstraints.push_back(ctx.MakeConstraint<TChoppedConstraintNode>(std::move(sets)));
}
}
@@ -178,9 +178,9 @@ private:
}
if (const auto& reduceBy = NYql::GetSettingAsColumnList(op.Settings().Ref(), EYtSettingType::ReduceBy); !reduceBy.empty()) {
- TConstraintNode::TSetOfSetsType sets;
+ TPartOfConstraintBase::TSetOfSetsType sets;
sets.reserve(reduceBy.size());
- std::transform(reduceBy.cbegin(), reduceBy.cend(), std::back_inserter(sets), [&ctx](const TString& column) { return TConstraintNode::TSetType{TConstraintNode::TPathType(1U, ctx.AppendString(column))}; });
+ std::transform(reduceBy.cbegin(), reduceBy.cend(), std::back_inserter(sets), [&ctx](const TString& column) { return TPartOfConstraintBase::TSetType{TPartOfConstraintBase::TPathType(1U, ctx.AppendString(column))}; });
argConstraints.push_back(ctx.MakeConstraint<TChoppedConstraintNode>(std::move(sets)));
}
diff --git a/ydb/library/yql/providers/yt/provider/yql_yt_datasource_constraints.cpp b/ydb/library/yql/providers/yt/provider/yql_yt_datasource_constraints.cpp
index c8cb525da2..f6630be193 100644
--- a/ydb/library/yql/providers/yt/provider/yql_yt_datasource_constraints.cpp
+++ b/ydb/library/yql/providers/yt/provider/yql_yt_datasource_constraints.cpp
@@ -94,7 +94,7 @@ public:
TStatus HandlePath(TExprBase input, TExprContext& ctx) {
auto path = input.Cast<TYtPath>();
const auto outItemType = path.Ref().GetTypeAnn()->Cast<TListExprType>()->GetItemType()->Cast<TStructExprType>();
- const auto filter = [outItemType](const TConstraintNode::TPathType& path) { return !path.empty() && outItemType->FindItem(path.front()); };
+ const auto filter = [outItemType](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && outItemType->FindItem(path.front()); };
if (const auto sort = path.Table().Ref().GetConstraint<TSortedConstraintNode>()) {
if (const auto filtered = sort->FilterFields(ctx, filter)) {
diff --git a/ydb/library/yql/providers/yt/provider/yql_yt_join_impl.cpp b/ydb/library/yql/providers/yt/provider/yql_yt_join_impl.cpp
index 9487b35af4..a3f8eda993 100644
--- a/ydb/library/yql/providers/yt/provider/yql_yt_join_impl.cpp
+++ b/ydb/library/yql/providers/yt/provider/yql_yt_join_impl.cpp
@@ -4615,10 +4615,10 @@ TYtJoinNodeOp::TPtr ImportYtEquiJoin(TYtEquiJoin equiJoin, TExprContext& ctx) {
auto leaf = MakeIntrusive<TYtJoinNodeLeaf>(equiJoin.Input().Item(i), TMaybeNode<TCoLambda>(equiJoin.Ref().ChildPtr(joinFixedArgsCount + i)));
leaf->Label = NYql::GetSetting(leaf->Section.Settings().Ref(), EYtSettingType::JoinLabel)->Child(1);
leaf->Index = i;
- TConstraintNode::TPathReduce rename;
+ TPartOfConstraintBase::TPathReduce rename;
if (leaf->Label->IsAtom()) {
leaf->Scope.emplace_back(leaf->Label->Content());
- rename = [&](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ rename = [&](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
auto result = path;
TStringBuilder sb;
sb << leaf->Scope.front() << '.' << result.front();
@@ -4655,9 +4655,8 @@ TYtJoinNodeOp::TPtr ImportYtEquiJoin(TYtEquiJoin equiJoin, TExprContext& ctx) {
}
const auto root = ImportYtEquiJoinRecursive(leaves, nullptr, drops, equiJoin.Joins().Ref(), ctx);
-
if (const auto renames = LoadJoinRenameMap(equiJoin.JoinOptions().Ref()); !renames.empty()) {
- const auto rename = [&renames](const TConstraintNode::TPathType& path) -> std::vector<TConstraintNode::TPathType> {
+ const auto rename = [&renames](const TPartOfConstraintBase::TPathType& path) -> std::vector<TPartOfConstraintBase::TPathType> {
if (path.empty())
return {};
@@ -4667,7 +4666,7 @@ TYtJoinNodeOp::TPtr ImportYtEquiJoin(TYtEquiJoin equiJoin, TExprContext& ctx) {
if (it->second.empty())
return {};
- std::vector<TConstraintNode::TPathType> res(it->second.size());
+ std::vector<TPartOfConstraintBase::TPathType> res(it->second.size());
std::transform(it->second.cbegin(), it->second.cend(), res.begin(), [&path](const std::string_view& newName) {
auto newPath = path;
newPath.front() = newName;
diff --git a/ydb/library/yql/providers/yt/provider/yql_yt_logical_optimize.cpp b/ydb/library/yql/providers/yt/provider/yql_yt_logical_optimize.cpp
index d8936fee93..83c482b49e 100644
--- a/ydb/library/yql/providers/yt/provider/yql_yt_logical_optimize.cpp
+++ b/ydb/library/yql/providers/yt/provider/yql_yt_logical_optimize.cpp
@@ -199,7 +199,7 @@ protected:
if (ctx.IsConstraintEnabled<TSortedConstraintNode>()) {
if (const auto s = path.Table().Ref().GetConstraint<TSortedConstraintNode>()) {
- if (const auto sorted = s->FilterFields(ctx, [outStructType](const TConstraintNode::TPathType& path) { return !path.empty() && outStructType->FindItem(path.front()); }) ) {
+ if (const auto sorted = s->FilterFields(ctx, [outStructType](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && outStructType->FindItem(path.front()); }) ) {
TKeySelectorBuilder builder(map.Mapper().Pos(), ctx, useNativeDescSort, outStructType);
builder.ProcessConstraint(*sorted);
builder.FillRowSpecSort(*mapOut.RowSpec);
diff --git a/ydb/library/yql/providers/yt/provider/yql_yt_physical_finalizing.cpp b/ydb/library/yql/providers/yt/provider/yql_yt_physical_finalizing.cpp
index f0fccd2241..82651debc8 100644
--- a/ydb/library/yql/providers/yt/provider/yql_yt_physical_finalizing.cpp
+++ b/ydb/library/yql/providers/yt/provider/yql_yt_physical_finalizing.cpp
@@ -695,7 +695,7 @@ private:
auto outStructType = ctx.MakeType<TStructExprType>(structItems);
auto distinct = outTable.Ref().GetConstraint<TDistinctConstraintNode>();
if (distinct) {
- distinct = distinct->FilterFields(ctx, [&columns](const TConstraintNode::TPathType& path) { return !path.empty() && columns.contains(path.front()); });
+ distinct = distinct->FilterFields(ctx, [&columns](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && columns.contains(path.front()); });
}
TExprNode::TPtr newOp;
@@ -750,7 +750,7 @@ private:
}
if (sorted = sorted->CutPrefix(prefixLength, ctx)) {
- if (sorted = sorted->FilterFields(ctx, [&columns](const TConstraintNode::TPathType& path) { return !path.empty() && columns.contains(path.front()); })) {
+ if (sorted = sorted->FilterFields(ctx, [&columns](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && columns.contains(path.front()); })) {
TKeySelectorBuilder builder(map.Mapper().Pos(), ctx, useNativeDescSort, outStructType);
builder.ProcessConstraint(*sorted);
builder.FillRowSpecSort(*mapOut.RowSpec);
diff --git a/ydb/library/yql/providers/yt/provider/yql_yt_table.cpp b/ydb/library/yql/providers/yt/provider/yql_yt_table.cpp
index d5372ad804..39a75af90c 100644
--- a/ydb/library/yql/providers/yt/provider/yql_yt_table.cpp
+++ b/ydb/library/yql/providers/yt/provider/yql_yt_table.cpp
@@ -940,11 +940,11 @@ TYtOutTableInfo& TYtOutTableInfo::SetUnique(const TDistinctConstraintNode* disti
auto content = simple->GetContent();
if (1U < content.size()) {
std::unordered_set<std::string_view> sorted(RowSpec->SortMembers.cbegin(), RowSpec->SortMembers.cend());
- if (const auto filtered = simple->FilterFields(ctx, [&sorted](const TConstraintNode::TPathType& path) { return 1U == path.size() && sorted.contains(path.front()); }))
+ if (const auto filtered = simple->FilterFields(ctx, [&sorted](const TPartOfConstraintBase::TPathType& path) { return 1U == path.size() && sorted.contains(path.front()); }))
content = filtered->GetContent();
}
std::vector<std::string_view> uniques(content.front().size());
- std::transform(content.front().cbegin(), content.front().cend(), uniques.begin(), [&](const TConstraintNode::TSetType& set) { return set.front().front(); });
+ std::transform(content.front().cbegin(), content.front().cend(), uniques.begin(), [&](const TPartOfConstraintBase::TSetType& set) { return set.front().front(); });
Settings = TExprBase(NYql::AddSetting(Settings.Ref(), EYtSettingType::UniqueBy, ToAtomList(uniques, pos, ctx), ctx));
}
}