Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DYOD] Support window function queries #2607

Open
wants to merge 170 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
44e28fa
Add `WindowFunctionEvaluator` class
niklasmohrin Jun 14, 2023
01ae82a
Write out the plan
niklasmohrin Jun 14, 2023
c95a63b
Implement `WindowFunctionEvaluator::partition_and_sort()`
niklasmohrin Jun 14, 2023
adffb55
Inheriting from `AbstractReadOnlyOperator` is correct
niklasmohrin Jun 15, 2023
f0ffe96
Note that we should at some point change the return type of `WindowFu…
niklasmohrin Jun 15, 2023
b0392fb
Figure out data type of result column
niklasmohrin Jun 15, 2023
58e6bb9
Implement `WindowFunctionEvaluator::compute_window_function` for `Win…
niklasmohrin Jun 15, 2023
3b05e8d
`WindowFunctionEvaluator::annotate_input_table`
niklasmohrin Jun 20, 2023
f42078f
Use inter-hash-partition parallelism for materializing input and `com…
niklasmohrin Jun 20, 2023
34cf584
Construct `ValueSegment`s from vectors
niklasmohrin Jun 20, 2023
9e9ac2f
Wait for tasks
niklasmohrin Jun 20, 2023
26d285c
add first two sql queries for window functions
cambryx Jun 20, 2023
eb6616e
fix first two sql queries for window functions
cambryx Jun 20, 2023
248da4c
Add `WindowNode::window_function_expression` helper
niklasmohrin Jun 20, 2023
5df980b
Add `WindowExpression::{partition, order}_by_expressions` helpers
niklasmohrin Jun 20, 2023
75ac6f0
Add missing pure virtual methods to `WindowFunctionEvaluator`
niklasmohrin Jun 20, 2023
ffbdf57
Add constructor for `WindowFunctionEvaluator`
niklasmohrin Jun 20, 2023
40fd424
Implement `LQPTranslator::_translate_window_node`
niklasmohrin Jun 20, 2023
1c6b829
Give explicit names to window function columns in sqlite queries
niklasmohrin Jun 20, 2023
24a7f9d
Actually, we do throw for the existing lqp translation test, because …
niklasmohrin Jun 20, 2023
fa18f75
Materialize segments before outputting them
niklasmohrin Jun 20, 2023
7e67dcb
Avoid materializing the whole table in annotate_input_table.
cambryx Jun 21, 2023
2260dfc
Make summing work
niklasmohrin Jun 21, 2023
c1b50ec
add accessor for frame_description to WindowFunctionEvaluator and add…
Finn-HPI Jun 21, 2023
0b88e49
Return ref, not unique_ptr ref from `WindowFunctionEvaluator::frame_d…
niklasmohrin Jun 21, 2023
225fcee
Do static dispatch very early
niklasmohrin Jun 21, 2023
e89da19
Fixups from meeting
niklasmohrin Jun 27, 2023
5cf0999
Sum NULL values like sqlite
niklasmohrin Jun 27, 2023
7ba4a64
add possibility to partition by and order by multiple columns
cambryx Jun 27, 2023
e63a58b
refactor comparator for RelevantRowInformation
cambryx Jun 27, 2023
70ef356
Add support for Row FrameBounds for Sum
niklasmohrin Jun 27, 2023
3000054
dont use C-style casts
niklasmohrin Jun 27, 2023
e3e8e6b
Separate partition bound calculation from window function evaluation
niklasmohrin Jun 27, 2023
254d3c9
Add `SegmentTree`
niklasmohrin Jun 27, 2023
1683106
Move `SegmentTree` neutral element to runtime argument, because `std:…
niklasmohrin Jun 27, 2023
cf7e78b
Use `SegmentTree` for computing window value
niklasmohrin Jun 27, 2023
89655da
Move segment tree operations to new file
niklasmohrin Jun 28, 2023
3163365
Implement min & max with segment tree
niklasmohrin Jun 28, 2023
bac45e8
Make `_on_execute` a little less nasty
niklasmohrin Jun 28, 2023
3b306c8
Get rid of `PartitionedData` and use `RelevantRowInformation` everywhere
cambryx Jun 29, 2023
0d28343
Just reordering stuff in header
niklasmohrin Jun 29, 2023
6e75fed
Move `spawn_and_wait_per_hash` to static function
niklasmohrin Jun 29, 2023
199f807
Move `calculate_partition_bounds` to static function `for_each_partit…
niklasmohrin Jun 29, 2023
926a0c3
Introduce `ComputationStrategy` and choose it accordingly
niklasmohrin Jun 29, 2023
430aff5
Separate `compute_window_function` into `compute_window_function_{one…
niklasmohrin Jun 29, 2023
39063b1
Refactor rank computation to use generic `OnePassState` pattern - and…
niklasmohrin Jun 29, 2023
a8778a6
Add `DenseRank` and `RowNumber` and fix `Rank`
niklasmohrin Jun 29, 2023
43d42b1
Start writing test for rank window operator
Finn-HPI Jun 29, 2023
7a0001d
Add is_output_nullable and save _function_argument_column_id as membe…
Finn-HPI Jun 29, 2023
d9052f2
add test result table and complete rank test
Finn-HPI Jun 29, 2023
0226ab1
Refactor window_test and add tests for DenseRank and RowNumber
Finn-HPI Jul 1, 2023
b090028
Make NULL self-equal when comparing partitioning and ordering values
niklasmohrin Jun 30, 2023
21b1ff1
Compare order values with NULL self-equality for rank-like queries
niklasmohrin Jun 30, 2023
70ee45b
Implement OnePass for Sum
niklasmohrin Jun 30, 2023
3616f4a
Generalize restriction for running onepass algorithm
niklasmohrin Jul 3, 2023
800d3e0
Fix Sum onepass compilation error
niklasmohrin Jul 3, 2023
543eae6
Format
niklasmohrin Jul 3, 2023
6e213ce
Retrieve ColumnIDs for window in lqp_translator
Finn-HPI Jul 4, 2023
7eda848
format
Finn-HPI Jul 4, 2023
c41c0eb
Only choose supported strategies
niklasmohrin Jul 4, 2023
6570ddc
Implement AVG
niklasmohrin Jul 4, 2023
9bd1261
Add test queries for more complicated ColumnExpressions
Finn-HPI Jul 4, 2023
08da2ce
Fix typing for min max neutral elements
niklasmohrin Jul 4, 2023
ef6e60a
Fix segment tree query range not being offset to current partition
niklasmohrin Jul 4, 2023
27e753e
Let `parallel_merge_sort` take comparator as argument
niklasmohrin Jul 5, 2023
2cc1070
Handle sort modes in order-by
niklasmohrin Jul 5, 2023
49b7624
Document `SegmentTree` implementation
niklasmohrin Jul 5, 2023
f0e132e
Add _on_deep_copy implementation
Finn-HPI Jul 11, 2023
ed26d50
Add PerformanceData to window_function_evaluator
Finn-HPI Jul 11, 2023
d880d9b
Use `segment_iterate` when constructing `RelevantRowInformation`
niklasmohrin Jul 11, 2023
81f4493
Replace `IdentityTransformer` with `std::identity`
niklasmohrin Jul 11, 2023
1b4b5de
Also use OnePass if in Rows mode
niklasmohrin Jul 11, 2023
806d275
Add mixin for onepass logic, if segment tree logic is already specifi…
niklasmohrin Jul 11, 2023
f4697a6
Add onepass support for min and max
niklasmohrin Jul 11, 2023
c0e0150
Add non-const version of `spawn_and_wait_per_hash` and support `per_h…
niklasmohrin Jul 11, 2023
7e8d5c5
Sort and merge each hash partition in own task
niklasmohrin Jul 11, 2023
5fc41b4
Save value of `computation_strategy` in `PerformanceData`, not only b…
niklasmohrin Jul 12, 2023
61590be
Only use onepass for rank like functions or if in rows mode
niklasmohrin Jul 12, 2023
ac14600
Move `QueryRange` out of `SegmentTree` template
niklasmohrin Jul 12, 2023
dfba20a
Add `FrameType` as template parameter for segment tree computation, b…
niklasmohrin Jul 12, 2023
0444459
Make `as_optional` public
niklasmohrin Jul 12, 2023
b5c6ab3
Add support for Range mode frames
niklasmohrin Jul 12, 2023
aa1bf95
Allow Range mode with no order by columns
niklasmohrin Jul 12, 2023
3d974ae
Support Count
niklasmohrin Jul 17, 2023
f35fc3b
Fix order-by assert
niklasmohrin Jul 17, 2023
958bde1
Add more supported queries
niklasmohrin Jul 17, 2023
63455d2
Update `resources/benchmark/tpcds/tpcds-result-reproduction` submodule
niklasmohrin Jul 17, 2023
3f73b67
Move `as_optional` to `all_type_variant.hpp`
niklasmohrin Jul 19, 2023
d77429f
Refactor `window_function_combinator.hpp`, now `window_function_evalu…
niklasmohrin Jul 19, 2023
5cc2308
Fix wrong usage of `SupportsSegmentTree`
niklasmohrin Jul 22, 2023
06dbec8
Restructure into own namespace and multiple files
niklasmohrin Jul 24, 2023
e36714e
Fix some lints
niklasmohrin Jul 24, 2023
c9beb8d
Allow running now-supported TPCDS queries
niklasmohrin Jul 25, 2023
cde50a7
Move recursion results when merging
niklasmohrin Jul 25, 2023
04b8fc1
Use `inplace_merge`
niklasmohrin Jul 25, 2023
5c1554f
Fix `neutral_element` compilation error
niklasmohrin Jul 25, 2023
25a7d31
Don't use default constructed lambdas
niklasmohrin Jul 25, 2023
26fa3a4
Changes needed after rebase
niklasmohrin Jul 26, 2023
a1b7057
Refactor and extend window_test
Finn-HPI Jul 26, 2023
f47fb94
Add some basic tests for sum,avg,min and max
Finn-HPI Jul 26, 2023
77afe3a
add range mode tests for sum/avg/min/max
Finn-HPI Jul 26, 2023
63236e1
add test for invalid WindowFunctionTypes
Finn-HPI Jul 26, 2023
626e6a6
revert change
Finn-HPI Jul 26, 2023
5ccdc02
Test some asserts
Finn-HPI Jul 26, 2023
2bd519b
Add missing trailing newlines
niklasmohrin Jul 26, 2023
3f95eab
Small fixups
niklasmohrin Jul 26, 2023
73ac894
Fix compilation error
niklasmohrin Jul 27, 2023
f0fe9e4
Make callers check the requirements for using OnePass and SegmentTree…
niklasmohrin Jul 27, 2023
6b69ae5
Remove `initial_rank`
niklasmohrin Jul 27, 2023
3bf56c0
Move more stuff out of `WindowFunctionEvaluator` class namespace into…
niklasmohrin Jul 27, 2023
37ae496
Missed a rename
niklasmohrin Jul 27, 2023
158552f
Add some basic WindowNode tests in lqp_translator_test
Finn-HPI Jul 31, 2023
c9d07e3
Materialize and then sort the input, so that we don't sort tiny vectors
niklasmohrin Jul 27, 2023
86bd440
Measure partition and sort in separate steps
niklasmohrin Jul 27, 2023
03b30c3
Inline `partition_and_sort`, so only one timer is needed (and they ar…
niklasmohrin Jul 30, 2023
1d64fff
Rename operator steps
niklasmohrin Aug 1, 2023
2f6283b
Replace gcc 9 with gcc 10
niklasmohrin Aug 1, 2023
48c3a95
Add microbenchmark, does it make sense?
niklasmohrin Aug 1, 2023
9872b1c
Suppress linter false positives
niklasmohrin Aug 2, 2023
d7da430
add scheduler to WindowOperator Microbenchmark
Finn-HPI Aug 2, 2023
2569e07
Small fixes
niklasmohrin Aug 2, 2023
140c26e
Add `RelevantRowInformation::is_peer_of`
niklasmohrin Aug 2, 2023
3b8430d
Clean tests a bit
niklasmohrin Aug 2, 2023
7ca2aad
Fix auto-to-stick from pr comments
Finn-HPI Aug 14, 2023
faee2a4
Fix grammar and punctuation in commments and messages
Finn-HPI Aug 14, 2023
e50e260
Integrate pr comments, mainly some incosistencies and vector reserve
Finn-HPI Aug 14, 2023
7108335
Use string stream to build error_message
Finn-HPI Aug 14, 2023
0786941
Extract size() from for loops
Finn-HPI Aug 15, 2023
b367eba
Make ComputationStrategy printable
Finn-HPI Aug 15, 2023
35d91b3
Use Fail instead of empty default switch case
Finn-HPI Aug 15, 2023
1761ff9
Small clarifications and comments
Finn-HPI Aug 15, 2023
981df28
Change value type and use `auto` for `computation_strategy_to_string`…
niklasmohrin Aug 16, 2023
456f3bc
Implement more detailed description
niklasmohrin Aug 17, 2023
68a2b11
add short comments to window_function_evaluator/util.hpp
Finn-HPI Aug 18, 2023
fda1453
update window_node comment for printing description
Finn-HPI Aug 18, 2023
d5d6e74
Add some comments for _templated_on_execute
Finn-HPI Aug 18, 2023
1d3800e
Remove unused include from window_function_evaluator
Finn-HPI Aug 18, 2023
4a45275
add comments to materialize_into_buckets
Finn-HPI Aug 18, 2023
01c987b
Add comment for the WindowBoundCalculator base implementation
Finn-HPI Aug 18, 2023
0fd54e6
remove extra ; from namespace in window_function_traits.hpp
Finn-HPI Aug 19, 2023
e5ff198
remove extra ; in segment_tree.hpp and window_function_evaluator.cpp
Finn-HPI Aug 20, 2023
229def1
Change description as discussed in slack and add test
niklasmohrin Aug 20, 2023
0ed7afc
Measure cleanup as extra step
niklasmohrin Aug 20, 2023
0d18c9b
Fix linter, reword some comments
niklasmohrin Aug 20, 2023
d8ecb29
Replace the word "hash partition" with "bucket"
niklasmohrin Aug 20, 2023
4a54bd4
Follow up: Rename `HashPartitionedData` to `Buckets`
niklasmohrin Aug 20, 2023
b979623
Add comment to `WindowFunctionEvaluator`
niklasmohrin Aug 20, 2023
11288f3
Fix auto-to-stick in window_function_evaluator_traits.hpp
Finn-HPI Aug 21, 2023
f2c802b
Remove `parallel_merge_sort` and add reference to other PR
niklasmohrin Aug 21, 2023
46fe698
Mention paper in operator description
niklasmohrin Aug 21, 2023
c104e71
Move `is_rank_like` to `util.hpp`
niklasmohrin Aug 21, 2023
71f783e
Document `window_function_evaluator_traits.hpp`
niklasmohrin Aug 21, 2023
dfcbe9c
Change constructor of WindowFunctionEvaluator
Finn-HPI Aug 22, 2023
bfd6764
Small naming change
Finn-HPI Aug 22, 2023
d0c45e6
Check for `nullptr` chunks in `materialize_into_buckets`
niklasmohrin Aug 23, 2023
081546c
Use `magic_enum` to make `_on_execute` less repetitive
niklasmohrin Aug 23, 2023
42d9e8f
Don't take output data type as constructor argument
niklasmohrin Aug 23, 2023
ad2352f
Allow `COUNT(nullable_string_col)` queries, because we already suppor…
niklasmohrin Aug 23, 2023
d64aa4b
add test with descending sort mode
cambryx Aug 23, 2023
ac5eee9
refactor compare_with_null_equal to always use reverse() not only on …
cambryx Aug 23, 2023
eaec7c1
Remove BM_WindowFunctionEvaluatorRank micro-benchmark
Finn-HPI Aug 23, 2023
0628d08
start writing test for deep copy. doesn't work yet because of accessi…
cambryx Aug 23, 2023
ce48e26
fix deepcopy test and format
cambryx Aug 24, 2023
34fc20f
Add sqlite query for `count(nullable_string_col)`
niklasmohrin Aug 24, 2023
55ed174
Run `./script/format.sh` with `InsertBraces` option enabled
niklasmohrin Aug 24, 2023
c1ca870
Clarify segment tree example query
niklasmohrin Aug 24, 2023
007c106
Remove our includes from benchmark file
niklasmohrin Aug 24, 2023
746cecf
Revert to normal header order
niklasmohrin Aug 24, 2023
46f51b3
Fix `count(nullable_string_col)` test
niklasmohrin Aug 24, 2023
8a002f4
Restart CI
Finn-HPI Aug 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ RUN apt-get update \
cmake \
curl \
dos2unix \
g++-9 \
g++-10 \
g++-11 \
gcc-9 \
gcc-10 \
gcc-11 \
gcovr \
git \
Expand Down
12 changes: 6 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ try {
clang = '-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++'
clang11 = '-DCMAKE_C_COMPILER=clang-11 -DCMAKE_CXX_COMPILER=clang++-11'
gcc = '-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++'
gcc9 = '-DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9'
gcc10 = '-DCMAKE_C_COMPILER=gcc-10 -DCMAKE_CXX_COMPILER=g++-10'

debug = '-DCMAKE_BUILD_TYPE=Debug'
release = '-DCMAKE_BUILD_TYPE=Release'
Expand All @@ -114,7 +114,7 @@ try {
mkdir gcc-debug && cd gcc-debug && ${cmake} ${debug} ${gcc} .. &\
mkdir gcc-release && cd gcc-release && ${cmake} ${release} ${gcc} .. &\
mkdir clang-11-debug && cd clang-11-debug && ${cmake} ${debug} ${clang11} .. &\
mkdir gcc-9-debug && cd gcc-9-debug && ${cmake} ${debug} ${gcc9} .. &\
mkdir gcc-10-debug && cd gcc-10-debug && ${cmake} ${debug} ${gcc10} .. &\
wait"
}

Expand All @@ -133,10 +133,10 @@ try {
sh "cd gcc-debug && make all -j \$(( \$(nproc) / 4))"
sh "cd gcc-debug && ./hyriseTest"
}
}, gcc9Debug: {
stage("gcc-9-debug") {
sh "cd gcc-9-debug && make all -j \$(( \$(nproc) / 4))"
sh "cd gcc-9-debug && ./hyriseTest"
}, gcc10Debug: {
stage("gcc-10-debug") {
sh "cd gcc-10-debug && make all -j \$(( \$(nproc) / 4))"
sh "cd gcc-10-debug && ./hyriseTest"
}
}, lint: {
stage("Linting") {
Expand Down
2 changes: 1 addition & 1 deletion install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if echo $REPLY | grep -E '^[Yy]$' > /dev/null; then
echo "Installing dependencies (this may take a while)..."
if sudo apt-get update >/dev/null; then
# Packages added here should also be added to the Dockerfile
sudo apt-get install --no-install-recommends -y autoconf bash-completion bc clang-11 clang-14 clang-format-14 clang-tidy-14 cmake curl dos2unix g++-9 gcc-9 g++-11 gcc-11 gcovr git graphviz libboost-all-dev libhwloc-dev libncurses5-dev libnuma-dev libnuma1 libpq-dev libreadline-dev libsqlite3-dev libtbb-dev lld man parallel postgresql-server-dev-all python3 python3-pip valgrind &
sudo apt-get install --no-install-recommends -y autoconf bash-completion bc clang-11 clang-14 clang-format-14 clang-tidy-14 cmake curl dos2unix g++-10 gcc-10 g++-11 gcc-11 gcovr git graphviz libboost-all-dev libhwloc-dev libncurses5-dev libnuma-dev libnuma1 libpq-dev libreadline-dev libsqlite3-dev libtbb-dev lld man parallel postgresql-server-dev-all python3 python3-pip valgrind &

if ! git submodule update --jobs 5 --init --recursive; then
echo "Error during git fetching submodules."
Expand Down
10 changes: 5 additions & 5 deletions resources/benchmark/tpcds/query_blacklist.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#09.sql
#10.sql
11.sql
12.sql
#12.sql
#13.sql
14a.sql
14b.sql
Expand All @@ -18,7 +18,7 @@
#17.sql
18.sql
#19.sql
20.sql
#20.sql
21.sql
22.sql
23a.sql
Expand All @@ -45,14 +45,14 @@
#41.sql
#42.sql
#43.sql
44.sql
#44.sql
#45.sql
46.sql
47.sql
#48.sql
49.sql
#50.sql
51.sql
#51.sql
#52.sql
53.sql
54.sql
Expand Down Expand Up @@ -99,5 +99,5 @@
#95.sql
#96.sql
#97.sql
98.sql
#98.sql
#99.sql
40 changes: 40 additions & 0 deletions resources/test_data/sqlite_testrunner_queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,46 @@ SELECT * FROM id_int_int_int_100 WHERE NOT EXISTS (SELECT * FROM int_date WHERE
-- exists to semi join reformulation: query not rewriteable
SELECT * FROM id_int_int_int_100 WHERE EXISTS (SELECT * FROM int_date WHERE id_int_int_int_100.id = int_date.a) OR id < 20

-- Window Functions
SELECT id, a, b, c, RANK() OVER (PARTITION BY a ORDER BY c) AS r FROM mixed
SELECT id, a, b, c, SUM(b) OVER (PARTITION BY a ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS s FROM mixed
SELECT a, b, c, SUM(b) OVER (PARTITION BY a ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS s FROM mixed_null
SELECT a, b, c, AVG(b) OVER (PARTITION BY a ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS s FROM mixed_null
-- multiple order by
SELECT id, a, b, c, RANK() OVER (PARTITION BY b ORDER BY a, c) AS r FROM mixed
SELECT id, a, b, c, RANK() OVER (PARTITION BY a, b ORDER BY c) AS r FROM mixed
-- rows frame
SELECT id, a, b, c, SUM(b) OVER (PARTITION BY a ORDER BY c ROWS BETWEEN 5 PRECEDING AND 5 FOLLOWING) as s FROM mixed
SELECT id, a, b, c, SUM(b) OVER (PARTITION BY a ORDER BY c ROWS BETWEEN 3 PRECEDING AND UNBOUNDED FOLLOWING) as s FROM mixed
SELECT id, a, b, c, SUM(b) OVER (PARTITION BY a ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING) as s FROM mixed
-- min, max
SELECT id, MIN(b) OVER (PARTITION BY a ORDER BY c ROWS BETWEEN 3 PRECEDING AND 1 FOLLOWING) AS m FROM mixed
SELECT id, MAX(b) OVER (PARTITION BY a ORDER BY c ROWS BETWEEN 3 PRECEDING AND 1 FOLLOWING) AS m FROM mixed
SELECT id, MIN(c) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN 3 PRECEDING AND 1 FOLLOWING) AS m FROM mixed
SELECT id, MAX(c) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN 3 PRECEDING AND 1 FOLLOWING) AS m FROM mixed
-- ranks
SELECT id, RANK() OVER (PARTITION BY a ORDER BY b) AS r FROM mixed
SELECT id, DENSE_RANK() OVER (PARTITION BY a ORDER BY b) AS r FROM mixed
SELECT id, ROW_NUMBER() OVER (PARTITION BY a ORDER BY b) AS r FROM mixed
-- partition on nullable column
SELECT a, b, RANK() OVER (PARTITION BY b ORDER BY a) AS r FROM mixed_null
SELECT a, b, RANK() OVER (PARTITION BY a ORDER BY b) AS r FROM mixed_null
-- column expressions with offset
SELECT id, RANK() OVER (PARTITION BY b + 2 ORDER BY c + 3) AS r FROM mixed
SELECT id, a, b, c, SUM(b + 5) OVER (PARTITION BY a ORDER BY c + 5 ROWS BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING) as s FROM mixed
SELECT id, a, b, c, SUM(b + 5) OVER (PARTITION BY a ORDER BY c + 5 ROWS BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING) as s FROM id_int_int_int_100
-- sort modes
SELECT id, RANK() OVER (ORDER BY b DESC, c) AS r from id_int_int_int_100;
SELECT id, DENSE_RANK() OVER (ORDER BY b DESC, c ASC) AS r from id_int_int_int_100;
SELECT id, ROW_NUMBER() OVER (ORDER BY b DESC, c DESC) AS r from id_int_int_int_100;
SELECT id, AVG(a) OVER (ORDER BY b ASC, c DESC ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING) AS average from id_int_int_int_100;
-- range mode
SELECT id, AVG(a) OVER (ORDER BY b RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING) AS average from id_int_int_int_100;
SELECT id, SUM(a) OVER (PARTITION BY b) AS average from id_int_int_int_100;
-- count
SELECT id, a, b, c, count(a) over (PARTITION BY b ORDER BY c) AS count from id_int_int_int_100;
SELECT a, b, COUNT(d) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN 3 PRECEDING AND 1 FOLLOWING) AS count FROM mixed_null

-- Aggregates
SELECT SUM(b + b) AS sum_b_b FROM mixed;
SELECT SUM(b) + AVG(c) AS x FROM mixed GROUP BY id + 5;
Expand Down
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/avg.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|AVG(b)
int|int|double
1|5|3.5
1|6|4.333333333333333
1|6|4.75
1|7|5.2
1|2|2
2|1|1
2|1|1
2|2|1.333333333333333
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/dense_rank.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|DENSE_RANK()
int|int|long
1|5|2
1|6|3
1|6|3
1|7|4
1|2|1
2|1|1
2|1|1
2|2|2
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/input_not_unique.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b
int|int
1|5
1|6
1|6
1|7
1|2
2|1
2|1
2|2
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/input_three_columns.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|c
int|int|int
1|5|2
1|6|3
1|6|5
1|7|6
1|2|3
2|1|0
2|1|3
2|2|2
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/max.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|MAX(b)
int|int|int
1|5|5
1|6|6
1|6|6
1|7|7
1|2|2
2|1|1
2|1|1
2|2|2
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/min.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|MIN(b)
int|int|int
1|5|2
1|6|2
1|6|2
1|7|2
1|2|2
2|1|1
2|1|1
2|2|1
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/prefix_sum.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|SUM(b)
int|int|long
1|5|7
1|6|19
1|6|19
1|7|26
1|2|2
2|1|2
2|1|2
2|2|4
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/range_avg.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|AVG(b)
int|int|double
1|5|3.5
1|6|5.66666666666667
1|6|5.66666666666667
1|7|6
1|2|2
2|1|1
2|1|1
2|2|1.33333333333333
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/range_max.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|MAX(b)
int|int|int
1|5|6
1|6|7
1|6|7
1|7|7
1|2|2
2|1|2
2|1|2
2|2|2
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/range_min.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|MIN(b)
int|int|int
1|5|2
1|6|5
1|6|5
1|7|5
1|2|2
2|1|1
2|1|1
2|2|1
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/rank.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|RANK()
int|int|long
1|5|2
1|6|3
1|6|3
1|7|5
1|2|1
2|1|1
2|1|1
2|2|3
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/rank_reverse.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|RANK()
int|int|long
1|5|4
1|6|2
1|6|2
1|7|1
1|2|5
2|1|2
2|1|2
2|2|1
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/row_number.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|ROW_NUMBER()
int|int|long
1|5|2
1|6|3
1|6|4
1|7|5
1|2|1
2|1|1
2|1|2
2|2|3
10 changes: 10 additions & 0 deletions resources/test_data/tbl/window_operator/sum.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a|b|SUM(b)
int|int|long
1|5|7
1|6|13
1|6|19
1|7|26
1|2|2
2|1|1
2|1|2
2|2|4
6 changes: 6 additions & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ set(
operators/update.hpp
operators/validate.cpp
operators/validate.hpp
operators/window_function_evaluator.cpp
operators/window_function_evaluator.hpp
operators/window_function_evaluator/util.cpp
operators/window_function_evaluator/util.hpp
operators/window_function_evaluator/window_function_evaluator_traits.hpp
optimizer/join_ordering/abstract_join_ordering_algorithm.cpp
optimizer/join_ordering/abstract_join_ordering_algorithm.hpp
optimizer/join_ordering/dp_ccp.cpp
Expand Down Expand Up @@ -650,6 +655,7 @@ set(
utils/print_utils.hpp
utils/pruning_utils.cpp
utils/pruning_utils.hpp
utils/segment_tree.hpp
utils/settings/abstract_setting.cpp
utils/settings/abstract_setting.hpp
utils/settings_manager.cpp
Expand Down
8 changes: 8 additions & 0 deletions src/lib/all_type_variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ inline DataType data_type_from_all_type_variant(const AllTypeVariant& all_type_v
return static_cast<DataType>(all_type_variant.which());
}

template <typename T>
std::optional<T> as_optional(AllTypeVariant value) {
if (variant_is_null(value)) {
return std::nullopt;
}
return boost::get<T>(value);
}

} // namespace hyrise

namespace std {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/expression/window_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ WindowExpression::WindowExpression(std::vector<std::shared_ptr<AbstractExpressio
arguments.begin() + order_by_expressions_begin_idx);
}

std::span<const std::shared_ptr<AbstractExpression>> WindowExpression::partition_by_expressions() const {
return {arguments.begin(), order_by_expressions_begin_idx};
}

std::span<const std::shared_ptr<AbstractExpression>> WindowExpression::order_by_expressions() const {
return {arguments.begin() + static_cast<int64_t>(order_by_expressions_begin_idx), arguments.end()};
}

std::shared_ptr<AbstractExpression> WindowExpression::_on_deep_copy(
std::unordered_map<const AbstractOperator*, std::shared_ptr<AbstractOperator>>& copied_ops) const {
const auto expression_count = arguments.size();
Expand Down
5 changes: 5 additions & 0 deletions src/lib/expression/window_expression.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <span>

#include "abstract_expression.hpp"

namespace hyrise {
Expand Down Expand Up @@ -61,6 +63,9 @@ class WindowExpression : public AbstractExpression {
FrameDescription frame_description;
size_t order_by_expressions_begin_idx{0};

std::span<const std::shared_ptr<AbstractExpression>> partition_by_expressions() const;
std::span<const std::shared_ptr<AbstractExpression>> order_by_expressions() const;

protected:
std::shared_ptr<AbstractExpression> _on_deep_copy(
std::unordered_map<const AbstractOperator*, std::shared_ptr<AbstractOperator>>& copied_ops) const override;
Expand Down
Loading