【发布时间】:2021-04-15 10:10:34
【问题描述】:
我需要找出给定 JSON 文件的架构,我看到 sql 有 schema_of_json function 像这样的东西完美无缺
> SELECT schema_of_json('[{"col":0}]');
ARRAY<STRUCT<`col`: BIGINT>>
但是如果我查询我的表名,它会给我以下错误
>SELECT schema_of_json(Transaction) as json_data from table_name;
Error in SQL statement: AnalysisException: cannot resolve 'schemaofjson(`Transaction`)' due to data type mismatch: The input json should be a string literal and not null; however, got `Transaction`.; line 1 pos 7;
事务是我表中的列之一,在手动检查后我可以证明它是字符串类型(json)。
SQL语句有它给我JSON的架构,怎么办?
【问题讨论】:
-
看起来“交易”列包含一些
null值。你可以试试SELECT schema_of_json(Transaction) as json_data from table_name where Transaction is not null; -
这仍然不起作用,显示相同的错误。就像我说的 Transaction 列是一个字符串而不是
null -
你能分享一个minimal reproducible example吗?
标签: sql azure-databricks