diff options
Diffstat (limited to 'tests/analyser_query_test.ml')
-rw-r--r-- | tests/analyser_query_test.ml | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/tests/analyser_query_test.ml b/tests/analyser_query_test.ml index 0e23f11..c4ab6d8 100644 --- a/tests/analyser_query_test.ml +++ b/tests/analyser_query_test.ml @@ -32,12 +32,12 @@ let select = "Select" >:: fun _ -> let query, _ = Q.select conf in let expected_query = - {|SELECT COALESCE('source'.col_1,'') || ? || '' AS result_0, -'source'.col_2 AS result_1, -'last_file'.col_5 AS result_2 + {|SELECT COALESCE('source'.'col_1','') || ? || '' AS result_0, +'source'.'col_2' AS result_1, +'last_file'.'col_5' AS result_2 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'|} +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'|} in Alcotest.check Alcotest.string "" expected_query query.q @@ -47,11 +47,11 @@ let check_externals = let query = Q.check_external conf (List.hd conf.externals) in let expected_query = - "SELECT 'source'.'id', 'source'.col_1 FROM\n\ - 'source' AS 'source'\n\ - LEFT JOIN 'other' AS 'other' ON rtrim(upper('source'.col_1)) = \ - 'other'.'key_other' WHERE 'other'.'key_other' IS NULL AND 'source'.col_1 \ - IS NOT NULL AND 'source'.col_1 <> ''" + "SELECT 'source'.'id', 'source'.'col_1'\n\ + FROM 'source' AS 'source'\n\ + LEFT JOIN 'other' AS 'other' ON rtrim(upper('source'.'col_1')) = \ + 'other'.'key_other' WHERE 'other'.'key_other' IS NULL AND \ + 'source'.'col_1' IS NOT NULL AND 'source'.'col_1' <> ''" in Alcotest.check Alcotest.string "" expected_query query.q @@ -81,8 +81,8 @@ let previous = let query, _ = ImportAnalyser.Query.select conf in let expected_query = - "SELECT LAG('previous'.col_5) OVER (PARTITION BY 'previous'.col_1 ORDER BY \ - 'previous'.col_3) AS result_0\n\ + "SELECT LAG('previous'.'col_5') OVER (PARTITION BY 'previous'.'col_1' \ + ORDER BY 'previous'.'col_3') AS result_0\n\ FROM 'source' AS 'previous'" in Alcotest.check Alcotest.string "" expected_query query.q @@ -112,7 +112,7 @@ let sum = let query, _ = ImportAnalyser.Query.select conf in let expected_query = - "SELECT SUM('previous'.col_5) OVER (PARTITION BY 'previous'.col_1) AS \ + "SELECT SUM('previous'.'col_5') OVER (PARTITION BY 'previous'.'col_1') AS \ result_0\n\ FROM 'source' AS 'previous'" in @@ -137,7 +137,7 @@ let sum_total = let query, _ = ImportAnalyser.Query.select conf in let expected_query = - "SELECT SUM('previous'.col_5) AS result_0\nFROM 'source' AS 'previous'" + "SELECT SUM('previous'.'col_5') AS result_0\nFROM 'source' AS 'previous'" in Alcotest.check Alcotest.string "" expected_query query.q @@ -166,7 +166,7 @@ let sum_unfiltered = let query, _ = ImportAnalyser.Query.select conf in let expected_query = - "SELECT SUM('previous'.col_5) AS result_0\nFROM 'source' AS 'previous'" + "SELECT SUM('previous'.'col_5') AS result_0\nFROM 'source' AS 'previous'" in Alcotest.check Alcotest.string "" expected_query query.q @@ -206,16 +206,16 @@ let filter_group = let contents, _ = ImportAnalyser.Query.select conf in let expected = - {|WITH cte 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 group0 + {|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') -SELECT 'source'.col_1 AS result_0 +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') +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 'cte' ON cte.id = source.id -WHERE (cte.group0)|} +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|} in Alcotest.check Alcotest.string "" expected contents.q @@ -238,18 +238,16 @@ let filter_group2 = let contents, _ = ImportAnalyser.Query.select conf in let expected = - {|WITH cte 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 group0 + {|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' -WHERE COALESCE('source'.col_3,0)=0) -SELECT 'source'.col_1 AS result_0 +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') +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 'cte' ON cte.id = source.id -WHERE COALESCE('source'.col_3,0)=0 -AND (cte.group0)|} +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 COALESCE('source'.'col_3',0)=0 AND filter0.group_function|} in Alcotest.check Alcotest.string "" expected contents.q |