From b38d717d5933fdae3fe85c87df7aee9a251fb58e Mon Sep 17 00:00:00 2001
From: Daniel Baumann <daniel.baumann@progress-linux.org>
Date: Mon, 3 Apr 2023 09:31:54 +0200
Subject: Merging upstream version 11.4.5.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
---
 tests/fixtures/optimizer/optimizer.sql | 40 ++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

(limited to 'tests/fixtures/optimizer/optimizer.sql')

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;
-- 
cgit v1.2.3

