From 6e6f9087b67c25183e5f127bf616828ecb56c230 Mon Sep 17 00:00:00 2001 From: lmk <1095689763@qq.com> Date: Tue, 16 Jun 2026 18:56:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(qa):=20ISSUE-002=20=E2=80=94=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20parseExpression=20{field}=20=E5=8D=A0=E4=BD=8D?= =?UTF-8?q?=E7=AC=A6=E6=AE=8B=E7=95=99=20SQL=20=E8=AF=AD=E6=B3=95=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当衍生指标表达式引用未在 indicators 中勾选的字段时, 原代码返回 {fieldCode} 占位符,导致生成的 SQL 包含大括号语法错误。 改为始终返回裸 fieldCode,避免 SQL 错误。 --- common/report/builder/sql_builder.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/report/builder/sql_builder.go b/common/report/builder/sql_builder.go index f219388..11a4357 100644 --- a/common/report/builder/sql_builder.go +++ b/common/report/builder/sql_builder.go @@ -360,6 +360,8 @@ func (b *SQLBuilder) buildTimeGroupExpr(dateField, timeGroup string) string { } // parseExpression 解析衍生指标表达式 +// 将 {fieldCode} 占位符替换为原始字段名,当字段不在 indicators 中时仍返回 fieldCode +// 避免未替换的 {fieldCode} 占位符泄漏到 SQL 中导致语法错误 func (b *SQLBuilder) parseExpression(expr string, indicators []model.IndicatorSelect) string { re := regexp.MustCompile(`\{([^}]+)\}`) return re.ReplaceAllStringFunc(expr, func(match string) string { @@ -369,7 +371,8 @@ func (b *SQLBuilder) parseExpression(expr string, indicators []model.IndicatorSe return fieldCode } } - return match + // 字段不在 indicators 中也返回裸字段名(避免 {fieldCode} 残留 SQL 导致语法错误) + return fieldCode }) }