aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/purecalc/ut/test_pg.cpp
blob: 3d26cfbd1be30dda4c5d3e4e848606a6ac8ffb6d (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
#include <yql/essentials/public/purecalc/purecalc.h>

#include "fake_spec.h"

#include <yql/essentials/public/purecalc/ut/protos/test_structs.pb.h>

#include <library/cpp/testing/unittest/registar.h>

Y_UNIT_TEST_SUITE(TestPg) {
    using namespace NYql::NPureCalc;

    Y_UNIT_TEST(TestPgCompile) {
        auto factory = MakeProgramFactory();

        auto sql = TString(R"(
            SELECT * FROM "Input";
        )");

        UNIT_ASSERT_NO_EXCEPTION([&](){
            factory->MakePullListProgram(FakeIS(1,true), FakeOS(true), sql, ETranslationMode::PG);
        }());

        UNIT_ASSERT_EXCEPTION_CONTAINS([&](){
            factory->MakePullStreamProgram(FakeIS(1,true), FakeOS(true), sql, ETranslationMode::PG);
        }(), TCompileError, "PullList mode");

        UNIT_ASSERT_EXCEPTION_CONTAINS([&](){
            factory->MakePushStreamProgram(FakeIS(1, true), FakeOS(true), sql, ETranslationMode::PG);
        }(), TCompileError, "PullList mode");
    }

    Y_UNIT_TEST(TestSqlWrongTableName) {
        auto factory = MakeProgramFactory();

        auto sql = TString(R"(
            SELECT * FROM WrongTable;
        )");

        UNIT_ASSERT_EXCEPTION_CONTAINS([&](){
            factory->MakePullListProgram(FakeIS(1, true), FakeOS(true), sql, ETranslationMode::PG);
        }(), TCompileError, "Failed to optimize");

        UNIT_ASSERT_EXCEPTION_CONTAINS([&](){
            factory->MakePullStreamProgram(FakeIS(1, true), FakeOS(true), sql, ETranslationMode::PG);
        }(), TCompileError, "PullList mode");

        UNIT_ASSERT_EXCEPTION_CONTAINS([&](){
            factory->MakePushStreamProgram(FakeIS(1, true), FakeOS(true), sql, ETranslationMode::PG);
        }(), TCompileError, "PullList mode");
    }

    Y_UNIT_TEST(TestInvalidSql) {
        auto factory = MakeProgramFactory();

        auto sql = TString(R"(
            Just some invalid SQL;
        )");

        UNIT_ASSERT_EXCEPTION_CONTAINS([&](){
            factory->MakePullListProgram(FakeIS(1, true), FakeOS(true), sql, ETranslationMode::PG);
        }(), TCompileError, "failed to parse PG");

        UNIT_ASSERT_EXCEPTION_CONTAINS([&](){
            factory->MakePullStreamProgram(FakeIS(1, true), FakeOS(true), sql, ETranslationMode::PG);
        }(), TCompileError, "PullList mode");

        UNIT_ASSERT_EXCEPTION_CONTAINS([&](){
            factory->MakePushStreamProgram(FakeIS(1, true), FakeOS(true), sql, ETranslationMode::PG);
        }(), TCompileError, "PullList mode");
    }
}