Commits/
!425 merge fix/dimension-join-inner-0930 into br_release_930
fix(nl2sql): 将维表取值 JOIN 默认改为 INNER Created-by: wjk2333 Commit-by: wjk Merged-by: Wistomize Description: **【MR类型】** fix: 维表取中文名的默认 JOIN 从 LEFT 改为 INNER **【改了什么】** 维表展示名改写时,默认 LEFT JOIN 改为 INNER JOIN。 - dimension_join_system.md 第 2 条改为 INNER,并写明维表对不上的 fact 行丢掉 - _add_dimension_context 写入 sql_rules 的规则同步改为 INNER,避免 Validator 按旧 LEFT 规则扣分 - 维表改写单测里的示例 SQL 从 LEFT 改为 INNER **【为什么】** 业务侧确认:维表对不上的 fact 行不再保留。 **【影响】** 维表缺行时,查询结果行数和合计会变少;编码都能对上时,观感与 LEFT 接近。 **【测试计划】** - [x] 本地跑 tests/ut/agents/nl2sql/test_generator_dimension_join.py(7 passed) - [ ] 人工看一条带维表中文名的业务孪生问题,确认 JOIN 为 INNER - [ ] 人工看维表缺编码时,对应 fact 行不再出现 See merge request: datagallery/dataagent!425
3 file(s) changed+3-3
Mdataagent/agents/nl2sql/prompts/generator/dimension_join_system.md+1-1
@@ -3,7 +3,7 @@ You are a SQL rewriter. Add only the dimension value lookups explicitly provided
3 3 
4# Rules4# Rules
51. Preserve the query's metrics, filters, aggregation granularity, ordering, limits, and all unrelated logic.51. Preserve the query's metrics, filters, aggregation granularity, ordering, limits, and all unrelated logic.
6-2. For every provided mapping, add a separate `LEFT JOIN` whose condition is `<fact source>.<dimension> = <dimension table>.<key_column>`.6+2. For every provided mapping, add a separate `INNER JOIN` whose condition is `<fact source>.<dimension> = <dimension table>.<key_column>`. Fact rows that do not match the dimension table are dropped.
73. Replace the standalone projected dimension with `<dimension table alias>.<value_column>`, preserving the original fact dimension name as the output column alias.73. Replace the standalone projected dimension with `<dimension table alias>.<value_column>`, preserving the original fact dimension name as the output column alias.
84. Update matching `GROUP BY` and `ORDER BY` expressions to the value column.84. Update matching `GROUP BY` and `ORDER BY` expressions to the value column.
95. Keep existing `WHERE` and `HAVING` predicates on the fact key; only qualify them when needed.95. Keep existing `WHERE` and `HAVING` predicates on the fact key; only qualify them when needed.
Mdataagent/agents/nl2sql/utils/nl2sql_utils.py+1-1File content is under review, please try again later
Mtests/ut/agents/nl2sql/test_generator_dimension_join.py+1-1

Comments