diff options
Diffstat (limited to 'sqlglot/dialects/spark2.py')
-rw-r--r-- | sqlglot/dialects/spark2.py | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/sqlglot/dialects/spark2.py b/sqlglot/dialects/spark2.py index 912b86b..bf24240 100644 --- a/sqlglot/dialects/spark2.py +++ b/sqlglot/dialects/spark2.py @@ -110,11 +110,6 @@ class Spark2(Hive): **Hive.Parser.FUNCTIONS, "MAP_FROM_ARRAYS": exp.Map.from_arg_list, "TO_UNIX_TIMESTAMP": exp.StrToUnix.from_arg_list, - "LEFT": lambda args: exp.Substring( - this=seq_get(args, 0), - start=exp.Literal.number(1), - length=seq_get(args, 1), - ), "SHIFTLEFT": lambda args: exp.BitwiseLeftShift( this=seq_get(args, 0), expression=seq_get(args, 1), @@ -123,14 +118,6 @@ class Spark2(Hive): this=seq_get(args, 0), expression=seq_get(args, 1), ), - "RIGHT": lambda args: exp.Substring( - this=seq_get(args, 0), - start=exp.Sub( - this=exp.Length(this=seq_get(args, 0)), - expression=exp.Add(this=seq_get(args, 1), expression=exp.Literal.number(1)), - ), - length=seq_get(args, 1), - ), "APPROX_PERCENTILE": exp.ApproxQuantile.from_arg_list, "IIF": exp.If.from_arg_list, "AGGREGATE": exp.Reduce.from_arg_list, @@ -240,17 +227,17 @@ class Spark2(Hive): TRANSFORMS.pop(exp.ArrayJoin) TRANSFORMS.pop(exp.ArraySort) TRANSFORMS.pop(exp.ILike) + TRANSFORMS.pop(exp.Left) + TRANSFORMS.pop(exp.Right) WRAP_DERIVED_VALUES = False CREATE_FUNCTION_RETURN_AS = False def cast_sql(self, expression: exp.Cast) -> str: - if isinstance(expression.this, exp.Cast) and expression.this.is_type( - exp.DataType.Type.JSON - ): + if isinstance(expression.this, exp.Cast) and expression.this.is_type("json"): schema = f"'{self.sql(expression, 'to')}'" return self.func("FROM_JSON", expression.this.this, schema) - if expression.to.is_type(exp.DataType.Type.JSON): + if expression.is_type("json"): return self.func("TO_JSON", expression.this) return super(Hive.Generator, self).cast_sql(expression) @@ -260,7 +247,7 @@ class Spark2(Hive): expression, sep=": " if isinstance(expression.parent, exp.DataType) - and expression.parent.is_type(exp.DataType.Type.STRUCT) + and expression.parent.is_type("struct") else sep, ) |