@@ -38,6 +38,7 @@ var _ sql.Expressioner = (*GroupBy)(nil)
3838var _ sql.Node = (* GroupBy )(nil )
3939var _ sql.Projector = (* GroupBy )(nil )
4040var _ sql.CollationCoercible = (* GroupBy )(nil )
41+ var _ sql.Describable = (* GroupBy )(nil )
4142
4243// NewGroupBy creates a new GroupBy node. Like Project, GroupBy is a top-level node, and contains all the fields that
4344// will appear in the output of the query. Some of these fields may be aggregate functions, some may be columns or
@@ -169,6 +170,28 @@ func (g *GroupBy) DebugString() string {
169170 return pr .String ()
170171}
171172
173+ func (g * GroupBy ) Describe (options sql.DescribeOptions ) string {
174+ pr := sql .NewTreePrinter ()
175+ _ = pr .WriteNode ("GroupBy" )
176+
177+ var selectDeps = make ([]string , len (g .SelectDeps ))
178+ for i , e := range g .SelectDeps {
179+ selectDeps [i ] = sql .Describe (e , options )
180+ }
181+
182+ var grouping = make ([]string , len (g .GroupByExprs ))
183+ for i , g := range g .GroupByExprs {
184+ grouping [i ] = sql .Describe (g , options )
185+ }
186+
187+ _ = pr .WriteChildren (
188+ fmt .Sprintf ("select: %s" , strings .Join (selectDeps , ", " )),
189+ fmt .Sprintf ("group: %s" , strings .Join (grouping , ", " )),
190+ sql .Describe (g .Child , options ),
191+ )
192+ return pr .String ()
193+ }
194+
172195// Expressions implements the Expressioner interface.
173196func (g * GroupBy ) Expressions () []sql.Expression {
174197 var exprs []sql.Expression
0 commit comments