共用方式為


bag_pack()

適用於:✅Microsoft網狀架構Azure 數據✅總管 Azure 監視器✅Microsoft Sentinel

從索引鍵和值清單中建立 動態 屬性包物件。

已被取代的別名:pack(),pack_dictionary()

語法

bag_pack(key1 value1,, key2 value2, ,... )

深入瞭解 語法慣例

參數

姓名 類型​​ 必要 描述
key string ✔️ 金鑰名稱。
value 任何純量數據類型 ✔️ 索引鍵值。

注意

索引 字串是替代清單,清單的總長度必須是偶數。

傳回

dynamic從列出的索引鍵輸入傳回屬性包物件。

範例

範例 1

下列範例會從索引鍵和值的替代清單建立並傳回屬性包。

print bag_pack("Level", "Information", "ProcessID", 1234, "Data", bag_pack("url", "www.bing.com"))

結果

print_0
{“Level”:“Information”,“ProcessID”:1234,“Data”:{“url”:“www.bing.com”}}

範例 2

下列範例會使用 『.』 運算子,從屬性包建立屬性包並擷取值。

datatable (
    Source: int,
    Destination: int,
    Message: string
) [
    1234, 100, "AA", 
    4567, 200, "BB",
    1212, 300, "CC" 
]
| extend MyBag=bag_pack("Dest", Destination, "Mesg", Message)
| project-away Source, Destination, Message
| extend MyBag_Dest=MyBag.Dest, MyBag_Mesg=MyBag.Mesg

結果

MyBag MyBag_Dest MyBag_Mesg
{“Dest”:100,“Mesg”:“AA”} 100 AA
{“Dest”:200,“Mesg”:“BB”} 200 BB
{“Dest”:300,“Mesg”:“CC”} 300 CC

範例 3

下列範例使用兩個數據表 SmsMessagesMmsMessages,並從其他數據行傳回其通用數據行和屬性包。 數據表會在查詢中建立臨機操作。

SmsMessages

SourceNumber TargetNumber CharsCount
555-555-1234 555-555-1212 46
555-555-1234 555-555-1213 50
555-555-1212 555-555-1234 32

MmsMessages

SourceNumber TargetNumber AttachmentSize AttachmentType AttachmentName
555-555-1212 555-555-1213 200 jpeg Pic1
555-555-1234 555-555-1212 250 jpeg Pic2
555-555-1234 555-555-1213 300 png Pic3
let SmsMessages = datatable (
    SourceNumber: string,
    TargetNumber: string,
    CharsCount: string
) [
    "555-555-1234", "555-555-1212", "46", 
    "555-555-1234", "555-555-1213", "50",
    "555-555-1212", "555-555-1234", "32" 
];
let MmsMessages = datatable (
    SourceNumber: string,
    TargetNumber: string,
    AttachmentSize: string,
    AttachmentType: string,
    AttachmentName: string
) [
    "555-555-1212", "555-555-1213", "200", "jpeg", "Pic1",
    "555-555-1234", "555-555-1212", "250", "jpeg", "Pic2",
    "555-555-1234", "555-555-1213", "300", "png", "Pic3"
];
SmsMessages 
| join kind=inner MmsMessages on SourceNumber
| extend Packed=bag_pack("CharsCount", CharsCount, "AttachmentSize", AttachmentSize, "AttachmentType", AttachmentType, "AttachmentName", AttachmentName) 
| where SourceNumber == "555-555-1234"
| project SourceNumber, TargetNumber, Packed

結果

SourceNumber TargetNumber 包裝好的
555-555-1234 555-555-1213 {“CharsCount”:“50”,“AttachmentSize”:“250”,“AttachmentType”:“jpeg”,“AttachmentName”:“Pic2”}
555-555-1234 555-555-1212 {“CharsCount”:“46”,“AttachmentSize”:“250”,“AttachmentType”:“jpeg”,“AttachmentName”:“Pic2”}
555-555-1234 555-555-1213 {“CharsCount”:“50”,“AttachmentSize”:“300”,“AttachmentType”:“png”,“AttachmentName”:“Pic3”}
555-555-1234 555-555-1212 {“CharsCount”:“46”,“AttachmentSize”:“300”,“AttachmentType”:“png”,“AttachmentName”:“Pic3”}