Skip to content

Commit ecd325b

Browse files
authored
fix(databricks): support IFF as a synonym for IF [CLAUDE] (#7488)
Databricks supports IFF as a synonym for the IF function. This adds IFF to the Databricks parser's FUNCTIONS mapping so it correctly parses to exp.If and transpiles to other dialects. Closes #7347
1 parent c26a573 commit ecd325b

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

sqlglot/parsers/databricks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class DatabricksParser(SparkParser):
1414

1515
FUNCTIONS = {
1616
**SparkParser.FUNCTIONS,
17+
"IFF": exp.If.from_arg_list,
1718
"GETDATE": exp.CurrentTimestamp.from_arg_list,
1819
"DATEADD": build_date_delta(exp.DateAdd),
1920
"DATE_ADD": build_date_delta(exp.DateAdd),

tests/dialects/test_databricks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,17 @@ def test_overlay(self):
491491
"SELECT OVERLAY('Spark SQL' PLACING 'ANSI ' FROM 7 FOR 0)",
492492
)
493493

494+
def test_iff(self):
495+
# IFF is a synonym for IF in Databricks; it normalizes to IF on output
496+
self.validate_all(
497+
"SELECT IF(x > 0, 'positive', 'non-positive')",
498+
read={"databricks": "SELECT IFF(x > 0, 'positive', 'non-positive')"},
499+
write={
500+
"databricks": "SELECT IF(x > 0, 'positive', 'non-positive')",
501+
"snowflake": "SELECT IFF(x > 0, 'positive', 'non-positive')",
502+
},
503+
)
504+
494505
def test_declare(self):
495506
self.validate_identity("DECLARE VAR x INT", "DECLARE x INT")
496507
self.validate_identity("DECLARE x INT")

0 commit comments

Comments
 (0)