Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions sqlglot/dialects/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ class Parser(Spark.Parser):
),
}

def _parse_overlay(self) -> exp.Overlay:
this = self._parse_bitwise()

if self._match(TokenType.COMMA):
return self.expression(
exp.Overlay,
this=this,
expression=self._parse_bitwise(),
from_=self._match(TokenType.COMMA) and self._parse_bitwise(),
for_=self._match(TokenType.COMMA) and self._parse_bitwise(),
)

return self.expression(
exp.Overlay,
this=this,
expression=self._match_text_seq("PLACING") and self._parse_bitwise(),
from_=self._match_text_seq("FROM") and self._parse_bitwise(),
for_=self._match_text_seq("FOR") and self._parse_bitwise(),
)

class Generator(Spark.Generator):
TABLESAMPLE_SEED_KEYWORD = "REPEATABLE"
COPY_PARAMS_ARE_WRAPPED = False
Expand Down
17 changes: 17 additions & 0 deletions tests/dialects/test_databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,20 @@ def test_to_char_is_numeric_transpile_to_cast(self):

def test_qdcolon(self):
self.validate_identity("SELECT '20'?::INTEGER", "SELECT TRY_CAST('20' AS INTEGER)")

def test_overlay(self):
self.validate_all(
"SELECT OVERLAY('Spark SQL', 'ANSI ', 7, 0)",
write={
"databricks": "SELECT OVERLAY('Spark SQL' PLACING 'ANSI ' FROM 7 FOR 0)",
},
)
self.validate_identity(
"SELECT OVERLAY('Spark SQL' PLACING 'CORE' FROM 7)",
)
self.validate_identity(
"SELECT OVERLAY(ENCODE('Spark SQL', 'utf-8') PLACING ENCODE('_', 'utf-8') FROM 6)",
)
self.validate_identity(
"SELECT OVERLAY('Spark SQL' PLACING 'ANSI ' FROM 7 FOR 0)",
)