Skip to content

Commit

Permalink
Fix: handle empty string in connector comment padding (#3437)
Browse files Browse the repository at this point in the history
* handle empty string in pad_comment  + staticmethod

* tests added for pad_comment

* style

* for now:
1. removing staticmethod
2. generator object only once

* style

* style

* redundant import

* test case for empty comment

* styling
  • Loading branch information
uncledata committed May 9, 2024
1 parent 761ba6f commit a2a6eaa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sqlglot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,8 @@ def connector_sql(
stack.append(expression.right)
if expression.comments and self.comments:
for comment in expression.comments:
op += f" /*{self.pad_comment(comment)}*/"
if comment:
op += f" /*{self.pad_comment(comment)}*/"
stack.extend((op, expression.left))
return op

Expand Down
7 changes: 7 additions & 0 deletions tests/test_transpile.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,13 @@ def test_comments(self):
pretty=True,
)

self.validate(
"""SELECT X FROM catalog.db.table WHERE Y
--
AND Z""",
"""SELECT X FROM catalog.db.table WHERE Y AND Z""",
)

def test_types(self):
self.validate("INT 1", "CAST(1 AS INT)")
self.validate("VARCHAR 'x' y", "CAST('x' AS VARCHAR) AS y")
Expand Down

0 comments on commit a2a6eaa

Please sign in to comment.