externaldata 運算子
externaldata
運算符會傳回數據表,其架構定義於查詢本身,以及其數據是從外部記憶體成品讀取,例如 Azure Blob 儲存體 中的 Blob 或 Azure Data Lake Storage 中的檔案。
注意
externaldata
運算子支援:
- 一組特定的記憶體服務,如 記憶體連接字串下所列,。
- 共用存取簽章 (SAS) 金鑰、存取金鑰,以及Microsoft Entra Token 驗證方法。 如需詳細資訊,請參閱 記憶體驗證方法。
注意
externaldata
使用 運算符,從外部記憶體成品擷取最多 100 MB 的小參考數據表。 運算子不是針對大型數據磁碟區所設計。 若要擷取大量的外部數據,建議將 外部數據內嵌至Log Analytics做為自定義記錄。
當記憶體成品的公用端點位於防火牆後方時,不支援此運算符。
語法
externaldata
columnName(
columnType [:
...] ,
[
storageConnectionString [,
...] ]
[with
(
propertyName=
propertyValue [,
...])
]
深入瞭解 語法慣例。
參數
姓名 | 類型 | 必要 | 描述 |
---|---|---|---|
columnName, columnType | string |
✔️ | 數據行名稱及其類型的清單。 此清單會定義資料表的架構。 |
storageConnectionString | string |
✔️ | 要查詢之記憶體成品的記憶體 連接字串。 |
propertyName、 propertyValue | string |
選擇性 支援的屬性 清單,決定如何解譯從記憶體擷取的數據。 |
支援的屬性
屬性 | 類型 | 描述 |
---|---|---|
format | string |
數據格式。 如果未指定,則會嘗試從擴展名偵測數據格式。 預設值為 CSV 。 支援所有 擷取數據格式 。 |
ignoreFirstRecord | bool |
如果設定為 true ,則會忽略每個檔案中的第一筆記錄。 使用標頭查詢 CSV 檔案時,這個屬性將發揮作用。 |
ingestionMapping | string |
指出如何將來源檔案中的數據對應至運算子結果集中的實際數據行。 請參閱資料對應。 |
傳回
運算符externaldata
會傳回指定架構的數據表,該數據表的數據是從指定的記憶體成品剖析,由記憶體 連接字串 表示。
範例
範例會查詢外部記憶體檔案中的數據。
擷取儲存在 Azure Blob 儲存體的使用者標識碼清單
下列範例示範如何在數據表中尋找所有記錄,其 UserID
數據行落在外部儲存盤案中保留的已知標識符集(每行一行)。 由於未指定資料格式,因此偵測到的數據格式為 TXT
。
Users
| where UserID in ((externaldata (UserID:string) [
@"https://storageaccount.blob.core.windows.net/storagecontainer/users.txt"
h@"?...SAS..." // Secret token needed to access the blob
]))
| ...
查詢多個數據檔
下列範例會查詢儲存在外部記憶體中的多個數據檔。
externaldata(Timestamp:datetime, ProductId:string, ProductDescription:string)
[
h@"https://mycompanystorage.blob.core.windows.net/archivedproducts/2019/01/01/part-00000-7e967c99-cf2b-4dbb-8c53-ce388389470d.csv.gz?...SAS...",
h@"https://mycompanystorage.blob.core.windows.net/archivedproducts/2019/01/02/part-00000-ba356fa4-f85f-430a-8b5a-afd64f128ca4.csv.gz?...SAS...",
h@"https://mycompanystorage.blob.core.windows.net/archivedproducts/2019/01/03/part-00000-acb644dc-2fc6-467c-ab80-d1590b23fc31.csv.gz?...SAS..."
]
with(format="csv")
| summarize count() by ProductId
上述範例可視為快速查詢多個數據檔的方式,而不需定義 外部數據表。
注意
運算子無法辨識 externaldata
數據分割。
查詢階層式數據格式
若要查詢階層式數據格式,例如 JSON
、 Parquet
、 Avro
或 ORC
, ingestionMapping
必須在運算符屬性中指定。
在此範例中,有一個 JSON 檔案會以下列內容儲存在 Azure Blob 儲存體:
{
"timestamp": "2019-01-01 10:00:00.238521",
"data": {
"tenant": "e1ef54a6-c6f2-4389-836e-d289b37bcfe0",
"method": "RefreshTableMetadata"
}
}
{
"timestamp": "2019-01-01 10:00:01.845423",
"data": {
"tenant": "9b49d0d7-b3e6-4467-bb35-fa420a25d324",
"method": "GetFileList"
}
}
...
若要使用 externaldata
運算子查詢此檔案,必須指定數據對應。 對應會指示如何將 JSON 欄位對應至運算子結果集數據行:
externaldata(Timestamp: datetime, TenantId: guid, MethodName: string)
[
h@'https://mycompanystorage.blob.core.windows.net/events/2020/09/01/part-0000046c049c1-86e2-4e74-8583-506bda10cca8.json?...SAS...'
]
with(format='multijson', ingestionMapping='[{"Column":"Timestamp","Properties":{"Path":"$.timestamp"}},{"Column":"TenantId","Properties":{"Path":"$.data.tenant"}},{"Column":"MethodName","Properties":{"Path":"$.data.method"}}]')
MultiJSON
因為單一 JSON 記錄會跨越多行,因此會在這裡使用格式。
相關內容
如需對應語法的詳細資訊,請參閱 數據對應。