- Newest
- Most votes
- Most comments
This issue occurs because of how JSON data is handled during the Parquet format round-trip between Redshift and Spark.
When you UNLOAD data from Redshift to Parquet format, JSON data in SUPER columns is properly stored in the Parquet file. However, when Spark reads this Parquet file, it doesn't recognize the JSON structure as a native JSON object but rather as a string that contains JSON. When Spark then writes this back to Parquet, it treats the JSON as a string value, which causes the quotes to be escaped.
When the second Redshift cluster reads this Parquet file with the COPY command, it sees the data as a string with escaped quotes rather than as native JSON data that should be parsed into a SUPER column.
There are a few potential workarounds:
-
If possible, avoid the Spark round-trip for columns containing JSON data.
-
In Redshift after the COPY operation, you can use the PARSE_JSON function to convert the escaped JSON string back to a proper SUPER type:
UPDATE dest_table SET nested_json_col = PARSE_JSON(nested_json_col);
-
If you must process the data in Spark, you could explicitly parse the JSON in Spark before writing it back out, ensuring it's handled as structured data rather than a string.
-
Another approach is to use CSV format with JSON option for the UNLOAD/COPY operations instead of Parquet, which might handle the JSON data differently.
The core issue is that Spark and Redshift have different ways of representing JSON data in Parquet files, and this mismatch causes the double escaping when the data makes a round trip through both systems.
Sources
Redshift super datatype not enough to store json data type column from Postgres | AWS re:Post
UNLOAD - Amazon Redshift
Load super data on Redshift with COPY scapes JSON fields | AWS re:Post
answered a year ago
Relevant content
asked 7 years ago
asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
