我正在測試我正在開發的應用程序的數據湖。我是U-SQL和數據湖的新手,只是試圖查詢JSON文件中的所有記錄。現在,這只是一個返回記錄,我不知道爲什麼,因爲文件中有大約200U-SQL Json提取器只提取一條記錄
我的代碼是:
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":{}
}
}
謝謝你提前提供幫助
當我放入時,它什麼也沒有返回。我添加了一個我在帖子中提到的數據的例子。 – WorkHardWork
我想清楚發生了什麼,輸出文件是一行分隔文件。有沒有辦法像這樣讀取它,或者我需要將它格式化爲數組? – WorkHardWork
您可以通過擴展當前的JSONExtractor來編寫自己的提取器來完成每行處理的行數(請參閱http://usql.io上我們的GitHub上的其他一些提取器),也可以使用內置函數在提取器中讀取JSON並作爲字符串讀取(然後,最大長度爲128kB)。一個例子是https://github.com/Azure/usql/blob/master/Examples/DataFormats/Microsoft.Analytics.Samples.Formats/readme.md –