Skip to content

Commit d732450

Browse files
committed
make updates backward-compatible
1 parent 55445ed commit d732450

File tree

10 files changed

+73
-78
lines changed

10 files changed

+73
-78
lines changed

ydb/library/yql/core/sql_types/match_recognize.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88

99
namespace NYql::NMatchRecognize {
1010

11+
enum class EAfterMatchSkipTo {
12+
NextRow,
13+
PastLastRow,
14+
ToFirst,
15+
ToLast,
16+
To
17+
};
18+
19+
struct TAfterMatchSkipTo {
20+
EAfterMatchSkipTo To;
21+
TString Var;
22+
23+
[[nodiscard]] bool operator==(const TAfterMatchSkipTo&) const noexcept = default;
24+
};
25+
1126
constexpr size_t MaxPatternNesting = 20; //Limit recursion for patterns
1227
constexpr size_t MaxPermutedItems = 6;
1328

ydb/library/yql/minikql/comp_nodes/mkql_match_recognize.cpp

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct TMatchRecognizeProcessorParameters {
3939
TMeasureInputColumnOrder MeasureInputColumnOrder;
4040
TComputationNodePtrVector Measures;
4141
TOutputColumnOrder OutputColumnOrder;
42+
TAfterMatchSkipTo SkipTo;
4243
};
4344

4445
class TStreamingMatchRecognize {
@@ -49,14 +50,12 @@ class TStreamingMatchRecognize {
4950
NUdf::TUnboxedValue&& partitionKey,
5051
const TMatchRecognizeProcessorParameters& parameters,
5152
TNfaTransitionGraph::TPtr nfaTransitions,
52-
const TContainerCacheOnContext& cache,
53-
bool afterMatchSkipPastLastRow
53+
const TContainerCacheOnContext& cache
5454
)
5555
: PartitionKey(std::move(partitionKey))
5656
, Parameters(parameters)
5757
, Nfa(nfaTransitions, parameters.MatchedVarsArg, parameters.Defines)
5858
, Cache(cache)
59-
, AfterMatchSkipPastLastRow(afterMatchSkipPastLastRow)
6059
{
6160
}
6261

@@ -96,7 +95,7 @@ class TStreamingMatchRecognize {
9695
break;
9796
}
9897
}
99-
if (AfterMatchSkipPastLastRow) {
98+
if (EAfterMatchSkipTo::PastLastRow == Parameters.SkipTo.To) {
10099
Nfa.Clear();
101100
}
102101
return result;
@@ -111,15 +110,13 @@ class TStreamingMatchRecognize {
111110
Rows.Save(serializer);
112111
Nfa.Save(serializer);
113112
serializer.Write(MatchNumber);
114-
serializer.Write(AfterMatchSkipPastLastRow);
115113
}
116114

117115
void Load(TMrInputSerializer& serializer) {
118116
// PartitionKey passed in contructor.
119117
Rows.Load(serializer);
120118
Nfa.Load(serializer);
121119
MatchNumber = serializer.Read<ui64>();
122-
AfterMatchSkipPastLastRow = serializer.Read<bool>();
123120
}
124121

125122
private:
@@ -129,7 +126,6 @@ class TStreamingMatchRecognize {
129126
TNfa Nfa;
130127
const TContainerCacheOnContext& Cache;
131128
ui64 MatchNumber = 0;
132-
bool AfterMatchSkipPastLastRow;
133129
};
134130

135131
class TStateForNonInterleavedPartitions
@@ -145,8 +141,7 @@ class TStateForNonInterleavedPartitions
145141
const TContainerCacheOnContext& cache,
146142
TComputationContext &ctx,
147143
TType* rowType,
148-
const TMutableObjectOverBoxedValue<TValuePackerBoxed>& rowPacker,
149-
bool afterMatchSkipPastLastRow
144+
const TMutableObjectOverBoxedValue<TValuePackerBoxed>& rowPacker
150145
)
151146
: TComputationValue<TStateForNonInterleavedPartitions>(memInfo)
152147
, InputRowArg(inputRowArg)
@@ -158,7 +153,6 @@ class TStateForNonInterleavedPartitions
158153
, Terminating(false)
159154
, SerializerContext(ctx, rowType, rowPacker)
160155
, Ctx(ctx)
161-
, AfterMatchSkipPastLastRow(afterMatchSkipPastLastRow)
162156
{}
163157

164158
NUdf::TUnboxedValue Save() const override {
@@ -194,8 +188,7 @@ class TStateForNonInterleavedPartitions
194188
std::move(key),
195189
Parameters,
196190
RowPatternConfiguration,
197-
Cache,
198-
AfterMatchSkipPastLastRow
191+
Cache
199192
));
200193
PartitionHandler->Load(in);
201194
}
@@ -261,8 +254,7 @@ class TStateForNonInterleavedPartitions
261254
std::move(partitionKey),
262255
Parameters,
263256
RowPatternConfiguration,
264-
Cache,
265-
AfterMatchSkipPastLastRow));
257+
Cache));
266258
PartitionHandler->ProcessInputRow(std::move(temp), ctx);
267259
}
268260
if (Terminating) {
@@ -283,7 +275,6 @@ class TStateForNonInterleavedPartitions
283275
bool Terminating;
284276
TSerializerContext SerializerContext;
285277
TComputationContext& Ctx;
286-
bool AfterMatchSkipPastLastRow;
287278
};
288279

