简体   繁体   English

从 JSON 复杂类型获取数据的 U-SQL 脚本语法错误

[英]Syntax error on U-SQL Script to get data from JSON complex type

This is my input JSON file.这是我的输入 JSON 文件。

[
  {
    "Tag": "STACK007",
    "data": [
      {
        "item": "UNIFY109",
        "timestamp": "2018-08-27T17:28:51.8490000Z",
        "jsonVersion": 1,
        "messageType": 1,
        "velocity": 709
      }
    ],
    "EventProcessedUtcTime": "2018-08-27T17:36:17.5519639Z",
    "EventEnqueuedUtcTime": "2018-08-27T17:28:52.0010000Z"
  }
]

I'm trying to convert this input JSON file to CSV.我正在尝试将此输入 JSON 文件转换为 CSV。 Here's my U-SQL Script这是我的 U-SQL 脚本

REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];

USING Microsoft.Analytics.Samples.Formats.Json;

DECLARE @input string = @"/demodata/logs/2018/08/input.json";

@json = 
EXTRACT 
        Tag string, 
        EventProcessedUtcTime DateTime,
        EventEnqueuedUtcTime DateTime,
        JsonFunctions.JsonTuple(data) AS data
  FROM @input 
USING new JsonExtractor();

@result =
SELECT Tag,          
       address["velocity"]AS Velocity,
       address["messageType"]AS MessageType,
       address["timestamp"]AS Timestamp
FROM @json;

OUTPUT @result
TO "/output/demooutput.csv"
USING Outputters.Csv();

This script is giving me a syntax error with the message " syntax error. Expected one of: '.'这个脚本给了我一个语法错误消息“语法错误。预期之一:'。' "

How do I fix this?我该如何解决?

I found that this had been answered previously:我发现这之前已经回答过:

@resultset = 
    EXTRACT 

        item string, 
        jsonversion int, 
        messageType int, 
        velocity float
    FROM @input
   USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor("data[*]");

This is from an answer by Michael Rys to this stackoverflow question: U- SQL Unable to extract data from JSON file这是 Michael Rys 对这个 stackoverflow 问题的回答: U-SQL Unable to extract data from JSON file

" Actually the JSONExtractor supports the rowpath parameter expressed in JSONPath that gives you the ability to identify the JSON object or JSON array items that you want to map into rows. So you can extract your data with a single statement from your JSON document " 实际上,JSONExtractor 支持以 JSONPath 表示的 rowpath 参数,它使您能够识别要映射到行中的 JSON 对象或 JSON 数组项。因此,您可以使用单个语句从 JSON 文档中提取数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM