aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql
diff options
context:
space:
mode:
authorMaxim Yurchuk <maxim-yurchuk@ydb.tech>2024-11-20 17:37:57 +0000
committerGitHub <noreply@github.com>2024-11-20 17:37:57 +0000
commitf76323e9b295c15751e51e3443aa47a36bee8023 (patch)
tree4113c8cad473a33e0f746966e0cf087252fa1d7a /yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql
parent753ecb8d410a4cb459c26f3a0082fb2d1724fe63 (diff)
parenta7b9a6afea2a9d7a7bfac4c5eb4c1a8e60adb9e6 (diff)
downloadydb-f76323e9b295c15751e51e3443aa47a36bee8023.tar.gz
Merge pull request #11788 from ydb-platform/mergelibs-241120-1113
Library import 241120-1113
Diffstat (limited to 'yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql')
-rw-r--r--yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql65
1 files changed, 65 insertions, 0 deletions
diff --git a/yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql b/yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql
new file mode 100644
index 0000000000..a68fdd16a3
--- /dev/null
+++ b/yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql
@@ -0,0 +1,65 @@
+pragma warning("disable", "4520");
+
+$my_table =
+SELECT 1 AS id, 1 AS ts, 4 AS value1
+UNION ALL
+SELECT 2 AS id, 1 AS ts, NULL AS value1
+UNION ALL
+SELECT 1 AS id, 2 AS ts, 4 AS value1
+UNION ALL
+SELECT 3 AS id, 2 AS ts, 40 AS value1
+UNION ALL
+SELECT 3 AS id, 5 AS ts, 2 AS value1
+UNION ALL
+SELECT 3 AS id, 10 AS ts, 40 AS value1
+;
+
+$cnt_create = ($_item, $_parent) -> { return 1ul };
+$cnt_add = ($state, $_item, $_parent) -> { return 1ul + $state };
+$cnt_merge = ($state1, $state2) -> { return $state1 + $state2 };
+$cnt_get_result = ($state) -> { return $state };
+$cnt_serialize = ($state) -> { return $state };
+$cnt_deserialize = ($state) -> { return $state };
+-- non-trivial default value
+$cnt_default = 0.0;
+
+$cnt_udaf_factory = AggregationFactory(
+ "UDAF",
+ $cnt_create,
+ $cnt_add,
+ $cnt_merge,
+ $cnt_get_result,
+ $cnt_serialize,
+ $cnt_deserialize,
+ $cnt_default
+);
+
+
+SELECT
+ id
+ , ts
+ , value1
+ , AGGREGATE_BY(value1, $cnt_udaf_factory) OVER lagging AS lagging_opt
+ , AGGREGATE_BY(value1, $cnt_udaf_factory) OVER generic AS generic_opt
+
+ , AGGREGATE_BY(ts, $cnt_udaf_factory) OVER lagging AS lagging
+ , AGGREGATE_BY(ts, $cnt_udaf_factory) OVER generic AS generic
+
+ , AGGREGATE_BY(value1, $cnt_udaf_factory) OVER empty AS empty_opt
+ , AGGREGATE_BY(ts, $cnt_udaf_factory) OVER empty AS empty
+
+FROM $my_table
+WINDOW lagging AS (
+ ORDER BY ts, id
+ ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
+)
+, generic AS (
+ ORDER BY ts, id
+ ROWS BETWEEN 10 PRECEDING AND 1 PRECEDING
+)
+, empty AS (
+ ORDER BY ts, id
+ ROWS BETWEEN 10 FOLLOWING AND 1 FOLLOWING
+)
+ORDER BY ts, id;
+