289280
class TStateForInterleavedPartitions
@@ -301,8 +292,7 @@ class TStateForInterleavedPartitions
301292
const TContainerCacheOnContext& cache,
302293
TComputationContext &ctx,
303294
TType* rowType,
304-
const TMutableObjectOverBoxedValue<TValuePackerBoxed>& rowPacker,
305-
bool afterMatchSkipPastLastRow
295+
const TMutableObjectOverBoxedValue<TValuePackerBoxed>& rowPacker
306296
)
307297
: TComputationValue<TStateForInterleavedPartitions>(memInfo)
308298
, InputRowArg(inputRowArg)
@@ -313,7 +303,6 @@ class TStateForInterleavedPartitions
313303
, Cache(cache)
314304
, SerializerContext(ctx, rowType, rowPacker)
315305
, Ctx(ctx)
316-
, AfterMatchSkipPastLastRow(afterMatchSkipPastLastRow)
317306
{}
318307

319308
NUdf::TUnboxedValue Save() const override {
@@ -350,8 +339,7 @@ class TStateForInterleavedPartitions
350339
std::move(key),
351340
Parameters,
352341
NfaTransitionGraph,
353-
Cache,
354-
AfterMatchSkipPastLastRow));
342+
Cache));
355343
pair.first->second->Load(in);
356344
}
357345

@@ -418,8 +406,7 @@ class TStateForInterleavedPartitions
418406
std::move(partitionKey),
419407
Parameters,
420408
NfaTransitionGraph,
421-
Cache,
422-
AfterMatchSkipPastLastRow
409+
Cache
423410
));
424411
}
425412
}
@@ -438,7 +425,6 @@ class TStateForInterleavedPartitions
438425
const TContainerCacheOnContext& Cache;
439426
TSerializerContext SerializerContext;
440427
TComputationContext& Ctx;
441-
bool AfterMatchSkipPastLastRow;
442428
};
443429

444430
template<class State>
@@ -450,8 +436,7 @@ class TMatchRecognizeWrapper : public TStatefulFlowComputationNode<TMatchRecogni
450436
IComputationNode *partitionKey,
451437
TType* partitionKeyType,
452438
const TMatchRecognizeProcessorParameters& parameters,
453-
TType* rowType,
454-
bool afterMatchSkipPastLastRow
439+
TType* rowType
455440
)
456441
:TBaseComputation(mutables, inputFlow, kind, EValueRepresentation::Embedded)
457442
, InputFlow(inputFlow)
@@ -462,7 +447,6 @@ class TMatchRecognizeWrapper : public TStatefulFlowComputationNode<TMatchRecogni
462447
, Cache(mutables)
463448
, RowType(rowType)
464449
, RowPacker(mutables)
465-
, AfterMatchSkipPastLastRow(afterMatchSkipPastLastRow)
466450
{}
467451

