diff options
author | zverevgeny <zverevgeny@ydb.tech> | 2023-10-18 10:07:17 +0300 |
---|---|---|
committer | zverevgeny <zverevgeny@ydb.tech> | 2023-10-18 10:29:44 +0300 |
commit | 6079544160d0de7872249550ef517f02b8e942c7 (patch) | |
tree | 9b59fae68819fcd89853984f128a9abdbac4f269 | |
parent | b1a190ceae154a9b93b7101534ea95b8c5a4aef6 (diff) | |
download | ydb-6079544160d0de7872249550ef517f02b8e942c7.tar.gz |
YQL-16856 introduce TVoidTransition to remove errorneous defaulted transitions
-rw-r--r-- | ydb/library/yql/minikql/comp_nodes/mkql_match_recognize_nfa.h | 18 | ||||
-rw-r--r-- | ydb/library/yql/minikql/comp_nodes/ut/mkql_match_recognize_nfa_ut.cpp | 12 |
2 files changed, 22 insertions, 8 deletions
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_match_recognize_nfa.h b/ydb/library/yql/minikql/comp_nodes/mkql_match_recognize_nfa.h index a8cb7a3209..7a7b713897 100644 --- a/ydb/library/yql/minikql/comp_nodes/mkql_match_recognize_nfa.h +++ b/ydb/library/yql/minikql/comp_nodes/mkql_match_recognize_nfa.h @@ -11,12 +11,14 @@ namespace NKikimr::NMiniKQL::NMatchRecognize { using namespace NYql::NMatchRecognize; +struct TVoidTransition{}; using TEpsilonTransition = size_t; //to using TEpsilonTransitions = std::vector<TEpsilonTransition>; using TMatchedVarTransition = std::pair<ui32, size_t>; //{varIndex, to} using TQuantityEnterTransition = size_t; //to using TQuantityExitTransition = std::pair<std::pair<ui64, ui64>, std::pair<size_t, size_t>>; //{{min, max}, {foFindMore, toMatched}} using TNfaTransition = std::variant< + TVoidTransition, TMatchedVarTransition, TEpsilonTransitions, TQuantityEnterTransition, @@ -141,17 +143,17 @@ public: std::set<TState> newStates; std::set<TState> deletedStates; for (const auto& s: ActiveStates) { - const auto& t = TransitionGraph->Transitions[s.Index]; - if (t.index() == 0) { //Here we handle only transitions of TMatchedVarTransition type, all other transtitions are handled in MakeEpsilonTransitions + //Here we handle only transitions of TMatchedVarTransition type, + //all other transitions are handled in MakeEpsilonTransitions + if (const auto* matchedVarTransition = std::get_if<TMatchedVarTransition>(&TransitionGraph->Transitions[s.Index])) { MatchedRangesArg->SetValue(ctx, ctx.HolderFactory.Create<TMatchedVarsValue<TRange>>(ctx.HolderFactory, s.Vars)); - const auto& matchedVarTransition = std::get<0>(t); - const auto varIndex = matchedVarTransition.first; + const auto varIndex = matchedVarTransition->first; const auto& v = Defines[varIndex]->GetValue(ctx); if (v && v.Get<bool>()) { auto vars = s.Vars; //TODO get rid of this copy auto& matchedVar = vars[varIndex]; Extend(matchedVar, currentRowLock); - newStates.emplace(matchedVarTransition.second, std::move(vars), std::stack<ui64>(s.Quantifiers)); + newStates.emplace(matchedVarTransition->second, std::move(vars), std::stack<ui64>(s.Quantifiers)); } deletedStates.insert(s); } @@ -190,7 +192,11 @@ private: TTransitionVisitor(const TState& state, TStateSet& newStates, TStateSet& deletedStates) : State(state) , NewStates(newStates) - , DeletedStates(deletedStates) {} + , DeletedStates(deletedStates) + {} + void operator()(const TVoidTransition&) { + //Do nothing for void + } void operator()(const TMatchedVarTransition& var) { //Transitions of TMatchedVarTransition type are handled in ProcessRow method Y_UNUSED(var); diff --git a/ydb/library/yql/minikql/comp_nodes/ut/mkql_match_recognize_nfa_ut.cpp b/ydb/library/yql/minikql/comp_nodes/ut/mkql_match_recognize_nfa_ut.cpp index 46ba1a68f2..f9b96bc88c 100644 --- a/ydb/library/yql/minikql/comp_nodes/ut/mkql_match_recognize_nfa_ut.cpp +++ b/ydb/library/yql/minikql/comp_nodes/ut/mkql_match_recognize_nfa_ut.cpp @@ -95,10 +95,18 @@ struct TNfaSetup { } //namespace Y_UNIT_TEST_SUITE(MatchRecognizeNfa) { + + Y_UNIT_TEST(OutputStateHasNoOutputEdges) { + const TRowPattern pattern{{TRowPatternFactor{"A", 1, 1, false, false}}}; + const auto transitionGraph = TNfaTransitionGraphBuilder::Create(pattern, {{"A", 0}}); + const auto& output = transitionGraph->Transitions.at(transitionGraph->Output); + UNIT_ASSERT(std::get_if<TVoidTransition>(&output)); + } + //Tests for NFA-based engine for MATCH_RECOGNIZE //In the full implementation pattern variables are calculated as lambda predicates on input partition - //For the sake of simplificationa in these tests predicates are replaced with bool literal values, - //that can be set explicitly in the tests body. So, the values of input rows are irrelevat and not used. + //For the sake of simplification, in these tests predicates are replaced with bool literal values, + //that can be set explicitly in the tests body. So, the values of input rows are irrelevant and not used. TMemoryUsageInfo memUsage("MatchedVars"); Y_UNIT_TEST(SingleVarAcceptNothing) { TScopedAlloc alloc(__LOCATION__); |