You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Lauri Koobas (Jira)" <ji...@apache.org> on 2021/04/08 17:38:00 UTC
[jira] [Updated] (SPARK-34993) from_json() acts differently on
created and literal strings with backslashes
[ https://issues.apache.org/jira/browse/SPARK-34993?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Lauri Koobas updated SPARK-34993:
---------------------------------
Description:
JSON string with the value that contains backslashes fails to be recovered by `from_json()`.
I found that if the same string is created with `to_json(named_struct())` then it actually does work.
The following code to reproduce. I would expect all of these methods to return the same (correct) result:
{code:java}
select to_json(named_struct('msg', ''))
, schema_of_json(to_json(named_struct('msg', '')))
, from_json(to_json(named_struct('msg', '')), schema_of_json(to_json(named_struct('msg', ''))))
, from_json('{"msg":""}', schema_of_json(to_json(named_struct('msg', ''))))
, from_json('{"msg":""}', 'msg string')
{code}
was:
JSON string with the value that contains backslashes fails to be recovered by `from_json()`.
I found that if the same string is created with `to_json(named_struct())` then it actually does work.
The following code to reproduce. I would expect all of these methods to return the same (correct) result:
```select to_json(named_struct('msg', '\\'))
, schema_of_json(to_json(named_struct('msg', '\\')))
, from_json(to_json(named_struct('msg', '\\')), schema_of_json(to_json(named_struct('msg', '\\'))))
, from_json('\{"msg":"\\"}', schema_of_json(to_json(named_struct('msg', '\\'))))
, from_json('\{"msg":"\\"}', 'msg string')
```
> from_json() acts differently on created and literal strings with backslashes
> ----------------------------------------------------------------------------
>
> Key: SPARK-34993
> URL: https://issues.apache.org/jira/browse/SPARK-34993
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 3.1.1
> Environment: Databricks DBR 8.1
> Reporter: Lauri Koobas
> Priority: Major
>
> JSON string with the value that contains backslashes fails to be recovered by `from_json()`.
> I found that if the same string is created with `to_json(named_struct())` then it actually does work.
>
> The following code to reproduce. I would expect all of these methods to return the same (correct) result:
> {code:java}
> select to_json(named_struct('msg', ''))
> , schema_of_json(to_json(named_struct('msg', '')))
> , from_json(to_json(named_struct('msg', '')), schema_of_json(to_json(named_struct('msg', ''))))
> , from_json('{"msg":""}', schema_of_json(to_json(named_struct('msg', ''))))
> , from_json('{"msg":""}', 'msg string')
>
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org