summaryrefslogtreecommitdiffstats
path: root/tests/fixtures/optimizer/optimizer.sql
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-04-03 07:31:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-04-03 07:31:50 +0000
commit1fb60a37d31eacbac62ddafde51b829522925694 (patch)
tree5c04a33630f7a2cd4cff248e965053f97ec3e4ac /tests/fixtures/optimizer/optimizer.sql
parentAdding upstream version 11.4.1. (diff)
downloadsqlglot-1fb60a37d31eacbac62ddafde51b829522925694.tar.xz
sqlglot-1fb60a37d31eacbac62ddafde51b829522925694.zip
Adding upstream version 11.4.5.upstream/11.4.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/fixtures/optimizer/optimizer.sql')
-rw-r--r--tests/fixtures/optimizer/optimizer.sql40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/fixtures/optimizer/optimizer.sql b/tests/fixtures/optimizer/optimizer.sql
index 0b5504d..c5112b2 100644
--- a/tests/fixtures/optimizer/optimizer.sql
+++ b/tests/fixtures/optimizer/optimizer.sql
@@ -461,3 +461,43 @@ SELECT
*
FROM "db1"."tbl" AS "tbl"
CROSS JOIN "db2"."tbl" AS "tbl_2";
+
+SELECT
+*,
+IFF(
+ IFF(
+ uploaded_at >= '2022-06-16',
+ 'workday',
+ 'bamboohr'
+ ) = source_system,
+ 1,
+ 0
+) AS sort_order
+FROM
+unioned
+WHERE
+(
+ source_system = 'workday'
+ AND '9999-01-01' >= '2022-06-16'
+)
+OR (
+ source_system = 'bamboohr'
+ AND '0001-01-01' < '2022-06-16'
+) QUALIFY ROW_NUMBER() OVER (
+ PARTITION BY unique_filter_key
+ ORDER BY
+ sort_order DESC,
+ 1
+) = 1;
+SELECT
+ *,
+ IFF(
+ IFF("unioned"."uploaded_at" >= '2022-06-16', 'workday', 'bamboohr') = "unioned"."source_system",
+ 1,
+ 0
+ ) AS "sort_order"
+FROM "unioned" AS "unioned"
+WHERE
+ "unioned"."source_system" = 'bamboohr' OR "unioned"."source_system" = 'workday'
+QUALIFY
+ ROW_NUMBER() OVER (PARTITION BY "unioned"."unique_filter_key" ORDER BY "unioned"."sort_order" DESC, 1) = 1;