我正在测试我正在开发的应用程序的数据湖。我是 U-SQL 和数据湖的新手,只是想查询 JSON 文件中的所有记录。现在,它只返回一条记录,我不确定为什么,因为该文件大约有 200 条记录。
我的代码是:
DECLARE @input string = @"/MSEStream/output/2016/08/12_0_fc829ede3c1d4cf9a3278d43e7e4e9d0.json";
REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];
@allposts =
EXTRACT
id string
FROM @input
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor();
@result =
SELECT *
FROM @allposts;
OUTPUT @result
TO "/ProcessedQueries/all_posts.csv"
USING Outputters.Csv();
数据示例:
{
"id":"398507",
"contenttype":"POST",
"posttype":"post",
"uri":"http://twitter.com/etc",
"title":null,
"profile":{
"@class":"PublisherV2_0",
"name":"Company",
"id":"2163171",
"profileIcon":"https://pbs.twimg.com/image",
"profileLocation":{
"@class":"DocumentLocation",
"locality":"Toronto",
"adminDistrict":"ON",
"countryRegion":"Canada",
"coordinates":{
"latitude":43.7217,
"longitude":-31.432},
"quadKey":"000000000000000"},
"displayName":"Name",
"externalId":"00000000000"},
"source":{
"name":"blogs",
"id":"18",
"param":"Twitter"},
"content":{
"text":"Description of post"},
"language":{
"name":"English",
"code":"en"},
"abstracttext":"More Text and links",
"score":{}
}
}
感谢您提前提供的帮助
最佳答案
JsonExtractor 采用一个参数,允许您使用 JSON 路径表达式指定将哪些项目或对象映射到行中。如果您不指定任何内容,它将采用顶部根(一行)。
您需要数组中的每一项,因此将其指定为:
使用新的 Microsoft.Analytics.Samples.Formats.Json.JsonExtractor("[*]");
其中 [*] 是 JSON 路径表达式,它表示给我数组的所有元素,在本例中是顶级数组。
关于json - U-SQL Json Extractor 仅提取一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38961029/