diff options
Diffstat (limited to 'tests/analyser_query_test.ml')
| -rw-r--r-- | tests/analyser_query_test.ml | 45 |
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 |
