aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/comp_nodes/mkql_squeeze_state.h
blob: 002fd1dc605a2bafbcdca38fb92943b9acaa9589 (plain) (blame)
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
76
77
78
79
80
81
82
83
#pragma once

#include <yql/essentials/minikql/computation/mkql_computation_node_pack.h>
#include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>

namespace NKikimr {
namespace NMiniKQL {

enum class ESqueezeState : ui8 {
    Idle = 0,
    Work,
    Finished,
    NeedInit
};

struct TSqueezeState {
    TSqueezeState(
        IComputationExternalNode* item,
        IComputationExternalNode* state,
        IComputationNode* outSwitch,
        IComputationNode* initState,
        IComputationNode* newState,
        IComputationExternalNode* inSave,
        IComputationNode* outSave,
        IComputationExternalNode* inLoad,
        IComputationNode* outLoad,
        const TType* stateType
    );

    TSqueezeState(const TSqueezeState& state);

    NUdf::TUnboxedValue Save(TComputationContext& ctx) const;

    void Load(TComputationContext& ctx, const NUdf::TStringRef& state);

    ESqueezeState Stage = ESqueezeState::Idle;

    IComputationExternalNode* const Item;
    IComputationExternalNode* const State;
    IComputationNode* const Switch;
    IComputationNode* const InitState;
    IComputationNode* const UpdateState;

    IComputationExternalNode* const InSave;
    IComputationNode* const OutSave;
    IComputationExternalNode* const InLoad;
    IComputationNode* const OutLoad;

private:
    const TValuePacker& GetPacker() const;

    const TType* StateType;

    mutable THolder<TValuePacker> Packer;
};

class TSqueezeCodegenValue : public TComputationValue<TSqueezeCodegenValue> {
public:
    using TBase = TComputationValue<TSqueezeCodegenValue>;

    using TFetchPtr = NUdf::EFetchStatus (*)(TComputationContext*, NUdf::TUnboxedValuePod, NUdf::TUnboxedValuePod&, ESqueezeState&);

    TSqueezeCodegenValue(TMemoryUsageInfo* memInfo, const TSqueezeState& state, TFetchPtr fetch, TComputationContext& ctx, NUdf::TUnboxedValue&& stream);

private:
    ui32 GetTraverseCount() const final;

    NUdf::TUnboxedValue GetTraverseItem(ui32) const final;

    NUdf::TUnboxedValue Save() const final;

    void Load(const NUdf::TStringRef& state) final;

    NUdf::EFetchStatus Fetch(NUdf::TUnboxedValue& result) final;

    const TFetchPtr FetchFunc;
    const NUdf::TUnboxedValue Stream;
    TComputationContext& Ctx;
    TSqueezeState State;
};

}
}