【发布时间】:2015-10-14 03:24:13
【问题描述】:
我有以下 JSON。
{
"_id": "00075602-f58d-49f5-8a82-9b5fb5582443",
"ActivityCountedCollection": [{
"Lesson": "98d66ab9-1ef4-4b61-a05d-857b3e07e0f8",
"DataSet": 1,
"DateTime": "2013-06-19T15:54:27.79+00:00",
"ElapsedSeconds": 0.0000
},
{
"Lesson": "Kindergarten - Play & Practice",
"DataSet": 0,
"DateTime": "2014-01-01T00:00:00",
"ElapsedSeconds": 0.0,
"Scores": [{
"DataSet": 11,
"Lesson": "c241ab4b-3d11-4aca-bb9b-a8a645c1e6ca",
"ActivityNode": "ef2d4aae-08ad-48eb-a2e3-0ab616ef2e9c",
"DateTime": "2013-07-01T15:31:11.81+00:00",
"NumPossible": 2,
"NumCorrect": 1,
"Mastered": false
},
{
"DataSet": 1,
"Lesson": "01d6691f-911f-45b5-b861-778c725b4d98",
"ActivityNode": "a2783eb1-873d-4ae7-bd58-6ab4bf48692c",
"DateTime": "2013-07-08T15:09:54.61+00:00",
"NumPossible": 5,
"NumCorrect": 5,
"Mastered": false
}]
}]
}
我想检索 _ID 值以及 ActivityCountedCollection 中的任何分数值。有些文档有分数,有些没有。
所以可以说我的结果表是这样的:
_ID,
Lesson,
DateTime,
NumPossible,
NumCorrect
我可以将分数数组作为字符串检索,方法是创建下表并使用所述 json 加载它。
CREATE EXTERNAL TABLE IF NOT EXISTS $ActivityCounted (
id string,
ActivityCountedcollection array<struct<
Scores:array<string>
>
>
)
但我想从分数数组中检索实际字段。我曾尝试将分数作为字符串加载到表中,然后再次分解它们,但相信由于它不知道它们是单独的字段,并且存在于字符串字段中,因此无法检索它们。 所以我尝试重新创建表以包含子数组。
CREATE EXTERNAL TABLE IF NOT EXISTS $ActivityCounted (
id string,
ActivityCountedcollection array<struct<
Scores:array<struct<
Skill:string,
Lesson:string,
DateTime:timestamp,
NumPossible:int,
NumCorrect:int,
Mastered:string
> >
>
>
)
但这也不起作用。
我有另一个例子,它不是一个复杂的字段数组,我能够将它提取到一个表中,将数组粘贴到一个表中,然后再次分解该表,并提取单个值。但是要再次爆炸并从数组中提取多个字段,我很难过。
【问题讨论】:
标签: arrays json hadoop explode azure-hdinsight