filter-expressions
它能做什么
这项技能说明如何为 Lightdash 查询工具编写筛选表达式。适合需要行筛选或条件指标筛选的查询的分析人员和开发者。
适用场景
- ✓当你需要把 Lightdash 查询筛选为特定行时。
- ✓当你想让自定义指标只统计符合某个条件的行时。
- ✓当你在 Lightdash 中用筛选条件搜索字段值时。
技能链接
https://github.com/lightdash/lightdash/blob/main/packages/backend/src/ee/services/ai/skills/builtInSkills/filter-expressions/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请运行一个 Lightdash 查询,计算总营收,但只包括北部地区、状态为已完成的订单。”
每周 5 个新技能,1 分钟读完。
工作原理
这项技能说明如何把每个筛选表达式放入正确的类别,例如维度、指标或表计算。它还提醒,不要把只用于筛选的字段加入分组。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Read this before writing filters for expression-enabled tools. It does not apply to tools whose schemas use structured filter objects. Follow each tool's input schema; this skill does not enable unavailable tools or filter modes.
Filter Expressions
For run_metric_query, set queryConfig.filters to null when no query filters are needed. Otherwise, dimensions, metrics, and tableCalculations are independent string expressions or null.
- A non-null category contains one raw string expression.
- Choose the category from discovered field metadata (its dimension/metric kind), never from a field name or whether a numeric field sounds metric-like. A raw numeric dimension belongs in
dimensions; only metrics and custom metrics belong inmetrics. - A field used only to restrict rows stays in its filter expression. Do not add it to
queryConfig.dimensionsunless the user asked to group by or display it: extra selected dimensions change aggregation and table-calculation grain. - Table calculations belong only in
tableCalculations. - Each category is flat and uses AND or OR, never both.
- The three categories combine implicitly with AND.
- Aggregation custom metric filters are flat AND expressions.
- Omit
search_field_values.filtersfor an unscoped search. When present, it is one flat dimension expression string and is AND-only. - The tool schema is authoritative for where each string is placed.
Raw placement examples:
dimensions: orders_status equals=completed,shipped AND orders_order_date inThePast=2{unit:weeks,completed:true}
dimensions (alternatives): orders_promo_code startsWith=VIP OR orders_promo_code endsWith=25
metrics: orders_total_order_amount greaterThan=100
tableCalculations: rank lessThanOrEqual=10
Join flat rules with AND or OR. Do not mix both connectors in one expression.
Bare scalars work. Double-quote reserved and whitespace/punctuation strings (apostrophes/parentheses); quote when unsure. Quoted commas/braces literal; backslash escapes. E.g.
orders_product_name equals="Coffee Filters (100pk)".Limits: 256 rules; 256 values including settings/rule; 256 characters/literal; 16384 characters/expression.
string
Grammar: <field> <operator form>
isNull [0 values]notNull [0 values]equals=<value>[,<value>...] [1+ values]notEquals=<value>[,<value>...] [1+ values]startsWith=<value>[,<value>...] [1+ values]endsWith=<value>[,<value>...] [1+ values]include=<value>[,<value>...] [1+ values]doesNotInclude=<value>[,<value>...] [1+ values]
number
Grammar: <field> <operator form>
isNull [0 values]notNull [0 values]equals=<value>[,<value>...] [1+ values]notEquals=<value>[,<value>...] [1+ values]lessThan=<value> [1 value]lessThanOrEqual=<value> [1 value]greaterThan=<value> [1 value]greaterThanOrEqual=<value> [1 value]inBetween=<first value>,<second value> [2 values]notInBetween=<first value>,<second value> [2 values]
date
Grammar: <field> <operator form>
isNull [0 values]notNull [0 values]equals=<value>[,<value>...] [1+ values]notEquals=<value>[,<value>...] [1+ values]lessThan=<value> [1 value]lessThanOrEqual=<value> [1 value]greaterThan=<value> [1 value]greaterThanOrEqual=<value> [1 value]inThePast=<count>{unit:<unit>,completed:<bool>} [1 count; settings required]notInThePast=<count>{unit:<unit>,completed:<bool>} [1 count; settings required]inTheNext=<count>{unit:<unit>,completed:<bool>} [1 count; settings required]inTheCurrent=<unit>[{toDate:true[,excludeToday:true]}] [1 unit; settings optional]notInTheCurrent=<unit>[{toDate:true[,excludeToday:true]}] [1 unit; settings optional]inBetween=<first value>,<second value> [2 values]- Units: days, weeks, months, quarters, years; completed=false includes partial, true completed only.
- Current-period bounds: {toDate:true} ends the current week/month/quarter/year at today ("month to date"); {toDate:true,excludeToday:true} ends it at yesterday (today's partial data excluded). Not valid for days.
boolean
Grammar: <field> <operator form>
isNull [0 values]notNull [0 values]equals=<value> [1 value]notEquals=<value> [1 value]
常见问题
筛选条件应该放在哪里?
每个筛选条件应放在与其字段相对应的类别中,例如维度或指标。
筛选会改变分组吗?
只有当你把该字段加入分组时才会。因此技能说明,不要把仅用于筛选的字段加入分组。
所有筛选模式都可用吗?
技能遵循每个工具自身的输入结构,因此只有该工具支持的模式才适用。
详情
作者的原始描述
Author filter expressions for run_metric_query and search_field_values, including conditional custom metric filters.
repo: lightdash/lightdash
热度
- GitHub 星标
- 6.2k
- 排名
- #14397
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
breakup-pr
6.2k帮你的智能体把一个大型拉取请求拆分成较小的、可堆叠的切片,每次可以审阅并合并一个。
lightdash-agent-slack-messaging
6.2k帮你的智能体根据现有证据,为 Lightdash 管理员撰写简短、友好的维护与活动报告。
developing-in-lightdash
6.2k帮你的智能体以 JSON 形式读取、创建和编辑 Lightdash 仪表板与图表,包括每种图表类型的设置。
mcp-artifact-integration
6.2k帮你的智能体在 HTML 或 React 产物中展示 Lightdash 查询结果,并处理加载、错误和空数据状态。