TMSL Xmla 在现有数据库上创建表 - 表格模型脚本语言 - Azure Analysis Services

TMSL Xmla Creating Tables on Existing Database - Tabular Model Scripting Language - Azure Analysis Services

我的问题是:使用 xmla 文件和 SSMS 向现有数据库添加 2 个或更多 table 的正确语法是什么? 我有一个模型部署到 Azure Analysis Services 服务器。所以数据库已经创建好了。我想在 SSMS 中用 运行 一个单独的 xmla 脚本创建或替换 tables。

当我使用下面的脚本创建一个 table 时,它工作得很好。但我需要的是使用一个 xmla 脚本创建多个 table(不仅仅是一个)。

适用于一个的脚本table

下面的脚本在数据库中"creates or replaces"一个table完美且正确地工作。

{
  "createOrReplace": {
    "object": {
      "database": "MyDatabase",
      "table": "MyTable"
    },
    "table": {
      "name": "MyTable",
      "columns": [
        {
          "name": "MyTableId",
          "dataType": "int64",
          "sourceColumn": "MyTableId"
        },
        {
          "name": "MyTable",
          "dataType": "string",
          "sourceColumn": "MyTable"
        }
      ],
      "partitions": [
        {
          "name": "Partition",
          "dataView": "full",
          "source": {
            "type": "m",
            "expression": [
              "let",
              "    Source=GetFileList(),",
              "    #\"MyTable txt\" = Source{[Name=\"MyTable.txt\"]}[Content],",
              "    #\"Imported CSV\" = Csv.Document(#\"MyTable txt\",[Delimiter=\",\", Columns=9, Encoding=1252, QuoteStyle=QuoteStyle.None]),",
              "    #\"Promoted Headers\" = Table.PromoteHeaders(#\"Imported CSV\", [PromoteAllScalars=true]),",
              "    #\"Changed Type\" = Table.TransformColumnTypes(#\"Promoted Headers\",{{\"MyTableId\", Int64.Type}, {\"MyTable\", type text}, {\"Description\", type text}}),",
              "    #\"Removed Columns\" = Table.RemoveColumns(#\"Changed Type\",{\"Description\"})",
              "in",
              "    #\"Removed Columns\""
            ]
          }
        }
      ]
    }
  }
}

我尝试使用下面的代码添加 2 tables 但出现错误 JSON DDL 请求失败并出现以下错误:无法识别 JSON 属性: table秒。检查路径 'tables',第 6 行,位置 16..

{   
  "createOrReplace": {   
    "database": {   
      "name": "MyDatabase",   
      "tables": [   
        {"name": "TableA",
      "columns": [
        {
          "name": "TableAId",
          "dataType": "int64",
          "sourceColumn": "TableAId"
        },
        {
          "name": "TableA",
          "dataType": "string",
          "sourceColumn": "TableA"
        }
      ],
      "partitions": [
        {
          "name": "Partition",
          "dataView": "full",
          "source": {
            "type": "m",
            "expression": [
              "let",
              "    Source=GetFileList(),",
              "    #\"TableA txt\" = Source{[Name=\"TableA.txt\"]}[Content],",
              "    #\"Imported CSV\" = Csv.Document(#\"TableA txt\",[Delimiter=\",\", Columns=9, Encoding=1252, QuoteStyle=QuoteStyle.None]),",
              "    #\"Promoted Headers\" = Table.PromoteHeaders(#\"Imported CSV\", [PromoteAllScalars=true]),",
              "    #\"Changed Type\" = Table.TransformColumnTypes(#\"Promoted Headers\",{{\"TableAId\", Int64.Type}, {\"TableA\", type text}, {\"Description\", type text}}),",
              "    #\"Removed Columns\" = Table.RemoveColumns(#\"Changed Type\",{\"Description\"})",
              "in",
              "    #\"Removed Columns\""
            ]
          }
        }
      ] },   
        {"name": "TableB",
      "columns": [
        {
          "name": "TableBId",
          "dataType": "int64",
          "sourceColumn": "TableBId"
        },
        {
          "name": "TableB",
          "dataType": "string",
          "sourceColumn": "TableB"
        }
      ],
      "partitions": [
        {
          "name": "Partition",
          "dataView": "full",
          "source": {
            "type": "m",
            "expression": [
              "let",
              "    Source=GetFileList(),",
              "    #\"TableB txt\" = Source{[Name=\"TableB.txt\"]}[Content],",
              "    #\"Imported CSV\" = Csv.Document(#\"TableB txt\",[Delimiter=\",\", Columns=11, Encoding=1252, QuoteStyle=QuoteStyle.None]),",
              "    #\"Promoted Headers\" = Table.PromoteHeaders(#\"Imported CSV\", [PromoteAllScalars=true]),",
              "    #\"Changed Type\" = Table.TransformColumnTypes(#\"Promoted Headers\",{{\"TableBId\", Int64.Type}, {\"TableB\", type text}, {\"Description\", type text}}),",
              "    #\"Removed Columns\" = Table.RemoveColumns(#\"Changed Type\",{\"Description\"})",
              "in",
              "    #\"Removed Columns\""
            ]
          }
        }
      ] } 
      ]      
    }   
  }   
}  

