summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/spark2.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sqlglot/dialects/spark2.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/sqlglot/dialects/spark2.py b/sqlglot/dialects/spark2.py
index 4489b6b..56d33ba 100644
--- a/sqlglot/dialects/spark2.py
+++ b/sqlglot/dialects/spark2.py
@@ -7,6 +7,7 @@ from sqlglot.dialects.dialect import (
binary_from_function,
create_with_partitions_sql,
format_time_lambda,
+ is_parse_json,
pivot_column_names,
rename_func,
trim_sql,
@@ -242,10 +243,11 @@ class Spark2(Hive):
CREATE_FUNCTION_RETURN_AS = False
def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
- if isinstance(expression.this, exp.Cast) and expression.this.is_type("json"):
+ if is_parse_json(expression.this):
schema = f"'{self.sql(expression, 'to')}'"
return self.func("FROM_JSON", expression.this.this, schema)
- if expression.is_type("json"):
+
+ if is_parse_json(expression):
return self.func("TO_JSON", expression.this)
return super(Hive.Generator, self).cast_sql(expression, safe_prefix=safe_prefix)