infer_storage_schema_with_suggestions 插件

使用 “版本 ”下拉列表切换服务。 了解有关导航的详细信息
适用于:✅ Azure Data Explorer

infer_storage_schema_with_suggestions 插件可以推断外部数据的架构并返回 JSON 对象。 对于每个列,该对象提供推断出的类型、建议的类型和建议的映射转换。 建议的类型和映射由建议逻辑提供,该逻辑使用以下逻辑确定最佳类型:

  • 标识列:如果列的推断类型为 ,且列名以 long 结尾,则建议的类型为 id,因为它为包含通用相等性筛选器的标识列提供优化的索引string
  • Unix 日期/时间列:如果列的推断类型为 ,并且其中一个 Unix 时间到日期/时间的long生成了有效的日期/时间值,则建议的类型为 ,而建议的 datetime 映射则是生成有效日期/时间值的映射ApplicableTransformationMapping

该插件通过 evaluate 运算符调用。 若要获取使用推断架构的表架构并更改Azure Storage外部表,请使用 infer_storage_schema 插件。

身份验证和授权

在请求属性中,指定要access的storage连接字符串。 每个storage connection string指定用于storage access的授权方法。 根据授权方法,可能需要向主体授予对外部storage的权限才能执行架构推理。

下表列出了受支持的身份验证方法和storage类型所需的任何权限。

身份验证方法 Azure Blob Storage/Data Lake Storage Gen2 Data Lake Storage Gen1
Impersonation Storage Blob 数据读取器 读取器
共享Access令牌 列出 + 读取 Gen1 不支持此身份验证方法。
Microsoft Entra access token
Storage帐户access密钥 Gen1 不支持此身份验证方法。

语法

evaluate infer_storage_schema_with_suggestions( 选项)

详细了解语法约定

参数

客户 类型 必需 说明
选项 dynamic ✔️ 一个用于指定请求属性的属性包。

请求的受支持的属性

客户 类型 必需 说明
StorageContainers dynamic ✔️ storage连接字符串数组,表示存储数据artifacts的前缀 URI。
DataFormat string ✔️ 支持的支持摄取的数据格式之一
FileExtension string 如果指定,则函数仅扫描以此文件扩展名结尾的文件。 指定扩展名可以加快进程或避免数据读取问题。
FileNamePrefix string 如果指定,则函数仅扫描以此前缀开头的文件。 指定前缀可以加快进程。
模式 string 架构推理策略。 值:anylastall。 此函数分别从找到的第一个文件、最后写入的文件或者从所有文件来推断数据架构。 默认值为 last
InferenceOptions dynamic 更多推理选项。 有效选项:UseFirstRowAsHeader(对于带分隔符的文件格式)。 例如,'InferenceOptions': {'UseFirstRowAsHeader': true}

返回

infer_storage_schema_with_suggestions 插件返回一个结果表,其中包含一个保留了 JSON 字符串的行/列。

注意

  • 除了 Read,Storage容器 URI 密钥还必须具有 List 的权限。
  • 架构推理策略“all”是非常“昂贵的”作,因为它意味着从 all artifacts 找到并合并其架构。
  • 由于错误的类型推测(或者由于架构合并进程),有些返回的类型可能并不是实际的类型。 正因如此,你应在使用它们之前仔细检查结果。

示例

let options = dynamic({
  'StorageContainers': [
    h@'https://storageaccount.blob.core.chinacloudapi.cn/MobileEvents;secretKey'
  ],
  'FileExtension': '.json',
  'FileNamePrefix': 'js-',
  'DataFormat': 'json'
});
evaluate infer_storage_schema_with_suggestions(options)

示例输入数据

    {
        "source": "DataExplorer",
        "created_at": "2022-04-10 15:47:57",
        "author_id": 739144091473215488,
        "time_millisec":1547083647000
    }

输出

{
  "Columns": [
    {
      "OriginalColumn": {
        "Name": "source",
        "CslType": {
          "type": "string",
          "IsNumeric": false,
          "IsSummable": false
        }
      },
      "RecommendedColumn": {
        "Name": "source",
        "CslType": {
          "type": "string",
          "IsNumeric": false,
          "IsSummable": false
        }
      },
      "ApplicableTransformationMapping": "None"
    },
    {
      "OriginalColumn": {
        "Name": "created_at",
        "CslType": {
          "type": "datetime",
          "IsNumeric": false,
          "IsSummable": true
        }
      },
      "RecommendedColumn": {
        "Name": "created_at",
        "CslType": {
          "type": "datetime",
          "IsNumeric": false,
          "IsSummable": true
        }
      },
      "ApplicableTransformationMapping": "None"
    },
    {
      "OriginalColumn": {
        "Name": "author_id",
        "CslType": {
          "type": "long",
          "IsNumeric": true,
          "IsSummable": true
        }
      },
      "RecommendedColumn": {
        "Name": "author_id",
        "CslType": {
          "type": "string",
          "IsNumeric": false,
          "IsSummable": false
        }
      },
      "ApplicableTransformationMapping": "None"
    },
    {
      "OriginalColumn": {
        "Name": "time_millisec",
        "CslType": {
          "type": "long",
          "IsNumeric": true,
          "IsSummable": true
        }
      },
      "RecommendedColumn": {
        "Name": "time_millisec",
        "CslType": {
          "type": "datetime",
          "IsNumeric": false,
          "IsSummable": true
        }
      },
      "ApplicableTransformationMapping": "DateTimeFromUnixMilliseconds"
    }
  ]
}