summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/sql_ut_common.h
diff options
context:
space:
mode:
authorvokayndzop <[email protected]>2025-08-14 12:16:50 +0300
committervokayndzop <[email protected]>2025-08-14 13:10:46 +0300
commit618abcfd3763bc44abbc9ef934a8b1d71dc9c674 (patch)
tree272ad8a5da9f5603ab59d41fcfcd93c7a5963e95 /yql/essentials/sql/v1/sql_ut_common.h
parentbf42f3c2a0fe15d25acb32dd153f19102e205e0a (diff)
Watermarks: add time extractor to HoppingWindow
commit_hash:d54496a7e3d9bd72e53ce880691a59490a34a138
Diffstat (limited to 'yql/essentials/sql/v1/sql_ut_common.h')
-rw-r--r--yql/essentials/sql/v1/sql_ut_common.h151
1 files changed, 151 insertions, 0 deletions
diff --git a/yql/essentials/sql/v1/sql_ut_common.h b/yql/essentials/sql/v1/sql_ut_common.h
index 95bd2ce5e40..46d01395bec 100644
--- a/yql/essentials/sql/v1/sql_ut_common.h
+++ b/yql/essentials/sql/v1/sql_ut_common.h
@@ -9045,3 +9045,154 @@ WITH(
UNIT_ASSERT(res.IsOk());
}
}
+
+Y_UNIT_TEST_SUITE(HoppingWindow) {
+ Y_UNIT_TEST(HoppingWindow) {
+ auto query = R"sql(
+ SELECT
+ *
+ FROM plato.Input
+ GROUP BY HoppingWindow(key, 39, 42);
+ )sql";
+
+ NYql::TAstParseResult res = SqlToYql(query);
+ UNIT_ASSERT_VALUES_UNEQUAL(nullptr, res.Root);
+ UNIT_ASSERT(res.IsOk());
+ UNIT_ASSERT_VALUES_EQUAL(0, res.Issues.Size());
+ }
+
+ Y_UNIT_TEST(HoppingWindowWithoutSource) {
+ ExpectFailWithError(
+ R"sql(SELECT 1 + HoppingWindow(key, 39, 42);)sql",
+ "<main>:1:12: Error: HoppingWindow requires data source\n"
+ );
+ }
+
+ Y_UNIT_TEST(HoppingWindowInProjection) {
+ ExpectFailWithError(
+ R"sql(SELECT 1 + HoppingWindow(key, 39, 42) FROM plato.Input;)sql",
+ "<main>:1:12: Error: HoppingWindow can only be used as a top-level GROUP BY expression\n"
+ );
+ }
+
+ Y_UNIT_TEST(HoppingWindowWithNonConstIntervals) {
+ ExpectFailWithError(
+ R"sql(
+ SELECT
+ key,
+ hopping_start
+ FROM plato.Input
+ GROUP BY
+ HoppingWindow(key, 39 + subkey, 42) AS hopping_start,
+ key;
+ )sql",
+
+ "<main>:7:21: Error: Source does not allow column references\n"
+ "<main>:7:45: Error: Column reference 'subkey'\n"
+ );
+
+ ExpectFailWithError(
+ R"sql(
+ SELECT
+ key,
+ hopping_start
+ FROM plato.Input
+ GROUP BY
+ HoppingWindow(key, 39 + subkey, 42) AS hopping_start,
+ key;
+ )sql",
+
+ "<main>:7:21: Error: Source does not allow column references\n"
+ "<main>:7:45: Error: Column reference 'subkey'\n"
+ );
+ }
+
+ Y_UNIT_TEST(HoppingWindowWithWrongNumberOfArgs) {
+ ExpectFailWithError(
+ R"sql(
+ SELECT
+ *
+ FROM plato.Input
+ GROUP BY HoppingWindow(key, 39);
+ )sql",
+
+ "<main>:5:26: Error: HoppingWindow requires three arguments\n"
+ );
+
+ ExpectFailWithError(
+ R"sql(
+ SELECT
+ *
+ FROM plato.Input
+ GROUP BY HoppingWindow(key, 39, 42, 63);
+ )sql",
+
+ "<main>:5:26: Error: HoppingWindow requires three arguments\n"
+ );
+ }
+
+ Y_UNIT_TEST(DuplicateHoppingWindow) {
+ ExpectFailWithError(
+ R"sql(
+ SELECT
+ *
+ FROM plato.Input
+ GROUP BY
+ HoppingWindow(key, 39, 42),
+ subkey,
+ HoppingWindow(ts, 42, 39);
+ )sql",
+
+ "<main>:8:21: Error: Duplicate hopping window specification:\n"
+ "<main>:6:21: Error: Previous hopping window is declared here\n"
+ );
+ }
+
+ Y_UNIT_TEST(HopStartEndWithoutSource) {
+ ExpectFailWithError(
+ R"sql(SELECT 1 + HopStart();)sql",
+ "<main>:1:12: Error: HopStart requires data source\n"
+ );
+
+ ExpectFailWithError(
+ R"sql(SELECT 1 + HopEnd();)sql",
+ "<main>:1:12: Error: HopEnd requires data source\n"
+ );
+ }
+
+ Y_UNIT_TEST(HopStartEndWithoutGroupByOrWindow) {
+ ExpectFailWithError(
+ R"sql(SELECT 1 + HopStart() FROM plato.Input;)sql",
+ "<main>:1:12: Error: HopStart can not be used without aggregation by HoppingWindow\n"
+ );
+
+ ExpectFailWithError(
+ R"sql(SELECT 1 + HopEnd() FROM plato.Input;)sql",
+ "<main>:1:12: Error: HopEnd can not be used without aggregation by HoppingWindow\n"
+ );
+ }
+
+ Y_UNIT_TEST(HopStartEndWithGroupByWithoutHopping) {
+ ExpectFailWithError(
+ R"sql(
+ SELECT
+ 1 + HopStart()
+ FROM plato.Input
+ GROUP BY user;
+ )sql",
+
+ "<main>:3:25: Error: HopStart can not be used here: HoppingWindow specification is missing in GROUP BY\n"
+ );
+
+ ExpectFailWithError(
+ R"sql(
+ SELECT
+ 1 + HopEnd()
+ FROM plato.Input
+ GROUP BY user;
+ )sql",
+
+ "<main>:3:25: Error: HopEnd can not be used here: HoppingWindow specification is missing in GROUP BY\n"
+ );
+ }
+}