diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-17 09:15:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-17 09:15:19 +0000 |
commit | 5ac403c53fc7e610ee679587187546a61e2e342b (patch) | |
tree | 819e7e322201cb0206e429e6590ae85f3676e68d /tests/dialects/test_oracle.py | |
parent | Releasing debian version 25.0.3-1. (diff) | |
download | sqlglot-5ac403c53fc7e610ee679587187546a61e2e342b.tar.xz sqlglot-5ac403c53fc7e610ee679587187546a61e2e342b.zip |
Merging upstream version 25.1.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/dialects/test_oracle.py')
-rw-r--r-- | tests/dialects/test_oracle.py | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/tests/dialects/test_oracle.py b/tests/dialects/test_oracle.py index 526b0b5..7cc4d72 100644 --- a/tests/dialects/test_oracle.py +++ b/tests/dialects/test_oracle.py @@ -1,5 +1,5 @@ -from sqlglot import exp -from sqlglot.errors import UnsupportedError +from sqlglot import exp, UnsupportedError +from sqlglot.dialects.oracle import eliminate_join_marks from tests.dialects.test_dialect import Validator @@ -43,6 +43,7 @@ class TestOracle(Validator): self.validate_identity("SELECT * FROM table_name SAMPLE (25) s") self.validate_identity("SELECT COUNT(*) * 10 FROM orders SAMPLE (10) SEED (1)") self.validate_identity("SELECT * FROM V$SESSION") + self.validate_identity("SELECT TO_DATE('January 15, 1989, 11:00 A.M.')") self.validate_identity( "SELECT last_name, employee_id, manager_id, LEVEL FROM employees START WITH employee_id = 100 CONNECT BY PRIOR employee_id = manager_id ORDER SIBLINGS BY last_name" ) @@ -249,7 +250,8 @@ class TestOracle(Validator): self.validate_identity("SELECT e1.x, e2.x FROM e e1, e e2 WHERE e1.y (+) = e2.y") self.validate_all( - "SELECT e1.x, e2.x FROM e e1, e e2 WHERE e1.y = e2.y (+)", write={"": UnsupportedError} + "SELECT e1.x, e2.x FROM e e1, e e2 WHERE e1.y = e2.y (+)", + write={"": UnsupportedError}, ) self.validate_all( "SELECT e1.x, e2.x FROM e e1, e e2 WHERE e1.y = e2.y (+)", @@ -413,3 +415,65 @@ WHERE for query in (f"{body}{start}{connect}", f"{body}{connect}{start}"): self.validate_identity(query, pretty, pretty=True) + + def test_eliminate_join_marks(self): + test_sql = [ + ( + "SELECT T1.d, T2.c FROM T1, T2 WHERE T1.x = T2.x (+) and T2.y (+) > 5", + "SELECT T1.d, T2.c FROM T1 LEFT JOIN T2 ON T1.x = T2.x AND T2.y > 5", + ), + ( + "SELECT T1.d, T2.c FROM T1, T2 WHERE T1.x = T2.x (+) and T2.y (+) IS NULL", + "SELECT T1.d, T2.c FROM T1 LEFT JOIN T2 ON T1.x = T2.x AND T2.y IS NULL", + ), + ( + "SELECT T1.d, T2.c FROM T1, T2 WHERE T1.x = T2.x (+) and T2.y IS NULL", + "SELECT T1.d, T2.c FROM T1 LEFT JOIN T2 ON T1.x = T2.x WHERE T2.y IS NULL", + ), + ( + "SELECT T1.d, T2.c FROM T1, T2 WHERE T1.x = T2.x (+) and T1.Z > 4", + "SELECT T1.d, T2.c FROM T1 LEFT JOIN T2 ON T1.x = T2.x WHERE T1.Z > 4", + ), + ( + "SELECT * FROM table1, table2 WHERE table1.column = table2.column(+)", + "SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column", + ), + ( + "SELECT * FROM table1, table2, table3, table4 WHERE table1.column = table2.column(+) and table2.column >= table3.column(+) and table1.column = table4.column(+)", + "SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column LEFT JOIN table3 ON table2.column >= table3.column LEFT JOIN table4 ON table1.column = table4.column", + ), + ( + "SELECT * FROM table1, table2, table3 WHERE table1.column = table2.column(+) and table2.column >= table3.column(+)", + "SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column LEFT JOIN table3 ON table2.column >= table3.column", + ), + ( + "SELECT table1.id, table2.cloumn1, table3.id FROM table1, table2, (SELECT tableInner1.id FROM tableInner1, tableInner2 WHERE tableInner1.id = tableInner2.id(+)) AS table3 WHERE table1.id = table2.id(+) and table1.id = table3.id(+)", + "SELECT table1.id, table2.cloumn1, table3.id FROM table1 LEFT JOIN table2 ON table1.id = table2.id LEFT JOIN (SELECT tableInner1.id FROM tableInner1 LEFT JOIN tableInner2 ON tableInner1.id = tableInner2.id) table3 ON table1.id = table3.id", + ), + # 2 join marks on one side of predicate + ( + "SELECT * FROM table1, table2 WHERE table1.column = table2.column1(+) + table2.column2(+)", + "SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column1 + table2.column2", + ), + # join mark and expression + ( + "SELECT * FROM table1, table2 WHERE table1.column = table2.column1(+) + 25", + "SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column1 + 25", + ), + ] + + for original, expected in test_sql: + with self.subTest(original): + self.assertEqual( + eliminate_join_marks(self.parse_one(original)).sql(dialect=self.dialect), + expected, + ) + + def test_query_restrictions(self): + for restriction in ("READ ONLY", "CHECK OPTION"): + for constraint_name in (" CONSTRAINT name", ""): + with self.subTest(f"Restriction: {restriction}"): + self.validate_identity(f"SELECT * FROM tbl WITH {restriction}{constraint_name}") + self.validate_identity( + f"CREATE VIEW view AS SELECT * FROM tbl WITH {restriction}{constraint_name}" + ) |