Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 13 additions & 2 deletions LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ Implementation of Julian Hyde's "Measures in SQL" paper (arXiv:2406.00251).

## Known Limitations

### 1. No Window Function Measures
### 1. Ambiguous AT Contexts for Window Measures

```sql
-- NOT SUPPORTED: Window functions in measure definitions
-- Supported: window measures in view definitions
CREATE VIEW v AS
SELECT year,
SUM(revenue) OVER (ORDER BY year) AS MEASURE running_total
FROM t;

-- Supported: direct query and AGGREGATE() without AT
SEMANTIC SELECT year, AGGREGATE(running_total)
FROM v
GROUP BY year;

-- Supported: AT modifiers when the evaluated window result is single-valued
SEMANTIC SELECT AGGREGATE(running_total) AT (WHERE year = 2024) FROM v;

-- Error: AT context produced multiple distinct window values
SEMANTIC SELECT year, AGGREGATE(running_total) AT (ALL) FROM v GROUP BY year;
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ The extension will be at `build/release/extension/yardstick/yardstick.duckdb_ext
See [LIMITATIONS.md](LIMITATIONS.md) for known issues and workarounds.

Key limitations:
- Window function measures not supported
- Window-defined measures with `AT (...)` must evaluate to a single value per context, or they error

## Testimonials

Expand Down
71 changes: 71 additions & 0 deletions test/sql/measures.test
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,77 @@ B 10
# Test: DuckDB generate_series / UNNEST
# =============================================================================

# =============================================================================
# Test: Window function in AS MEASURE
# =============================================================================

statement ok
CREATE TABLE window_measure_orders (year INT, revenue INT);

statement ok
INSERT INTO window_measure_orders VALUES
(2021, 10),
(2022, 20),
(2023, 30);

statement ok
CREATE VIEW window_measure_v AS
SELECT
year,
SUM(revenue) OVER (ORDER BY year) AS MEASURE running_total
FROM window_measure_orders;

query IT rowsort
SELECT year, running_total::VARCHAR
FROM window_measure_v
ORDER BY year;
----
2021 10
2022 30
2023 60

query IT rowsort
SEMANTIC SELECT year, AGGREGATE(running_total)::VARCHAR
FROM window_measure_v
GROUP BY year
ORDER BY year;
----
2021 10
2022 30
2023 60

query IT rowsort
SEMANTIC SELECT year, AGGREGATE(running_total) AT (WHERE year = 2022)::VARCHAR
FROM window_measure_v;
----
2021 20
2022 20
2023 20

statement error
SEMANTIC SELECT year, AGGREGATE(running_total) AT (ALL)
FROM window_measure_v
GROUP BY year;
----
Window measure running_total returned multiple values for the evaluation context

statement ok
CREATE VIEW window_total_v AS
SELECT
year,
SUM(revenue) OVER () AS MEASURE global_total
FROM window_measure_orders;

query IT rowsort
SEMANTIC SELECT year, AGGREGATE(global_total) AT (ALL)::VARCHAR
FROM window_total_v
GROUP BY year
ORDER BY year;
----
2021 60
2022 60
2023 60

statement ok
CREATE VIEW series_v AS
SELECT x, SUM(x) AS MEASURE total
Expand Down
Loading
Loading