File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed
Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -186,31 +186,29 @@ func extractGroupFields(s *SelectStatement) []string {
186186func buildSelectFields (fields []Field ) (aggMap map [string ]aggregator.AggregateType , fieldMap map [string ]string ) {
187187 selectFields := make (map [string ]aggregator.AggregateType )
188188 fieldMap = make (map [string ]string )
189- fieldExpressions := make (map [string ]types.FieldExpression )
190189
191190 for _ , f := range fields {
192191 if alias := f .Alias ; alias != "" {
193- t , n , expression , allFields := ParseAggregateTypeWithExpression (f .Expression )
192+ t , n , _ , _ := ParseAggregateTypeWithExpression (f .Expression )
194193 if t != "" {
195194 // 使用别名作为聚合器的key,而不是字段名
196195 selectFields [alias ] = t
196+
197+ // 字段映射:输出字段名(别名) -> 输入字段名(保持与buildSelectFieldsWithExpressions一致)
197198 if n != "" {
198- fieldMap [n ] = alias
199+ fieldMap [alias ] = n
199200 } else {
200- // 当没有特定字段名时,使用表达式或别名
201+ // 如果没有提取到字段名,使用别名本身
201202 fieldMap [alias ] = alias
202203 }
203-
204- // 如果存在表达式,保存表达式信息
205- if expression != "" {
206- fieldExpressions [alias ] = types.FieldExpression {
207- Field : n ,
208- Expression : expression ,
209- Fields : allFields ,
210- }
211- }
212204 }
213- // 如果聚合类型和字段名都为空,不做处理,避免空聚合器类型
205+ } else {
206+ // 没有别名的情况,使用表达式本身作为字段名
207+ t , n , _ , _ := ParseAggregateTypeWithExpression (f .Expression )
208+ if t != "" && n != "" {
209+ selectFields [n ] = t
210+ fieldMap [n ] = n
211+ }
214212 }
215213 }
216214 return selectFields , fieldMap
You can’t perform that action at this time.
0 commit comments