ON_ERROR 参数对 JSON 文件不起作用

ON_ERROR parameter does not work for me with JSON files

我在 Snowflake 中创建了简单的 table:

Column name    Type
S              VARCHAR
N              NUMBER

两列都可以为空。 现在我想从 CSVJSON 文件中将部分错误的结果加载到 table 中。

CSV

s, n
hello, 1
bye, 2
nothing, zero

第三行是"bad":它的第二个元素不是数字。 我用来加载此文件的命令:

"COPY INTO "DEMO_DB"."PUBLIC"."TEST5" FROM @my_s3_stage1 files=('2good-1bad.csv') file_format = (type = csv field_delimiter = ',' skip_header = 1) ON_ERROR = CONTINUE;

抛出SnowflakeSQLException:

errorCode = 200038 
SQLState = 0A000 
message: Cannot convert value in the driver from type:12 to type:int, value=PARTIALLY_LOADED.

两行"good"写入table; "bad" 一个被忽略。这个结果是意料之中的。

然而,当我使用以下 JSON 行文件时:

{"s":"hello", "n":1}
{"s":"bye", "n":2}
{"s":"nothing", "n":"zero"}

使用此命令:

COPY INTO "DEMO_DB"."PUBLIC"."TEST5" FROM @my_s3_stage1 files=('2good-1bad.json') file_format = (type = json) 
MATCH_BY_COLUMN_NAME=CASE_INSENSITIVE 
ON_ERROR = CONTINUE

我得到以下 SnowflakeSQLException:

errorCode = 100071 
SQLState = 22000 
message: Failed to cast variant value "zero" to FIXED

没有任何内容写入数据库。

问题是"What's wrong?" 为什么 ON_ERROR = CONTINUE 不适用于我的 JSON 文件?

PS:

  1. 用单引号包裹 CONTINUE 没有帮助
  2. 使用小写没有帮助
  3. 实际上我不需要 CONTINUE,我需要 SKIP_FILE_<num>,但是这也不适用于 JSON。
  4. 其实我们在生产环境中使用的是avro,所以比较贴切。我正在使用 JSON 进行测试,因为它更容易。

您说得对 on_error 不支持非 CSV 文件格式。我见过有文件的人可以解决使用 FIELD_DELIMITER = 'none' 指定 CSV 文件类型的问题。

我看到一些人要求此选项适用于半结构化文件,欢迎您也提交功能请求以创造更多需求: https://community.snowflake.com/s/ideas

文档并没有真正说明它不受支持(请随时使用底部的按钮提交文档反馈),但您可以看到它的提示: https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html

"You can use the corresponding file format (e.g. JSON), but any error in the transformation will stop the COPY operation, even if you set the ON_ERROR option to continue or skip the file."