[英]Copy JSON with multiple values from S3 to Redshift
I'm trying to load a JSON file with multiple values in one of the columns to Redshift using the copy command but get an error: 我正在尝试使用copy命令将列中具有多个值的JSON文件加载到Redshift中,但出现错误:
Invalid JSONPath format: Member is not an object.
无效的JSONPath格式:成员不是对象。
This is how my JSON file looks like: 这是我的JSON文件的样子:
{"id":3,
"name":"John",
"children":[
{"child":"Ann","age":10},
{"child":"Dan","age":4},
{"child":"Ben","age":3}]
}
This is my jsonpath file: 这是我的jsonpath文件:
{
"jsonpaths": [
"$.id",
"$.name",
"$.children.child",
"$.children.age"
]
}
And I expect the data in the SQL to show: 我希望SQL中的数据能够显示:
id name child age
-- ---- ----- ---
3 John Ann 10
3 John Dan 4
3 John Ben 3
Any ideas? 有任何想法吗?
JSONPaths in COPY will only create one row per entry (or line) in your input file. COPY中的JSONPaths将仅在输入文件中为每个条目(或行)创建一行。 In your example above, you want to create 3 lines from one entry, and Redshift doesn't support that.
在上面的示例中,您想从一个条目创建3行,而Redshift不支持该行。
You can consider preprocessing the data to convert it to something like this: 您可以考虑对数据进行预处理,以将其转换为如下形式:
{
"id":3,
"name":"John",
"child":"Ann",
"age":10
},
{
"id":3,
"name":"John",
"child":"Dan",
"age":4
},
{
"id":3,
"name":"John",
"child":"Ben",
"age":3
}
And then, the following simple JSONPath will work: 然后,以下简单的JSONPath将起作用:
{
"jsonpaths": [
"$.id",
"$.name",
"$.child",
"$.age"
]
}
If you cannot change the structure of source file, try to load this to a PIVOT table with one column for each value (provided there are fixed number of values). 如果您无法更改源文件的结构,请尝试将其加载到PIVOT表中,每个值只有一列(前提是值的数目固定)。 Do an UNPIVOT in Redshift post the COPY process.
在COPY过程之后,在Redshift中进行UNPIVOT。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.