468452
NUdf::TUnboxedValue DoCalculate(NUdf::TUnboxedValue &stateValue, TComputationContext &ctx) const {
@@ -475,8 +459,7 @@ class TMatchRecognizeWrapper : public TStatefulFlowComputationNode<TMatchRecogni
475459
Cache,
476460
ctx,
477461
RowType,
478-
RowPacker,
479-
AfterMatchSkipPastLastRow
462+
RowPacker
480463
);
481464
} else if (stateValue.HasValue()) {
482465
MKQL_ENSURE(stateValue.IsBoxed(), "Expected boxed value");
@@ -491,8 +474,7 @@ class TMatchRecognizeWrapper : public TStatefulFlowComputationNode<TMatchRecogni
491474
Cache,
492475
ctx,
493476
RowType,
494-
RowPacker,
495-
AfterMatchSkipPastLastRow
477+
RowPacker
496478
);
497479
state.Load2(stateValue);
498480
stateValue = state;
@@ -541,7 +523,6 @@ class TMatchRecognizeWrapper : public TStatefulFlowComputationNode<TMatchRecogni
541523
const TContainerCacheOnContext Cache;
542524
TType* const RowType;
543525
TMutableObjectOverBoxedValue<TValuePackerBoxed> RowPacker;
544-
bool AfterMatchSkipPastLastRow;
545526
};
546527

