forked from ydb-platform/ydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable COUNT in view queries (ydb-platform#6820)
- Loading branch information
Showing
23 changed files
with
223 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ydb/core/kqp/ut/view/input/cases/aggregates_and_window/create_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
CREATE VIEW `/Root/aggregates_and_window` WITH (security_invoker = TRUE) AS | ||
SELECT | ||
series.title AS series, | ||
series_stats.seasons_with_episode_count_greater_than_average AS seasons_with_episode_count_greater_than_average | ||
FROM ( | ||
SELECT | ||
series_id, | ||
SUM( | ||
CASE | ||
WHEN episode_count > average_episodes_in_season | ||
THEN 1 | ||
ELSE 0 | ||
END | ||
) AS seasons_with_episode_count_greater_than_average | ||
FROM ( | ||
SELECT | ||
series_id, | ||
season_id, | ||
episode_count, | ||
AVG(episode_count) OVER average_episodes_in_season_window AS average_episodes_in_season | ||
FROM ( | ||
SELECT | ||
series_id, | ||
season_id, | ||
COUNT(*) AS episode_count | ||
FROM `/Root/episodes` | ||
GROUP BY | ||
series_id, | ||
season_id | ||
) | ||
WINDOW | ||
average_episodes_in_season_window AS ( | ||
PARTITION BY | ||
series_id | ||
) | ||
) | ||
GROUP BY | ||
series_id | ||
) | ||
AS series_stats | ||
JOIN `/Root/series` | ||
AS series | ||
USING (series_id); |
1 change: 1 addition & 0 deletions
1
ydb/core/kqp/ut/view/input/cases/aggregates_and_window/drop_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW `/Root/aggregates_and_window`; |
46 changes: 46 additions & 0 deletions
46
ydb/core/kqp/ut/view/input/cases/aggregates_and_window/etalon_query.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
SELECT | ||
* | ||
FROM ( | ||
SELECT | ||
series.title AS series, | ||
series_stats.seasons_with_episode_count_greater_than_average AS seasons_with_episode_count_greater_than_average | ||
FROM ( | ||
SELECT | ||
series_id, | ||
SUM( | ||
CASE | ||
WHEN episode_count > average_episodes_in_season | ||
THEN 1 | ||
ELSE 0 | ||
END | ||
) AS seasons_with_episode_count_greater_than_average | ||
FROM ( | ||
SELECT | ||
series_id, | ||
season_id, | ||
episode_count, | ||
AVG(episode_count) OVER average_episodes_in_season_window AS average_episodes_in_season | ||
FROM ( | ||
SELECT | ||
series_id, | ||
season_id, | ||
COUNT(*) AS episode_count | ||
FROM `/Root/episodes` | ||
GROUP BY | ||
series_id, | ||
season_id | ||
) | ||
WINDOW | ||
average_episodes_in_season_window AS ( | ||
PARTITION BY | ||
series_id | ||
) | ||
) | ||
GROUP BY | ||
series_id | ||
) | ||
AS series_stats | ||
JOIN `/Root/series` | ||
AS series | ||
USING (series_id) | ||
); |
3 changes: 3 additions & 0 deletions
3
ydb/core/kqp/ut/view/input/cases/aggregates_and_window/select_from_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT | ||
* | ||
FROM `/Root/aggregates_and_window`; |
9 changes: 9 additions & 0 deletions
9
ydb/core/kqp/ut/view/input/cases/count_episodes/create_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE VIEW `/Root/count_episodes` WITH (security_invoker = TRUE) AS | ||
SELECT | ||
series_id, | ||
season_id, | ||
COUNT(*) | ||
FROM `/Root/episodes` | ||
GROUP BY | ||
series_id, | ||
season_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW `/Root/count_episodes`; |
12 changes: 12 additions & 0 deletions
12
ydb/core/kqp/ut/view/input/cases/count_episodes/etalon_query.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SELECT | ||
* | ||
FROM ( | ||
SELECT | ||
series_id, | ||
season_id, | ||
COUNT(*) | ||
FROM `/Root/episodes` | ||
GROUP BY | ||
series_id, | ||
season_id | ||
); |
3 changes: 3 additions & 0 deletions
3
ydb/core/kqp/ut/view/input/cases/count_episodes/select_from_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT | ||
* | ||
FROM `/Root/count_episodes`; |
22 changes: 22 additions & 0 deletions
22
ydb/core/kqp/ut/view/input/cases/count_episodes_with_titles/create_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CREATE VIEW `/Root/count_episodes_with_titles` WITH (security_invoker = TRUE) AS | ||
SELECT | ||
series.title AS series, | ||
seasons.title AS season, | ||
episodes.episode_count AS episode_count | ||
FROM ( | ||
SELECT | ||
series_id, | ||
season_id, | ||
COUNT(*) AS episode_count | ||
FROM `/Root/episodes` | ||
GROUP BY | ||
series_id, | ||
season_id | ||
) | ||
AS episodes | ||
JOIN `/Root/series` | ||
AS series | ||
ON episodes.series_id == series.series_id | ||
JOIN `/Root/seasons` | ||
AS seasons | ||
ON episodes.series_id == seasons.series_id AND episodes.season_id == seasons.season_id; |
1 change: 1 addition & 0 deletions
1
ydb/core/kqp/ut/view/input/cases/count_episodes_with_titles/drop_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW `/Root/count_episodes_with_titles`; |
25 changes: 25 additions & 0 deletions
25
ydb/core/kqp/ut/view/input/cases/count_episodes_with_titles/etalon_query.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
SELECT | ||
* | ||
FROM ( | ||
SELECT | ||
series.title AS series, | ||
seasons.title AS season, | ||
episodes.episode_count AS episode_count | ||
FROM ( | ||
SELECT | ||
series_id, | ||
season_id, | ||
COUNT(*) AS episode_count | ||
FROM `/Root/episodes` | ||
GROUP BY | ||
series_id, | ||
season_id | ||
) | ||
AS episodes | ||
JOIN `/Root/series` | ||
AS series | ||
ON episodes.series_id == series.series_id | ||
JOIN `/Root/seasons` | ||
AS seasons | ||
ON episodes.series_id == seasons.series_id AND episodes.season_id == seasons.season_id | ||
); |
3 changes: 3 additions & 0 deletions
3
ydb/core/kqp/ut/view/input/cases/count_episodes_with_titles/select_from_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT | ||
* | ||
FROM `/Root/count_episodes_with_titles`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE VIEW `/Root/count_rows` WITH (security_invoker = TRUE) AS | ||
SELECT | ||
COUNT(*) | ||
FROM `/Root/episodes`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW `/Root/count_rows`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SELECT | ||
* | ||
FROM ( | ||
SELECT | ||
COUNT(*) | ||
FROM `/Root/episodes` | ||
); |
3 changes: 3 additions & 0 deletions
3
ydb/core/kqp/ut/view/input/cases/count_rows/select_from_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT | ||
* | ||
FROM `/Root/count_rows`; |