diff options
Diffstat (limited to 'sqlglot/dialects/presto.py')
-rw-r--r-- | sqlglot/dialects/presto.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sqlglot/dialects/presto.py b/sqlglot/dialects/presto.py index 52a04a4..d839864 100644 --- a/sqlglot/dialects/presto.py +++ b/sqlglot/dialects/presto.py @@ -8,10 +8,12 @@ from sqlglot.dialects.dialect import ( date_trunc_to_time, format_time_lambda, if_sql, + left_to_substring_sql, no_ilike_sql, no_pivot_sql, no_safe_divide_sql, rename_func, + right_to_substring_sql, struct_extract_sql, timestamptrunc_sql, timestrtotime_sql, @@ -30,7 +32,7 @@ def _approx_distinct_sql(self: generator.Generator, expression: exp.ApproxDistin def _datatype_sql(self: generator.Generator, expression: exp.DataType) -> str: sql = self.datatype_sql(expression) - if expression.this == exp.DataType.Type.TIMESTAMPTZ: + if expression.is_type("timestamptz"): sql = f"{sql} WITH TIME ZONE" return sql @@ -240,6 +242,7 @@ class Presto(Dialect): INTERVAL_ALLOWS_PLURAL_FORM = False JOIN_HINTS = False TABLE_HINTS = False + IS_BOOL = False STRUCT_DELIMITER = ("(", ")") PROPERTIES_LOCATION = { @@ -272,6 +275,7 @@ class Presto(Dialect): exp.BitwiseOr: lambda self, e: f"BITWISE_OR({self.sql(e, 'this')}, {self.sql(e, 'expression')})", exp.BitwiseRightShift: lambda self, e: f"BITWISE_ARITHMETIC_SHIFT_RIGHT({self.sql(e, 'this')}, {self.sql(e, 'expression')})", exp.BitwiseXor: lambda self, e: f"BITWISE_XOR({self.sql(e, 'this')}, {self.sql(e, 'expression')})", + exp.Cast: transforms.preprocess([transforms.epoch_cast_to_ts]), exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP", exp.DataType: _datatype_sql, exp.DateAdd: lambda self, e: self.func( @@ -292,11 +296,13 @@ class Presto(Dialect): exp.ILike: no_ilike_sql, exp.Initcap: _initcap_sql, exp.Lateral: _explode_to_unnest_sql, + exp.Left: left_to_substring_sql, exp.Levenshtein: rename_func("LEVENSHTEIN_DISTANCE"), exp.LogicalAnd: rename_func("BOOL_AND"), exp.LogicalOr: rename_func("BOOL_OR"), exp.Pivot: no_pivot_sql, exp.Quantile: _quantile_sql, + exp.Right: right_to_substring_sql, exp.SafeDivide: no_safe_divide_sql, exp.Schema: _schema_sql, exp.Select: transforms.preprocess( @@ -319,6 +325,7 @@ class Presto(Dialect): exp.TimeStrToUnix: lambda self, e: f"TO_UNIXTIME(DATE_PARSE({self.sql(e, 'this')}, {Presto.time_format}))", exp.TimeToStr: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", exp.TimeToUnix: rename_func("TO_UNIXTIME"), + exp.TryCast: transforms.preprocess([transforms.epoch_cast_to_ts]), exp.TsOrDiToDi: lambda self, e: f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS VARCHAR), '-', ''), 1, 8) AS INT)", exp.TsOrDsAdd: _ts_or_ds_add_sql, exp.TsOrDsToDate: _ts_or_ds_to_date_sql, @@ -356,7 +363,7 @@ class Presto(Dialect): else: target_type = None - if target_type and target_type.is_type(exp.DataType.Type.TIMESTAMP): + if target_type and target_type.is_type("timestamp"): to = target_type.copy() if target_type is start.to: |