[英]How to load on Snowflake a JSON that has a literal unicode escape char “\\uNo”
I have the following JSON:我有以下 JSON:
{
"name": "foo \\uNo bar"
}
I'm trying to load this into Snowflake using a STAGE on S3.我正在尝试使用 S3 上的 STAGE 将其加载到雪花中。 This is in a CSV file like:这是在 CSV 文件中,例如:
{"name": "foo \\uNo bar"}
However, when I try to load it, Snowflake breaks with an Error parsing JSON message.但是,当我尝试加载它时,Snowflake 会因解析 JSON 消息时出现错误而中断。 If I try to load it directly on Snowflake console, as SELECT PARSE_JSON('{"name": "foo \\uNo bar"}')
, I get:如果我尝试直接在 Snowflake 控制台上加载它,如SELECT PARSE_JSON('{"name": "foo \\uNo bar"}')
,我得到:
Error parsing JSON: hex digit is expected in \u????解析 JSON 时出错:\u 中应为十六进制数字???? escape sequence, pos 17转义序列,位置 17
The problem is that Snowflake is parsing the string, checking for an unicode digit \uNo
(which doesn't exist).问题是 Snowflake 正在解析字符串,检查 unicode 数字\uNo
(不存在)。 How can I disable this?我怎样才能禁用它?
The default FILE FORMAT for parsing CSVs in Snowflake is interpreting the double backslash string '{"name": "foo \\uNo bar"}'
as an escape sequence for the character \
which means that the character sequence \uNo
is getting passed to PARSE_JSON which then fails because \uNo
not a valid escape sequence for a JSON string.在 Snowflake 中解析 CSV 的默认文件格式将双反斜杠字符串'{"name": "foo \\uNo bar"}'
为字符\
的转义序列,这意味着将字符序列\uNo
传递给PARSE_JSON 然后失败,因为\uNo
不是 JSON 字符串的有效转义序列。 You can prevent this by overriding the FILE FORMAT escape sequence settings.您可以通过覆盖 FILE FORMAT 转义序列设置来防止这种情况。
Given this CSV file:鉴于此 CSV 文件:
JSON
'{"name": "foo \\uNo bar"}'
And the following CREATE TABLE and COPY INTO statements:以及以下 CREATE TABLE 和 COPY INTO 语句:
CREATE OR REPLACE TABLE JSON_TEST (JSON TEXT);
COPY INTO JSON_TEST
FROM @my_db.public.my_s3_stage/json.csv
FILE_FORMAT = (TYPE = CSV
SKIP_HEADER = 1
FIELD_OPTIONALLY_ENCLOSED_BY = '\''
ESCAPE = NONE
ESCAPE_UNENCLOSED_FIELD = NONE);
I am able to parse there result as JSON:我能够将结果解析为 JSON:
SELECT PARSE_JSON(JSON) FROM JSON_TEST;
Which returns哪个返回
+-----------------------------+
| JSON |
+-----------------------------|
| { "name": "foo \\uNo bar" } |
+-----------------------------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.