diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 16:13:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 16:13:01 +0000 |
commit | a7044b672667f2a0b48bd0b326b5a55b0815ef79 (patch) | |
tree | 4fb5238d47fb4709d47f766a74b8bbaa9c6f17d8 /sqlglot/dialects/spark2.py | |
parent | Releasing debian version 23.12.1-1. (diff) | |
download | sqlglot-a7044b672667f2a0b48bd0b326b5a55b0815ef79.tar.xz sqlglot-a7044b672667f2a0b48bd0b326b5a55b0815ef79.zip |
Merging upstream version 23.13.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/spark2.py')
-rw-r--r-- | sqlglot/dialects/spark2.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sqlglot/dialects/spark2.py b/sqlglot/dialects/spark2.py index 5264f39..9030d32 100644 --- a/sqlglot/dialects/spark2.py +++ b/sqlglot/dialects/spark2.py @@ -259,12 +259,15 @@ class Spark2(Hive): return Generator.struct_sql(self, expression) def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str: - if is_parse_json(expression.this): + arg = expression.this + is_json_extract = isinstance(arg, (exp.JSONExtract, exp.JSONExtractScalar)) + + if is_parse_json(arg) or is_json_extract: schema = f"'{self.sql(expression, 'to')}'" - return self.func("FROM_JSON", expression.this.this, schema) + return self.func("FROM_JSON", arg if is_json_extract else arg.this, schema) if is_parse_json(expression): - return self.func("TO_JSON", expression.this) + return self.func("TO_JSON", arg) return super(Hive.Generator, self).cast_sql(expression, safe_prefix=safe_prefix) |