aboutsummaryrefslogtreecommitdiff
path: root/tests/analyser_query_test.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2026-02-06 19:04:27 +0100
committerSébastien Dailly <sebastien@dailly.me>2026-02-07 12:15:00 +0100
commit7a8d35a8a27f4492fbb021e583f30f9a96f10a25 (patch)
treebfdb989ed504944c293366b173a63dfd84343451 /tests/analyser_query_test.ml
parent69d9b6ada15af41fa5db179f71c2bb284c643f96 (diff)
Corrected a bug when mixing plain and group filtersmain
Diffstat (limited to 'tests/analyser_query_test.ml')
-rw-r--r--tests/analyser_query_test.ml45
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/analyser_query_test.ml b/tests/analyser_query_test.ml
index 37a748b..0af6d42 100644
--- a/tests/analyser_query_test.ml
+++ b/tests/analyser_query_test.ml
@@ -227,7 +227,7 @@ WHERE filter0.group_function|}
This generate a CTE expression in order to evaluate the group before loading
the results from the query. *)
let filter_group2 =
- "Test filter_group" >:: fun _ ->
+ "Test filter_group2" >:: fun _ ->
let c col = Expr.path ImportDataTypes.Path.{ alias = None; column = col } in
let conf =
{
@@ -254,6 +254,46 @@ WHERE (COALESCE('source'.'col_3',0)=0) AND filter0.group_function|}
Alcotest.check Alcotest.string "" expected contents.q
+(** Test a group filter, followed by a simple clause and another group : The
+ simple clause is evaluated after the first group, but before the last one *)
+let filter_group3 =
+ "Test filter_group3" >:: fun _ ->
+ let c col = Expr.path ImportDataTypes.Path.{ alias = None; column = col } in
+ let conf =
+ {
+ conf with
+ columns = [ c 1 ];
+ filters =
+ [
+ Expr.(max (c 3) [ c 1 ] [ c 1 ]);
+ Expr.equal (c 3) Expr.integer_zero;
+ Expr.(max (c 3) [ c 1 ] [ c 1 ]);
+ ];
+ }
+ in
+ let contents, _ = ImportAnalyser.Query.select conf in
+
+ let expected =
+ {|WITH filter0 AS (SELECT source.id, (LAST_VALUE('source'.'col_3') OVER (PARTITION BY 'source'.'col_1' ORDER BY 'source'.'col_1' RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)) AS group_function
+FROM 'source' AS 'source'
+LEFT JOIN 'other' AS 'other' ON rtrim(upper('source'.'col_1')) = 'other'.'key_other'
+LEFT JOIN 'last' AS 'last_file' ON rtrim(upper('other'.'col_1')) = 'last_file'.'key_last_file')
+, filter1 AS (SELECT source.id, (LAST_VALUE('source'.'col_3') OVER (PARTITION BY 'source'.'col_1' ORDER BY 'source'.'col_1' RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)) AS group_function
+FROM 'source' AS 'source'
+LEFT JOIN 'other' AS 'other' ON rtrim(upper('source'.'col_1')) = 'other'.'key_other'
+LEFT JOIN 'last' AS 'last_file' ON rtrim(upper('other'.'col_1')) = 'last_file'.'key_last_file'
+INNER JOIN 'filter0' ON filter0.id = source.id
+WHERE filter0.group_function AND (COALESCE('source'.'col_3',0)=0))
+SELECT 'source'.'col_1' AS result_0
+FROM 'source' AS 'source'
+LEFT JOIN 'other' AS 'other' ON rtrim(upper('source'.'col_1')) = 'other'.'key_other'
+LEFT JOIN 'last' AS 'last_file' ON rtrim(upper('other'.'col_1')) = 'last_file'.'key_last_file'
+INNER JOIN 'filter1' ON filter1.id = source.id
+WHERE filter1.group_function|}
+ in
+
+ Alcotest.check Alcotest.string "" expected contents.q
+
(** Add an external with a filter. Ensure the predicate is reported in the
query. *)
let external_filter =
@@ -349,9 +389,10 @@ let test_suit =
prepare_insert;
filter_group;
filter_group2;
+ filter_group3;
external_filter;
order_by;
group_by;
]
-let tests = "analyser_query_test" >::: test_suit
+let tests = __FILE__ >::: test_suit