首页 > 解决方案 > 将 JSON 模式插入 U-SQL 表

问题描述

我想在 DataLake Analysts 工具中为我的 U-SQL 表插入 JSON 模式。这是我的 JSON 模式

DECLARE @json string=  "{
        "definitions": {},
        "$schema": "http://json-schema.org/draft-06/schema#",
        "$id": "http://getIQOS.com/IQOSAbandonedCartV1.json",
        "title": "CE:I:ORD:ABC",
        "type": "object",
        "properties": {
            "altriaOrchestrated": {
                "$id": "/properties/altriaOrchestrated",
                "type": "integer",
                "title": "Altria Orchestrated",
                "description": "Specifies whether the AT object is being called by Core Services (1) or from an outside source (0)",
                "default": 0,
                "enum": [
                    0, 1
                ],
                "examples": [
                    0, 1
                ],
                "minimum": 0,
                "maximum": 1
            },
        "required": [
            "altriaOrchestrated",
            "initiativeName",
            "date",
            "inventory"
        ]
     }"

我遇到了错误,无法理解它是什么错误。由于这个问题,我的开发停止了。

 AGG ALL AND ARRAY BETWEEN BIGINT BIT BINARY BY COLUMNSET CREATED CSHARP CURRENT DATETIME DATETIME2 DECIMAL EXISTS FILE FLOAT FOLLOWING GROUP IN INT IS LENGTH LCID MAP MAX MODIFIED MONEY NULL NVARCHAR OR OVER PARTITION PRECEDING REAL SMALLINT SQL STRUCT TINYINT UNBOUNDED UNIQUEIDENTIFIER VARBINARY VARCHAR WITHIN string-literal numeric-literal character-literal punctuation-mark identifier quoted-identifier reserved-identifier variable system-variable '[' ']' '(' '{' '}' '=' '.' '*' ':' '?' '<' '>'

标签: azureazure-web-app-serviceazure-data-lakeu-sql

解决方案


根据我的测试,您可以利用双引号、反斜杠如下声明您的 json 字符串参数。

DECLARE @json string ="{"+
        "\"definitions\": {},"+
        "\"$schema\": \"http://json-schema.org/draft-06/schema#\","+
        "\"$id\": \"http://getIQOS.com/IQOSAbandonedCartV1.json\","+
        "\"title\": \"CE:I:ORD:ABC\","+
        "\"type\": \"object\","+
        "\"properties\": {"+
            "\"altriaOrchestrated\": {}"+
        "}"+
"}";

此外,您可以利用 Verbatim C# 字符串文字,通过在字符串的起始双引号前面添加 @ 字符来简化此类字符的处理。对于您的 json 字符串,您可以将其声明如下:

DECLARE @json string =@"{
        ""definitions"": {},
        ""$schema"": ""http://json-schema.org/draft-06/schema#"",
        ""$id"": ""http://getIQOS.com/IQOSAbandonedCartV1.json"",
        ""title"": ""CE:I:ORD:ABC"",
        ""type"": ""object"",
        ""properties"": {
           ""altriaOrchestrated"": {}
        }
}";

笔记:

在 U-SQL 中,字符串类型的列的最大大小为 128kB(基于以 UTF-8 编码表示的字符串值的字节数)。

您可以遵循Textual Types and Literals的详细信息。


推荐阅读