@@ -264,6 +264,7 @@ func validateGroupBy(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop
264
264
case * plan.Having , * plan.Project , * plan.Sort :
265
265
// TODO: these shouldn't be skipped but we currently aren't able to validate GroupBys with selected aliased
266
266
// expressions and a lot of our tests group by aliases
267
+ // https://github.com/dolthub/dolt/issues/4998
267
268
return true
268
269
}
269
270
@@ -297,6 +298,8 @@ func validateGroupBy(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop
297
298
298
299
for _ , expr := range gb .SelectedExprs {
299
300
if ! expressionReferencesOnlyGroupBys (groupBys , expr ) {
301
+ // TODO: this is currently too restrictive. Dependent columns are fine to reference
302
+ // https://dev.mysql.com/doc/refman/8.4/en/group-by-functional-dependence.html
300
303
err = analyzererrors .ErrValidationGroupBy .New (expr .String ())
301
304
return false
302
305
}
@@ -310,12 +313,11 @@ func validateGroupBy(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop
310
313
func expressionReferencesOnlyGroupBys (groupBys map [string ]bool , expr sql.Expression ) bool {
311
314
valid := true
312
315
sql .Inspect (expr , func (expr sql.Expression ) bool {
313
- exprStr := strings .ToLower (expr .String ())
314
316
switch expr := expr .(type ) {
315
317
case nil , sql.Aggregation , * expression.Literal :
316
318
return false
317
319
default :
318
- if groupBys [exprStr ] {
320
+ if groupBys [strings . ToLower ( expr . String ()) ] {
319
321
return false
320
322
}
321
323
0 commit comments