aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
commit31773f157bf8164364649b5f470f52dece0a4317 (patch)
tree33d0f7eef45303ab68cf08ab381ce5e5e36c5240 /yql/essentials/tests/sql/suites/window/udaf_with_def_value.sql
parent2c7938962d8689e175574fc1e817c05049f27905 (diff)
parenteff600952d5dfe17942f38f510a8ac2b203bb3a5 (diff)
downloadydb-31773f157bf8164364649b5f470f52dece0a4317.tar.gz
Merge branch 'rightlib' into mergelibs-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;
+