Skip to content

Commit

Permalink
Fix(redshift): add support for Oracle style outer join markers #3611 (#…
Browse files Browse the repository at this point in the history
…3612)

Co-authored-by: Sandeep <[email protected]>
  • Loading branch information
sandband and sandband authored Jun 7, 2024
1 parent 4b30b87 commit 514b3a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sqlglot/dialects/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def _parse_approximate_count(self) -> t.Optional[exp.ApproxDistinct]:
self._retreat(index)
return None

def _parse_column(self) -> t.Optional[exp.Expression]:
column = super()._parse_column()
if column:
column.set("join_mark", self._match(TokenType.JOIN_MARKER))
return column

class Tokenizer(Postgres.Tokenizer):
BIT_STRINGS = []
HEX_STRINGS = []
Expand All @@ -128,6 +134,7 @@ class Tokenizer(Postgres.Tokenizer):
"UNLOAD": TokenType.COMMAND,
"VARBYTE": TokenType.VARBINARY,
"MINUS": TokenType.EXCEPT,
"(+)": TokenType.JOIN_MARKER,
}
KEYWORDS.pop("VALUES")

Expand All @@ -148,6 +155,7 @@ class Generator(Postgres.Generator):
HEX_FUNC = "TO_HEX"
# Redshift doesn't have `WITH` as part of their with_properties so we remove it
WITH_PROPERTIES_PREFIX = " "
COLUMN_JOIN_MARKS_SUPPORTED = True

TYPE_MAPPING = {
**Postgres.Generator.TYPE_MAPPING,
Expand Down
6 changes: 6 additions & 0 deletions tests/dialects/test_redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,9 @@ def test_column_unnesting(self):
self.assertEqual(
ast.sql("redshift"), "SELECT * FROM x AS a, a.b AS c, c.d.e AS f, f.g.h.i.j.k AS l"
)

def test_join_markers(self):
self.validate_identity(
"select a.foo, b.bar, a.baz from a, b where a.baz = b.baz (+)",
"SELECT a.foo, b.bar, a.baz FROM a, b WHERE a.baz = b.baz (+)",
)

0 comments on commit 514b3a5

Please sign in to comment.