Repository: tobymao/sqlglot

Issue:
TS_OR_DS_ADD function in transpiled sql
Similar to #1195 - would it be possible to add this DATE_ADD function please?

```py
import sqlglot

sql = "SELECT date_add(my_date_column, 1)"
bq_sql = sqlglot.transpile(sql, read="spark", write="bigquery")[0]
print(bq_sql)
```
which returns: `SELECT TS_OR_DS_ADD(my_date_column, 1, 'DAY')`

the correct code is: `SELECT DATE_ADD(my_date_column, INTERVAL 1 DAY)`

thank you!!


Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py
--- a/sqlglot/dialects/bigquery.py
+++ b/sqlglot/dialects/bigquery.py
@@ -38,7 +38,10 @@ def _date_add_sql(
 ) -> t.Callable[[generator.Generator, exp.Expression], str]:
     def func(self, expression):
         this = self.sql(expression, "this")
-        return f"{data_type}_{kind}({this}, {self.sql(exp.Interval(this=expression.expression, unit=expression.args.get('unit') or exp.Literal.string('day')))})"
+        unit = expression.args.get("unit")
+        unit = exp.var(unit.name.upper() if unit else "DAY")
+        interval = exp.Interval(this=expression.expression, unit=unit)
+        return f"{data_type}_{kind}({this}, {self.sql(interval)})"
 
     return func
 
@@ -235,6 +238,7 @@ class Generator(generator.Generator):
             exp.TimestampSub: _date_add_sql("TIMESTAMP", "SUB"),
             exp.TimeStrToTime: timestrtotime_sql,
             exp.TsOrDsToDate: ts_or_ds_to_date_sql("bigquery"),
+            exp.TsOrDsAdd: _date_add_sql("DATE", "ADD"),
             exp.PartitionedByProperty: lambda self, e: f"PARTITION BY {self.sql(e, 'this')}",
             exp.VariancePop: rename_func("VAR_POP"),
             exp.Values: _derived_table_values_to_unnest,


Test patch:
diff --git a/tests/dialects/test_dialect.py b/tests/dialects/test_dialect.py
--- a/tests/dialects/test_dialect.py
+++ b/tests/dialects/test_dialect.py
@@ -513,7 +513,7 @@ def test_time(self):
                 "starrocks": "DATE_ADD(x, INTERVAL 1 DAY)",
             },
             write={
-                "bigquery": "DATE_ADD(x, INTERVAL 1 'day')",
+                "bigquery": "DATE_ADD(x, INTERVAL 1 DAY)",
                 "drill": "DATE_ADD(x, INTERVAL 1 DAY)",
                 "duckdb": "x + INTERVAL 1 day",
                 "hive": "DATE_ADD(x, 1)",
@@ -530,7 +530,7 @@ def test_time(self):
         self.validate_all(
             "DATE_ADD(x, 1)",
             write={
-                "bigquery": "DATE_ADD(x, INTERVAL 1 'day')",
+                "bigquery": "DATE_ADD(x, INTERVAL 1 DAY)",
                 "drill": "DATE_ADD(x, INTERVAL 1 DAY)",
                 "duckdb": "x + INTERVAL 1 DAY",
                 "hive": "DATE_ADD(x, 1)",
diff --git a/tests/dialects/test_spark.py b/tests/dialects/test_spark.py
--- a/tests/dialects/test_spark.py
+++ b/tests/dialects/test_spark.py
@@ -213,6 +213,13 @@ def test_spark(self):
         self.validate_identity("TRIM(LEADING 'SL' FROM 'SSparkSQLS')")
         self.validate_identity("TRIM(TRAILING 'SL' FROM 'SSparkSQLS')")
 
+        self.validate_all(
+            "SELECT DATE_ADD(my_date_column, 1)",
+            write={
+                "spark": "SELECT DATE_ADD(my_date_column, 1)",
+                "bigquery": "SELECT DATE_ADD(my_date_column, INTERVAL 1 DAY)",
+            },
+        )
         self.validate_all(
             "AGGREGATE(my_arr, 0, (acc, x) -> acc + x, s -> s * 2)",
             write={