Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for old (+) join syntax #1224

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sqlglot/dialects/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class Parser(parser.Parser):
"XMLTABLE": _parse_xml_table,
}

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 Generator(generator.Generator):
LOCKING_READS_SUPPORTED = True

Expand Down Expand Up @@ -142,6 +148,10 @@ def offset_sql(self, expression: exp.Offset) -> str:
def table_sql(self, expression: exp.Table, sep: str = " ") -> str:
return super().table_sql(expression, sep=sep)

def column_sql(self, expression: exp.Column) -> str:
column = super().column_sql(expression)
return f"{column} (+)" if expression.args.get("join_mark") else column

def xmltable_sql(self, expression: exp.XMLTable) -> str:
this = self.sql(expression, "this")
passing = self.expressions(expression, "passing")
Expand All @@ -156,6 +166,7 @@ def xmltable_sql(self, expression: exp.XMLTable) -> str:
class Tokenizer(tokens.Tokenizer):
KEYWORDS = {
**tokens.Tokenizer.KEYWORDS,
"(+)": TokenType.JOIN_MARKER,
"COLUMNS": TokenType.COLUMN,
"MATCH_RECOGNIZE": TokenType.MATCH_RECOGNIZE,
"MINUS": TokenType.EXCEPT,
Expand Down
2 changes: 1 addition & 1 deletion sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ class ByteString(Condition):


class Column(Condition):
arg_types = {"this": True, "table": False, "db": False, "catalog": False}
arg_types = {"this": True, "table": False, "db": False, "catalog": False, "join_mark": False}

@property
def table(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions sqlglot/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class TokenType(AutoName):
IS = auto()
ISNULL = auto()
JOIN = auto()
JOIN_MARKER = auto()
LANGUAGE = auto()
LATERAL = auto()
LAZY = auto()
Expand Down
5 changes: 5 additions & 0 deletions tests/dialects/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ class TestOracle(Validator):
def test_oracle(self):
self.validate_identity("SELECT * FROM V$SESSION")

def test_join_marker(self):
self.validate_identity("SELECT e1.x, e2.x FROM e e1, e e2 WHERE e1.y (+) = e2.y")
self.validate_identity("SELECT e1.x, e2.x FROM e e1, e e2 WHERE e1.y = e2.y (+)")
self.validate_identity("SELECT e1.x, e2.x FROM e e1, e e2 WHERE e1.y (+) = e2.y (+)")

def test_xml_table(self):
self.validate_identity("XMLTABLE('x')")
self.validate_identity("XMLTABLE('x' RETURNING SEQUENCE BY REF)")
Expand Down