Skip to content

Commit

Permalink
Bump sqlglot from 25.8.1 to 25.35.0 (#1205)
Browse files Browse the repository at this point in the history
Co-authored-by: sundar.shankar <[email protected]>
Co-authored-by: SundarShankar89 <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent cf04ded commit d4ad0cd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class SnowflakeCallMapper extends ir.CallMapper with ir.IRHelpers {

private def regexpExtract(args: Seq[ir.Expression]): ir.Expression = {
if (args.size == 2) {
ir.RegExpExtract(args.head, args(1), oneLiteral)
ir.RegExpExtract(args.head, args(1), zeroLiteral)
} else if (args.size == 3) {
ir.RegExpExtract(args.head, args(1), args(2))
} else {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ classifiers = [
]
dependencies = [
"databricks-sdk~=0.29.0",
"sqlglot==25.8.1",
"sqlglot==25.30.0",
"databricks-labs-blueprint[yaml]>=0.2.3",
"databricks-labs-lsql>=0.7.5",
"cryptography>=41.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/databricks/labs/remorph/snow/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def delete_sql(self, expression: exp.Delete) -> str:

return self.prepend_ctes(expression, f"DELETE{tables}{expression_sql};")

def converttimezone_sql(self, expression: local_expression.ConvertTimeZone):
def converttimezone_sql(self, expression: exp.ConvertTimezone):
func = "CONVERT_TIMEZONE"
expr = expression.args["tgtTZ"]
if len(expression.args) == 3 and expression.args.get("this"):
Expand Down
4 changes: 4 additions & 0 deletions src/databricks/labs/remorph/snow/local_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class TryToDate(Func):
arg_types = {"this": True, "format": False}


class TryToTimestamp(Func):
arg_types = {"this": True, "format": False}


class SplitPart(Func):
arg_types = {"this": True, "expression": False, "partNum": False}

Expand Down
9 changes: 9 additions & 0 deletions src/databricks/labs/remorph/snow/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ def _parse_split_part(args: list) -> local_expression.SplitPart:
return local_expression.SplitPart(this=seq_get(args, 0), expression=seq_get(args, 1), partNum=part_num)


def _div0_to_if(args: list) -> exp.If:
cond = exp.EQ(this=seq_get(args, 1), expression=exp.Literal.number(0))
true = exp.Literal.number(0)
false = exp.Div(this=seq_get(args, 0), expression=seq_get(args, 1))
return exp.If(this=cond, true=true, false=false)


def _div0null_to_if(args: list) -> exp.If:
cond = exp.Or(
this=exp.EQ(this=seq_get(args, 1), expression=exp.Literal.number(0)),
Expand Down Expand Up @@ -346,6 +353,7 @@ class Parser(Snowflake.Parser):
"DATE_FROM_PARTS": local_expression.MakeDate.from_arg_list,
"CONVERT_TIMEZONE": local_expression.ConvertTimeZone.from_arg_list,
"TRY_TO_DATE": local_expression.TryToDate.from_arg_list,
"TRY_TO_TIMESTAMP": local_expression.TryToTimestamp.from_arg_list,
"STRTOK": local_expression.StrTok.from_arg_list,
"SPLIT_PART": _parse_split_part,
"TIMESTAMPADD": _parse_date_add,
Expand All @@ -355,6 +363,7 @@ class Parser(Snowflake.Parser):
"DATEADD": parse_date_delta(exp.DateAdd, unit_mapping=DATE_DELTA_INTERVAL),
"DATEDIFF": parse_date_delta(exp.DateDiff, unit_mapping=DATE_DELTA_INTERVAL),
"IS_INTEGER": local_expression.IsInteger.from_arg_list,
"DIV0": _div0_to_if,
"DIV0NULL": _div0null_to_if,
"JSON_EXTRACT_PATH_TEXT": _parse_json_extract_path_text,
"BITOR_AGG": local_expression.BitOr.from_arg_list,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
SELECT regexp_substr(col1, '(E|e)rror') AS regexp_substr_col1 FROM tabl;

-- databricks sql:
SELECT REGEXP_EXTRACT(col1, '(E|e)rror') AS regexp_substr_col1 FROM tabl;
SELECT REGEXP_EXTRACT(col1, '(E|e)rror', 0) AS regexp_substr_col1 FROM tabl;
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ select id, string1,
-- databricks sql:

select id, string1,
REGEXP_EXTRACT(string1, 'the\\W+\\w+') as `SUBSTRING`
REGEXP_EXTRACT(string1, 'the\\W+\\w+', 0) as `SUBSTRING`
from demo2;

0 comments on commit d4ad0cd

Please sign in to comment.