summaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/comp_nodes/ut/mkql_linear_ut.cpp
blob: ecd7219977c894116488bf53dfe5fbd0a44befd1 (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
#include "mkql_computation_node_ut.h"

namespace NKikimr {
namespace NMiniKQL {

Y_UNIT_TEST_SUITE(TMiniKQLLinearTest) {
    Y_UNIT_TEST_LLVM(TestDynamicConvert) {
        TSetup<LLVM> setup;
        TProgramBuilder& pb = *setup.PgmBuilder;
        const auto dataType = pb.NewDataType(NUdf::TDataType<ui32>::Id);
        const auto arg = pb.Arg(pb.NewLinearType(dataType, false));
        const auto pgmReturn = pb.FromDynamicLinear(pb.ToDynamicLinear(arg), "foo.sql", 5, 6);
        const auto graph = setup.BuildGraph(pgmReturn, {arg.GetNode()});
        auto& ctx = graph->GetContext();
        graph->GetEntryPoint(0, true)->SetValue(ctx, NUdf::TUnboxedValuePod(1));
        UNIT_ASSERT_VALUES_EQUAL(graph->GetValue().template Get<ui32>(), 1);
    }

    Y_UNIT_TEST_LLVM(TestDynamicConvertTwice) {
        TSetup<LLVM> setup;
        TProgramBuilder& pb = *setup.PgmBuilder;
        const auto dataType = pb.NewDataType(NUdf::TDataType<ui32>::Id);
        const auto arg = pb.Arg(pb.NewLinearType(dataType, false));
        const auto linear = pb.ToDynamicLinear(arg);
        const auto use1 = pb.FromDynamicLinear(linear, "foo.sql", 5, 6);
        const auto use2 = pb.FromDynamicLinear(linear, "foo.sql", 8, 9);
        const auto pgmReturn = pb.NewTuple({use1, use2});
        const auto graph = setup.BuildGraph(pgmReturn, {arg.GetNode()});
        auto& ctx = graph->GetContext();
        graph->GetEntryPoint(0, true)->SetValue(ctx, NUdf::TUnboxedValuePod(1));
        UNIT_ASSERT_EXCEPTION_CONTAINS(graph->GetValue(), std::exception, R"(Terminate was called, reason(51): foo.sql:8:9: The linear value has already been used)");
    }
}

}
}