547528
TOutputColumnOrder GetOutputColumnOrder(TRuntimeNode partitionKyeColumnsIndexes, TRuntimeNode measureColumnsIndexes) {
@@ -669,7 +650,11 @@ IComputationNode* WrapMatchRecognizeCore(TCallable& callable, const TComputation
669650
defines.push_back(callable.GetInput(inputIndex++));
670651
}
671652
const auto& streamingMode = callable.GetInput(inputIndex++);
672-
const auto& afterMatchSkipPastLastRow = callable.GetInput(inputIndex++);
653+
NYql::NMatchRecognize::TAfterMatchSkipTo skipTo = {NYql::NMatchRecognize::EAfterMatchSkipTo::NextRow, ""};
654+
if (callable.GetInputsCount() - inputIndex >= 2) {
655+
skipTo.To = static_cast<EAfterMatchSkipTo>(AS_VALUE(TDataLiteral, callable.GetInput(inputIndex++))->AsValue().Get<i32>());
656+
skipTo.Var = AS_VALUE(TDataLiteral, callable.GetInput(inputIndex++))->AsValue().AsStringRef();
657+
}
673658
MKQL_ENSURE(callable.GetInputsCount() == inputIndex, "Wrong input count");
674659

675660
const auto& [vars, varsLookup] = ConvertListOfStrings(varNames);
@@ -690,6 +675,7 @@ IComputationNode* WrapMatchRecognizeCore(TCallable& callable, const TComputation
690675
)
691676
, ConvertVectorOfCallables(measures, ctx)
692677
, GetOutputColumnOrder(partitionColumnIndexes, measureColumnIndexes)
678+
, skipTo
693679
};
694680
if (AS_VALUE(TDataLiteral, streamingMode)->AsValue().Get<bool>()) {
695681
return new TMatchRecognizeWrapper<TStateForInterleavedPartitions>(ctx.Mutables
@@ -700,7 +686,6 @@ IComputationNode* WrapMatchRecognizeCore(TCallable& callable, const TComputation
700686
, partitionKeySelector.GetStaticType()
701687
, std::move(parameters)
702688
, rowType
703-
, AS_VALUE(TDataLiteral, afterMatchSkipPastLastRow)->AsValue().Get<bool>()
704689
);
705690
} else {
706691
return new TMatchRecognizeWrapper<TStateForNonInterleavedPartitions>(ctx.Mutables
@@ -711,7 +696,6 @@ IComputationNode* WrapMatchRecognizeCore(TCallable& callable, const TComputation
711696
, partitionKeySelector.GetStaticType()
712697
, std::move(parameters)
713698
, rowType
714-
, AS_VALUE(TDataLiteral, afterMatchSkipPastLastRow)->AsValue().Get<bool>()
715699
);
716700
}
717701
}

ydb/library/yql/minikql/mkql_program_builder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5974,7 +5974,7 @@ TRuntimeNode TProgramBuilder::MatchRecognizeCore(
59745974
const NYql::NMatchRecognize::TRowPattern& pattern,
59755975
const TArrayRef<std::pair<TStringBuf, TTernaryLambda>>& getDefines,
59765976
bool streamingMode,
5977-
bool afterMatchSkipPastLastRow
5977+
NYql::NMatchRecognize::TAfterMatchSkipTo skipTo
59785978
) {
59795979
MKQL_ENSURE(RuntimeVersion >= 42, "MatchRecognize is not supported in runtime version " << RuntimeVersion);
59805980

@@ -6128,7 +6128,11 @@ TRuntimeNode TProgramBuilder::MatchRecognizeCore(
61286128
callableBuilder.Add(d);
61296129
}
61306130
callableBuilder.Add(NewDataLiteral(streamingMode));
6131-
callableBuilder.Add(NewDataLiteral(afterMatchSkipPastLastRow));
6131+
if (skipTo != NYql::NMatchRecognize::TAfterMatchSkipTo{NYql::NMatchRecognize::EAfterMatchSkipTo::NextRow, ""}) {
6132+
MKQL_ENSURE(RuntimeVersion >= 52U, "Too old runtime version");
6133+
callableBuilder.Add(NewDataLiteral(static_cast<i32>(skipTo.To)));
6134+
callableBuilder.Add(NewDataLiteral<NUdf::EDataSlot::String>(skipTo.Var));
6135+
}
61326136
return TRuntimeNode(callableBuilder.Build(), false);
61336137
}
61346138

ydb/library/yql/minikql/mkql_program_builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ class TProgramBuilder : public TTypeBuilder {
714714
const NYql::NMatchRecognize::TRowPattern& pattern,
715715
const TArrayRef<std::pair<TStringBuf, TTernaryLambda>>& getDefines,
716716
bool streamingMode,
717-
bool afterMatchSkipPastLastRow = false
717+
NYql::NMatchRecognize::TAfterMatchSkipTo skipTo = {NYql::NMatchRecognize::EAfterMatchSkipTo::NextRow, ""}
718718
);
719719

720720
TRuntimeNode TimeOrderRecover(

ydb/library/yql/minikql/mkql_runtime_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace NMiniKQL {
2424
// 1. Bump this version every time incompatible runtime nodes are introduced.
2525
// 2. Make sure you provide runtime node generation for previous runtime versions.
2626
#ifndef MKQL_RUNTIME_VERSION
27-
#define MKQL_RUNTIME_VERSION 51U
27+
#define MKQL_RUNTIME_VERSION 52U
2828
#endif
2929

3030
// History:

ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <ydb/library/yql/parser/pg_catalog/catalog.h>
2020

2121
#include <util/stream/null.h>
22+
#include <util/string/cast.h>
2223

2324
#include <array>
2425

@@ -878,7 +879,7 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
878879

879880
//explore params
880881
const auto& measures = params->ChildRef(0);
881-
const auto& skip = params->ChildRef(2);
882+
const auto& skipTo = params->ChildRef(2);
882883
const auto& pattern = params->ChildRef(3);
883884
const auto& defines = params->ChildRef(4);
884885

@@ -921,9 +922,11 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
921922
};
922923
}
923924

924-
auto to = skip->Child(0)->Content();
925-
MKQL_ENSURE(to.SkipPrefix("AfterMatchSkip_"), R"(MATCH_RECOGNIZE: <row pattern skip to> should start with "AfterMatchSkip_")");
926-
const auto afterMatchSkipPastLastRow = to == "PastLastRow";
925+
auto stringTo = skipTo->Child(0)->Content();
926+
auto var = skipTo->Child(1)->Content();
927+
MKQL_ENSURE(stringTo.SkipPrefix("AfterMatchSkip_"), R"(MATCH_RECOGNIZE: <row pattern skip to> should start with "AfterMatchSkip_")");
928+
NYql::NMatchRecognize::EAfterMatchSkipTo to;
929+
MKQL_ENSURE(TryFromString<NYql::NMatchRecognize::EAfterMatchSkipTo>(stringTo, to), "MATCH_RECOGNIZE: <row pattern skip to> cannot conver to enum");
927930

928931
const auto streamingMode = FromString<bool>(settings->Child(0)->Child(1)->Content());
929932

@@ -935,7 +938,7 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
935938
NYql::NMatchRecognize::ConvertPattern(pattern, ctx.ExprCtx),
936939
getDefines,
937940
streamingMode,
938-
afterMatchSkipPastLastRow
941+
NYql::NMatchRecognize::TAfterMatchSkipTo{to, TString{var}}
939942
);
940943
});
941944

