【发布时间】:2017-04-23 23:30:00
【问题描述】:
我有一个在 Azure Data Lake 环境中运行的 U-SQL 应用程序。它应该处理一个充满 JSON 数据的文件,看起来像这样,除了在现实生活中超过两行。
[
{"reports" : {"direction": "FWD", "drive": "STOPS", "frob_variable": 0}},
{"reports" : {"direction": "FWD", "drive": "CRANKS", "frob_variable": -3}}
]
在那个 Data Lake 工作中,我有以下一行:
@json =
EXTRACT direction string, drive string, frob_variable int FROM @"/input/file.json"
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor("reports");
当我将 @json 变量的内容转储到文本文件时,我得到空值:零长度字符串和零值整数。我确实得到了正确数量的输出行,所以它必须遍历我的所有输入。
对JsonExtractor 的源代码稍作研究表明,我指定的 JsonPath 值(“reports”)似乎正在返回带有嵌入 dict 的“reports”键。如果我尝试“reports.*”的 JsonPath 值,我确实会得到嵌入的值(例如,{ "FWD", "STOPS", 0 }),但我真的希望这些键与它们一起使用,所以SELECT direction, drive, frob_variable 会返回一些有用的东西。
长话短说,我正在寻找一种方法来从内部字典中提取键 和 值。因此,我想要的EXTRACT 的输出将是一个行集,其列是“direction”、“drive”和“frob_variable”,其值如源数据中所示。似乎应该有一个 JsonPath 解决方案或 U-SQL 中的简单解决方法。
【问题讨论】:
标签: json jsonpath azure-data-lake u-sql