我也尝试了下面的代码,但出现错误 错误 -1055784777:JSON DDL 请求失败,出现以下错误:无法识别 JSON 属性:tables。检查路径 'createOrReplace.tables',第 6 行,位置 14.. JSON DDL 请求失败,出现以下错误:无法识别 JSON 属性:tables。检查路径 'createOrReplace.tables',第 6 行,位置 14..

{
  "createOrReplace": {
    "object": {
      "database": "MyDatabase"
      },
    "tables": [
      {
        "name": "TableA",
        "columns": [
          {
            "name": "TableAId",
            "dataType": "int64",
            "sourceColumn": "TableAId"
          },
          {
            "name": "TableA",
            "dataType": "string",
            "sourceColumn": "TableA"
          }
        ],
        "partitions": [
          {
            "name": "Partition",
            "dataView": "full",
            "source": {
              "type": "m",
              "expression": [
                "let",
                "    Source=GetFileList(),",
                "    #\"TableA txt\" = Source{[Name=\"TableA.txt\"]}[Content],",
                "    #\"Imported CSV\" = Csv.Document(#\"TableA txt\",[Delimiter=\",\", Columns=9, Encoding=1252, QuoteStyle=QuoteStyle.None]),",
                "    #\"Promoted Headers\" = Table.PromoteHeaders(#\"Imported CSV\", [PromoteAllScalars=true]),",
                "    #\"Changed Type\" = Table.TransformColumnTypes(#\"Promoted Headers\",{{\"TableAId\", Int64.Type}, {\"TableA\", type text}, {\"Description\", type text}}),",
                "    #\"Removed Columns\" = Table.RemoveColumns(#\"Changed Type\",{\"Description\"})",
                "in",
                "    #\"Removed Columns\""
              ]
            }
          }
        ]
      },
      {
        "name": "TableB",
        "columns": [
          {
            "name": "TableBId",
            "dataType": "int64",
            "sourceColumn": "TableBId"
          },
          {
            "name": "TableB",
            "dataType": "string",
            "sourceColumn": "TableB"
          }
        ],
        "partitions": [
          {
            "name": "Partition",
            "dataView": "full",
            "source": {
              "type": "m",
              "expression": [
                "let",
                "    Source=GetFileList(),",
                "    #\"TableB txt\" = Source{[Name=\"TableB.txt\"]}[Content],",
                "    #\"Imported CSV\" = Csv.Document(#\"TableB txt\",[Delimiter=\",\", Columns=11, Encoding=1252, QuoteStyle=QuoteStyle.None]),",
                "    #\"Promoted Headers\" = Table.PromoteHeaders(#\"Imported CSV\", [PromoteAllScalars=true]),",
                "    #\"Changed Type\" = Table.TransformColumnTypes(#\"Promoted Headers\",{{\"TableBId\", Int64.Type}, {\"TableB\", type text}, {\"Description\", type text}}),",
                "    #\"Removed Columns\" = Table.RemoveColumns(#\"Changed Type\",{\"Description\"})",
                "in",
                "    #\"Removed Columns\""
              ]
            }
          }
        ]
      }
    ]
  }
}

使用顺序命令:

{
  "sequence": {
    "operations": [
      { CREATE TABLE 1},
      { CREATE TABLE 2}
    ]
  }
}

您可以包含任意数量的操作。