ydb/library/yql/sql/v1/match_recognize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TMatchRecognize: public TAstListNode {
2222
std::pair<TPosition, TVector<TSortSpecificationPtr>>&& sortSpecs,
2323
std::pair<TPosition, TVector<TNamedFunction>>&& measures,
2424
std::pair<TPosition, ERowsPerMatch>&& rowsPerMatch,
25-
std::pair<TPosition, TAfterMatchSkipTo>&& skipTo,
25+
std::pair<TPosition, NYql::NMatchRecognize::TAfterMatchSkipTo>&& skipTo,
2626
std::pair<TPosition, NYql::NMatchRecognize::TRowPattern>&& pattern,
2727
std::pair<TPosition, TNodePtr>&& subset,
2828
std::pair<TPosition, TVector<TNamedFunction>>&& definitions
@@ -57,7 +57,7 @@ class TMatchRecognize: public TAstListNode {
5757
std::pair<TPosition, TVector<TSortSpecificationPtr>>&& sortSpecs,
5858
std::pair<TPosition, TVector<TNamedFunction>>&& measures,
5959
std::pair<TPosition, ERowsPerMatch>&& rowsPerMatch,
60-
std::pair<TPosition, TAfterMatchSkipTo>&& skipTo,
60+
std::pair<TPosition, NYql::NMatchRecognize::TAfterMatchSkipTo>&& skipTo,
6161
std::pair<TPosition, NYql::NMatchRecognize::TRowPattern>&& pattern,
6262
std::pair<TPosition, TNodePtr>&& subset,
6363
std::pair<TPosition, TVector<TNamedFunction>>&& definitions

ydb/library/yql/sql/v1/match_recognize.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@ enum class ERowsPerMatch {
1515
AllRows
1616
};
1717

18-
enum class EAfterMatchSkipTo {
19-
NextRow,
20-
PastLastRow,
21-
ToFirst,
22-
ToLast,
23-
To
24-
};
25-
26-
struct TAfterMatchSkipTo {
27-
TAfterMatchSkipTo(EAfterMatchSkipTo to, const TStringBuf var = TStringBuf())
28-
: To(to)
29-
, Var(var)
30-
{}
31-
EAfterMatchSkipTo To;
32-
TString Var;
33-
};
34-
3518
class TMatchRecognizeBuilder: public TSimpleRefCount<TMatchRecognizeBuilder> {
3619
public:
3720
TMatchRecognizeBuilder(
@@ -40,7 +23,7 @@ class TMatchRecognizeBuilder: public TSimpleRefCount<TMatchRecognizeBuilder> {
4023
std::pair<TPosition, TVector<TSortSpecificationPtr>>&& sortSpecs,
4124
std::pair<TPosition, TVector<TNamedFunction>>&& measures,
4225
std::pair<TPosition, ERowsPerMatch>&& rowsPerMatch,
43-
std::pair<TPosition, TAfterMatchSkipTo>&& skipTo,
26+
std::pair<TPosition, NYql::NMatchRecognize::TAfterMatchSkipTo>&& skipTo,
4427
std::pair<TPosition, NYql::NMatchRecognize::TRowPattern>&& pattern,
4528
std::pair<TPosition, TNodePtr>&& subset,
4629
std::pair<TPosition, TVector<TNamedFunction>>&& definitions
@@ -63,7 +46,7 @@ class TMatchRecognizeBuilder: public TSimpleRefCount<TMatchRecognizeBuilder> {
6346
std::pair<TPosition, TVector<TSortSpecificationPtr>> SortSpecs;
6447
std::pair<TPosition, TVector<TNamedFunction>> Measures;
6548
std::pair<TPosition, ERowsPerMatch> RowsPerMatch;
66-
std::pair<TPosition, TAfterMatchSkipTo> SkipTo;
49+
std::pair<TPosition, NYql::NMatchRecognize::TAfterMatchSkipTo> SkipTo;
6750
std::pair<TPosition, NYql::NMatchRecognize::TRowPattern> Pattern;
6851
std::pair<TPosition, TNodePtr> Subset;
6952
std::pair<TPosition, TVector<TNamedFunction>> Definitions;

0 commit comments

Comments
 (0)