json - U-SQL Json Extractor 仅提取一条记录

标签 json azure-data-lake u-sql

我正在测试我正在开发的应用程序的数据湖。我是 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/

相关文章:

json文件没有在 native react 中更新

android - 从 Google Cloud Firestore 获取 JSON 对象

javascript - 我应该使用 JSON 还是 AJAX 作为响应数据?

azure-data-lake - 如何在 U-SQL 中抛出错误或引发异常?

azure - 如何从azure数据湖读取行分隔的json文件并使用usql进行查询

java - 如何将 Restful 服务上的字符串转换为 xml 文件以进行 xsd 验证

python - 使用 Databricks 将 Google Api 的结果写入数据湖

azure - ADLS2 Blob 存储 "Last Modified Date"生成时间戳

azure - 数据湖分析 U-SQL 提取速度(本地与 Azure)

azure - Google 的 BigQuery 与 Azure 数据湖 U-SQL