Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nepal committed Dec 21, 2023
1 parent 8b7eb04 commit 18f2f22
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ydb/library/yql/sql/pg/pg_sql_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,25 @@ SELECT COUNT(*) FROM public.t;");
UNIT_ASSERT_C(res.Root, "Failed to parse statement, root is nullptr");
UNIT_ASSERT_STRINGS_EQUAL(res.Root->ToString(), expectedAst.Root->ToString());
}

Y_UNIT_TEST(BlockEngine) {
auto res = PgSqlToYql("set blockEngine='auto'; select 1;");
UNIT_ASSERT(res.Root);
UNIT_ASSERT_STRING_CONTAINS(res.Root->ToString(), "(let world (Configure! world (DataSource 'config) 'BlockEngine 'auto))");

res = PgSqlToYql("set Blockengine='force'; select 1;");
UNIT_ASSERT(res.Root);
UNIT_ASSERT_STRING_CONTAINS(res.Root->ToString(), "(let world (Configure! world (DataSource 'config) 'BlockEngine 'force))");

res = PgSqlToYql("set BlockEngine='disable'; select 1;");
UNIT_ASSERT(res.Root);
UNIT_ASSERT(!res.Root->ToString().Contains("BlockEngine"));

res = PgSqlToYql("set BlockEngine='foo'; select 1;");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_EQUAL(res.Issues.Size(), 1);

auto issue = *(res.Issues.begin());
UNIT_ASSERT(issue.GetMessage().Contains("VariableSetStmt, not supported BlockEngine option value: foo"));
}
}
25 changes: 25 additions & 0 deletions ydb/library/yql/sql/v1/sql_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5918,3 +5918,28 @@ Y_UNIT_TEST_SUITE(TopicsDDL) {
)", false);
}
}

Y_UNIT_TEST_SUITE(BlockEnginePragma) {
Y_UNIT_TEST(Basic) {
const TVector<TString> values = {"auto", "force", "disable"};
for (const auto& value : values) {
const auto query = TStringBuilder() << "pragma Blockengine='" << value << "'; select 1;";
NYql::TAstParseResult res = SqlToYql(query);
UNIT_ASSERT(res.Root);

TVerifyLineFunc verifyLine = [&](const TString& word, const TString& line) {
Y_UNUSED(word);
UNIT_ASSERT_STRING_CONTAINS(line, TStringBuilder() << R"(Configure! world (DataSource '"config") '"BlockEngine" '")" << value << "\"");
};

TWordCountHive elementStat({"BlockEngine"});
VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT(elementStat["BlockEngine"] == ((value == "disable") ? 0 : 1));
}
}

Y_UNIT_TEST(UnknownSetting) {
ExpectFailWithError("use plato; pragma BlockEngine='foo';",
"<main>:1:31: Error: Expected `disable|auto|force' argument for: BlockEngine\n");
}
}

0 comments on commit 18f2f22

Please sign in to comment.