【问题标题】:Unable to parse list of Json blocks in U-SQL无法解析 U-SQL 中的 Json 块列表
【发布时间】:2019-05-21 16:12:16
【问题描述】:

我有一个包含 json 块列表的文件,并且卡在 U-Sql 中处理/读取它们并写入文本文件。

{
    "id": "0001",
    "type": "donut",
    "name": "Cake",
    "ppu": 0.55,
    "batters":
        {
            "batter":
                [
                    { "id": "1001", "type": "Regular" },
                    { "id": "1002", "type": "Chocolate" },
                    { "id": "1003", "type": "Blueberry" },
                    { "id": "1004", "type": "Devil's Food" }
                ]
        },
    "topping":
        [
            { "id": "5001", "type": "None" },
            { "id": "5002", "type": "Glazed" },
            { "id": "5005", "type": "Sugar" },
            { "id": "5007", "type": "Powdered Sugar" },
            { "id": "5006", "type": "Chocolate with Sprinkles" },
            { "id": "5003", "type": "Chocolate" },
            { "id": "5004", "type": "Maple" }
        ]
}
{
    "id": "0002",
    "type": "nut",
    "name": "ake",
    "ppu": 1.55,
    "batters":
        {
            "batter":
                [
                    { "id": "1001", "type": "Regular" },
                    { "id": "1002", "type": "Chocolate" },
                    { "id": "1003", "type": "Blueberry" },
                    { "id": "1004", "type": "Devil's Food" }
                ]
        },
    "topping":
        [
            { "id": "5001", "type": "None" },
            { "id": "5002", "type": "Glazed" },
            { "id": "5005", "type": "Sugar" },
            { "id": "5007", "type": "Powdered Sugar" },
            { "id": "5006", "type": "Chocolate with Sprinkles" },
            { "id": "5003", "type": "Chocolate" },
            { "id": "5004", "type": "Maple" }
        ]
}

{
    "id": "0003",
    "type": "test",
    "name": "ake",
    "ppu": 1.55,
    "batters":
        {
            "batter":
                [

                ]
        },
    "topping":
        [

            { "id": "5003", "type": "Chocolate" },
            { "id": "5004", "type": "Maple" }
        ]
}

有人可以帮我解决这个问题吗?

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

DECLARE @Full_Path string = @"C:\Users\test\Desktop\File\JsonTest.json";

USING [Microsoft.Analytics.Samples.Formats];

@RawExtract = 
    EXTRACT 
        [RawString] string

    FROM
        @Full_Path
    USING 
        Extractors.Text(delimiter:'\n', quoting : false);

@ParsedJSONLines =
    SELECT JsonFunctions.JsonTuple([RawString]) AS JSONLine

    FROM @RawExtract;


@StagedData =
    SELECT 
        JSONLine["id"] AS Id,
        JSONLine["name"] AS Name,
        JSONLine["type"] AS Type,
        JSONLine["ppu"] AS PPU,
JSONLine["batters"] AS Batter
    FROM 
        @ParsedJSONLines;

DECLARE @Output_Path string = @"C:\Users\Test\Desktop\File\Test2.csv";

OUTPUT @StagedData
TO @Output_Path 
USING Outputters.Csv();

在评估表达式时收到错误。

Error while evaluating expression JsonFunctions.JsonTuple(RawString)

【问题讨论】:

    标签: azure azure-data-lake u-sql data-lake


    【解决方案1】:

    你不能使用文本提取器来提取 Json,除非你使用 Json Lines。

    使用提取器会拆分json,你会得到错误。

    使用 JsonExtractor 代替文本提取器。

    https://github.com/Azure/usql/blob/master/Examples/DataFormats/Microsoft.Analytics.Samples.Formats/Json/JsonExtractor.cs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-23
      • 2019-08-02
      • 1970-01-01
      相关资源
      最近更新 更多