1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#pragma once
#include "mkql_match_recognize_nfa.h"
#include <yql/essentials/core/sql_types/match_recognize.h>
#include <yql/essentials/minikql/computation/mkql_computation_node.h>
#include <yql/essentials/minikql/computation/mkql_computation_node_holders_codegen.h>
#include <yql/essentials/minikql/mkql_alloc.h>
#include <yql/essentials/public/udf/udf_value.h>
namespace NKikimr::NMiniKQL::NMatchRecognize {
struct TOutputColumnEntry {
size_t Index;
NYql::NMatchRecognize::EOutputColumnSource SourceType;
};
using TOutputColumnOrder = std::vector<TOutputColumnEntry, TMKQLAllocator<TOutputColumnEntry>>;
class IRowsFormatter {
public:
struct TState {
std::unique_ptr<TContainerCacheOnContext> Cache;
TOutputColumnOrder OutputColumnOrder;
TComputationNodePtrVector Measures;
NYql::NMatchRecognize::ERowsPerMatch RowsPerMatch;
TState(
const TComputationNodeFactoryContext& ctx,
TOutputColumnOrder outputColumnOrder,
TComputationNodePtrVector measures,
NYql::NMatchRecognize::ERowsPerMatch rowsPerMatch)
: Cache(std::make_unique<TContainerCacheOnContext>(ctx.Mutables))
, OutputColumnOrder(std::move(outputColumnOrder))
, Measures(std::move(measures))
, RowsPerMatch(rowsPerMatch)
{}
};
explicit IRowsFormatter(const TState& state);
virtual ~IRowsFormatter() = default;
virtual NUdf::TUnboxedValue GetFirstMatchRow(
TComputationContext& ctx,
const TSparseList& rows,
const NUdf::TUnboxedValue& partitionKey,
const TNfaTransitionGraph& graph,
const TNfa::TMatch& match) = 0;
virtual NUdf::TUnboxedValue GetOtherMatchRow(
TComputationContext& ctx,
const TSparseList& rows,
const NUdf::TUnboxedValue& partitionKey,
const TNfaTransitionGraph& graph) = 0;
virtual void Load(TMrInputSerializer& serializer) = 0;
virtual void Save(TMrOutputSerializer& serializer) const = 0;
static TOutputColumnOrder GetOutputColumnOrder(TRuntimeNode outputColumnOrder);
static std::unique_ptr<IRowsFormatter> Create(const TState& state);
protected:
NUdf::TUnboxedValue DoGetMatchRow(TComputationContext& ctx, const TSparseList& rows, const NUdf::TUnboxedValue& partitionKey, const TNfaTransitionGraph& graph);
inline void Clear() {
Match_ = {};
CurrentRowIndex_ = Max();
}
const TState& State_;
TNfa::TMatch Match_ {};
size_t CurrentRowIndex_ = Max();
};
} // namespace NKikimr::NMiniKQL::NMatchRecognize
|