@@ -95,9 +95,8 @@ func (b *Builder) buildGroupingCols(fromScope, projScope *scope, groupby ast.Gro
9595 // 3) an index into selects
9696 // 4) a simple non-aggregate expression
9797 groupings := make ([]sql.Expression , 0 )
98- if fromScope .groupBy == nil {
99- fromScope .initGroupBy ()
100- }
98+ fromScope .initGroupBy ()
99+
101100 g := fromScope .groupBy
102101 for _ , e := range groupby {
103102 var col scopeColumn
@@ -194,9 +193,7 @@ func (b *Builder) buildAggregation(fromScope, projScope *scope, groupingCols []s
194193 // - grouping cols projection
195194 // - aggregate expressions
196195 // - output projection
197- if fromScope .groupBy == nil {
198- fromScope .initGroupBy ()
199- }
196+ fromScope .initGroupBy ()
200197
201198 group := fromScope .groupBy
202199 outScope := group .outScope
@@ -281,9 +278,7 @@ func (b *Builder) buildAggregateFunc(inScope *scope, name string, e *ast.FuncExp
281278 b .handleErr (err )
282279 }
283280
284- if inScope .groupBy == nil {
285- inScope .initGroupBy ()
286- }
281+ inScope .initGroupBy ()
287282 gb := inScope .groupBy
288283
289284 if strings .EqualFold (name , "count" ) {
@@ -466,9 +461,7 @@ func (b *Builder) buildCountStarAggregate(e *ast.FuncExpr, gb *groupBy) sql.Expr
466461
467462// buildGroupConcat builds a GROUP_CONCAT aggregate function
468463func (b * Builder ) buildGroupConcat (inScope * scope , e * ast.GroupConcatExpr ) sql.Expression {
469- if inScope .groupBy == nil {
470- inScope .initGroupBy ()
471- }
464+ inScope .initGroupBy ()
472465 gb := inScope .groupBy
473466
474467 args := make ([]sql.Expression , len (e .Exprs ))
@@ -898,9 +891,7 @@ func (b *Builder) buildHaving(fromScope, projScope, outScope *scope, having *ast
898891 if having == nil {
899892 return
900893 }
901- if fromScope .groupBy == nil {
902- fromScope .initGroupBy ()
903- }
894+ fromScope .initGroupBy ()
904895
905896 havingScope := b .newScope ()
906897 if fromScope .parent != nil {
0 commit comments