blob: 825e71b0b21ff9a08a0205d709a07aae58101fa8 (
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
|
#include "mkql_source.h"
#include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>
#include <yql/essentials/minikql/computation/mkql_computation_node_codegen.h> // Y_IGNORE
#include <yql/essentials/minikql/computation/mkql_computation_node_holders_codegen.h>
#include <yql/essentials/minikql/mkql_node_cast.h>
namespace NKikimr {
namespace NMiniKQL {
namespace {
class TSourceOfWrapper : public TMutableComputationNode<TSourceOfWrapper> {
typedef TMutableComputationNode<TSourceOfWrapper> TBaseComputation;
private:
class TValue : public TComputationValue<TValue> {
public:
TValue(TMemoryUsageInfo* memInfo)
: TComputationValue<TValue>(memInfo)
{}
private:
ui32 GetTraverseCount() const override { return 0U; }
NUdf::EFetchStatus Fetch(NUdf::TUnboxedValue& result) override {
result = NUdf::TUnboxedValuePod();
return NUdf::EFetchStatus::Ok;
}
};
public:
TSourceOfWrapper(TComputationMutables& mutables)
: TBaseComputation(mutables)
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
return ctx.HolderFactory.Create<TValue>();
}
private:
void RegisterDependencies() const final {}
};
class TSourceWrapper : public TStatelessWideFlowCodegeneratorNode<TSourceWrapper> {
using TBaseComputation = TStatelessWideFlowCodegeneratorNode<TSourceWrapper>;
public:
TSourceWrapper()
: TStatelessWideFlowCodegeneratorNode<TSourceWrapper>(nullptr)
{}
EFetchResult DoCalculate(TComputationContext&, NUdf::TUnboxedValue*const*) const {
return EFetchResult::One;
}
#ifndef MKQL_DISABLE_CODEGEN
TGenerateResult DoGenGetValues(const TCodegenContext& ctx, BasicBlock*&) const {
return {ConstantInt::get(Type::getInt32Ty(ctx.Codegen.GetContext()), static_cast<i32>(EFetchResult::One)), {}};
}
#endif
private:
void RegisterDependencies() const final {}
};
}
IComputationNode* WrapSourceOf(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
MKQL_ENSURE(!callable.GetInputsCount(), "Expected no args.");
const auto type = callable.GetType()->GetReturnType();
if (type->IsFlow()) {
return ctx.NodeFactory.CreateImmutableNode(NUdf::TUnboxedValuePod());
} else if (type->IsStream()) {
return new TSourceOfWrapper(ctx.Mutables);
}
THROW yexception() << "Expected flow or stream.";
}
IComputationNode* WrapSource(TCallable& callable, const TComputationNodeFactoryContext&) {
MKQL_ENSURE(!callable.GetInputsCount(), "Expected no args.");
MKQL_ENSURE(!GetWideComponentsCount(AS_TYPE(TFlowType, callable.GetType()->GetReturnType())), "Expected zero width of output flow.");
return new TSourceWrapper;
}
}
}
|