summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/dialects')
-rw-r--r--sqlglot/dialects/bigquery.py6
-rw-r--r--sqlglot/dialects/mysql.py5
-rw-r--r--sqlglot/dialects/postgres.py5
-rw-r--r--sqlglot/dialects/snowflake.py10
-rw-r--r--sqlglot/dialects/spark.py7
-rw-r--r--sqlglot/dialects/teradata.py1
6 files changed, 30 insertions, 4 deletions
diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py
index a75e802..32b5147 100644
--- 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 BigQuery(Dialect):
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,
diff --git a/sqlglot/dialects/mysql.py b/sqlglot/dialects/mysql.py
index 235eb77..836bf3c 100644
--- a/sqlglot/dialects/mysql.py
+++ b/sqlglot/dialects/mysql.py
@@ -462,6 +462,11 @@ class MySQL(Dialect):
TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
+ PROPERTIES_LOCATION = {
+ **generator.Generator.PROPERTIES_LOCATION, # type: ignore
+ exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
+ }
+
def show_sql(self, expression):
this = f" {expression.name}"
full = " FULL" if expression.args.get("full") else ""
diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py
index 7612330..3507cb5 100644
--- a/sqlglot/dialects/postgres.py
+++ b/sqlglot/dialects/postgres.py
@@ -318,3 +318,8 @@ class Postgres(Dialect):
if isinstance(seq_get(e.expressions, 0), exp.Select)
else f"{self.normalize_func('ARRAY')}[{self.expressions(e, flat=True)}]",
}
+
+ PROPERTIES_LOCATION = {
+ **generator.Generator.PROPERTIES_LOCATION, # type: ignore
+ exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
+ }
diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
index 9342865..5931364 100644
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -150,6 +150,10 @@ class Snowflake(Dialect):
FUNCTIONS = {
**parser.Parser.FUNCTIONS,
"ARRAYAGG": exp.ArrayAgg.from_arg_list,
+ "DATE_TRUNC": lambda args: exp.DateTrunc(
+ unit=exp.Literal.string(seq_get(args, 0).name), # type: ignore
+ this=seq_get(args, 1),
+ ),
"IFF": exp.If.from_arg_list,
"TO_TIMESTAMP": _snowflake_to_timestamp,
"ARRAY_CONSTRUCT": exp.Array.from_arg_list,
@@ -215,7 +219,6 @@ class Snowflake(Dialect):
}
class Generator(generator.Generator):
- CREATE_TRANSIENT = True
PARAMETER_TOKEN = "$"
TRANSFORMS = {
@@ -252,6 +255,11 @@ class Snowflake(Dialect):
"replace": "RENAME",
}
+ PROPERTIES_LOCATION = {
+ **generator.Generator.PROPERTIES_LOCATION, # type: ignore
+ exp.SetProperty: exp.Properties.Location.UNSUPPORTED,
+ }
+
def ilikeany_sql(self, expression: exp.ILikeAny) -> str:
return self.binary(expression, "ILIKE ANY")
diff --git a/sqlglot/dialects/spark.py b/sqlglot/dialects/spark.py
index dd3e0c8..05ee53f 100644
--- a/sqlglot/dialects/spark.py
+++ b/sqlglot/dialects/spark.py
@@ -8,9 +8,12 @@ from sqlglot.helper import seq_get
def _create_sql(self, e):
kind = e.args.get("kind")
- temporary = e.args.get("temporary")
+ properties = e.args.get("properties")
- if kind.upper() == "TABLE" and temporary is True:
+ if kind.upper() == "TABLE" and any(
+ isinstance(prop, exp.TemporaryProperty)
+ for prop in (properties.expressions if properties else [])
+ ):
return f"CREATE TEMPORARY VIEW {self.sql(e, 'this')} AS {self.sql(e, 'expression')}"
return create_with_partitions_sql(self, e)
diff --git a/sqlglot/dialects/teradata.py b/sqlglot/dialects/teradata.py
index e3eec71..7953bc5 100644
--- a/sqlglot/dialects/teradata.py
+++ b/sqlglot/dialects/teradata.py
@@ -114,6 +114,7 @@ class Teradata(Dialect):
PROPERTIES_LOCATION = {
**generator.Generator.PROPERTIES_LOCATION, # type: ignore
exp.PartitionedByProperty: exp.Properties.Location.POST_INDEX,
+ exp.VolatilityProperty: exp.Properties.Location.POST_CREATE,
}
def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str: