You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Data Explorer:如何用多选参数筛选仪表板显示列?

使用多选参数筛选Azure Data Explorer仪表板列的解决方案

核心思路

通过将表列打包为动态对象,结合多选参数计算需要保留/移除的列,再通过bag_remove/bag_keep和bag_unpack完成列筛选,以下是具体实现示例:

场景1:多选参数为「需要保留的列」

假设仪表板的多选参数名为SelectedColumns,参数值是类似["ColumnA", "ColumnB"]的动态数组,查询示例如下:

// 替换YourTable为实际表名
YourTable
| project AllColumns = pack_all() // 将所有列打包为动态键值对对象
| extend ColumnNames = bag_keys(AllColumns) // 提取所有列名
| extend ColumnsToKeep = dynamic([{SelectedColumns}]) // 引入多选参数
| extend ColumnsToRemove = set_difference(ColumnNames, ColumnsToKeep) // 计算需移除的列
| mv-expand ColumnsToRemove to typeof(string) // 展开需移除的列名单行
| evaluate bag_remove(AllColumns, ColumnsToRemove) // 从打包对象中移除不需要的列
| evaluate bag_unpack(AllColumns) // 解包剩余列为单独列

场景2:多选参数为「需要排除的列」

如果多选参数是要排除的列,只需调整set_difference的参数顺序,改用bag_keep保留目标列:

YourTable
| project AllColumns = pack_all()
| extend ColumnNames = bag_keys(AllColumns)
| extend ColumnsToRemove = dynamic([{SelectedColumns}]) // 引入要排除的列参数
| extend ColumnsToKeep = set_difference(ColumnNames, ColumnsToRemove) // 计算需保留的列
| mv-expand ColumnsToKeep to typeof(string)
| evaluate bag_keep(AllColumns, ColumnsToKeep) // 保留指定列
| evaluate bag_unpack(AllColumns)

关键命令说明

  • pack_all(): 把表中所有列转换为一个动态对象,统一处理列筛选逻辑
  • bag_keys(): 提取动态对象的所有键(对应原表的列名)
  • set_difference(): 计算两个列名集合的差集,快速得到需要保留或移除的列
  • mv-expand: 将数组类型的列展开为多行,适配bag_remove/bag_keep的逐行处理要求
  • bag_remove/bag_keep: 从动态对象中移除或保留指定键(列名)
  • bag_unpack: 将处理后的动态对象还原为单独的列,符合仪表板展示需求

内容的提问来源于stack exchange,提问作者Dawid Coetzee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 20:12:44