Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions sqlglot/dialects/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
from collections import defaultdict
import typing as t

from sqlglot import exp, transforms, jsonpath, parser
from sqlglot.dialects.dialect import (
Expand Down Expand Up @@ -75,6 +76,20 @@ class Parser(Spark.Parser):
),
}

def _parse_overlay(self) -> exp.Overlay:
def _parse_overlay_arg(text: str) -> t.Optional[exp.Expression]:
return (
self._match(TokenType.COMMA) or self._match_text_seq(text)
) and self._parse_bitwise()

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

class Generator(Spark.Generator):
TABLESAMPLE_SEED_KEYWORD = "REPEATABLE"
COPY_PARAMS_ARE_WRAPPED = False
Expand Down
15 changes: 15 additions & 0 deletions tests/dialects/test_databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,18 @@ 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_identity(
"SELECT OVERLAY('Spark SQL', 'ANSI ', 7, 0)",
"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)",
)