Skip to content

Commit 7ea932a

Browse files
committed
passes most tests
1 parent 0a910f3 commit 7ea932a

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

sql/planbuilder/aggregates.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,16 @@ func (b *Builder) buildAggFunctionArgs(inScope *scope, e *ast.FuncExpr, gb *grou
374374
e := b.selectExprToExpression(inScope, arg)
375375
switch e := e.(type) {
376376
case *expression.GetField:
377-
if e.TableId() == 0 {
378-
// TODO: not sure where this came from but it's not true
379-
// aliases are not valid aggregate arguments, the alias must be masking a column
380-
gf := b.selectExprToExpression(inScope.parent, arg)
381-
var ok bool
382-
e, ok = gf.(*expression.GetField)
383-
if !ok || e.TableId() == 0 {
384-
b.handleErr(fmt.Errorf("failed to resolve aggregate column argument: %s", gf))
385-
}
386-
}
377+
//if e.TableId() == 0 {
378+
// // TODO: not sure where this came from but it's not true
379+
// // aliases are not valid aggregate arguments, the alias must be masking a column
380+
// gf := b.selectExprToExpression(inScope.parent, arg)
381+
// // var ok bool
382+
// e, ok := gf.(*expression.GetField)
383+
// if !ok || e.TableId() == 0 {
384+
// b.handleErr(fmt.Errorf("failed to resolve aggregate column argument: %s", gf))
385+
// }
386+
//}
387387
args = append(args, e)
388388
col := scopeColumn{tableId: e.TableID(), db: e.Database(), table: e.Table(), col: e.Name(), scalar: e, typ: e.Type(), nullable: e.IsNullable()}
389389
gb.addInCol(col)

sql/planbuilder/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (b *Builder) analyzeSelectList(inScope, outScope *scope, selectExprs ast.Se
135135
err := sql.ErrColumnNotFound.New(gf.String())
136136
b.handleErr(err)
137137
}
138-
col = scopeColumn{id: id, tableId: gf.TableId(), col: e.Name(), db: gf.Database(), table: gf.Table(), typ: gf.Type(), scalar: e, nullable: gf.IsNullable(), originalCol: gf.Name()}
138+
col = scopeColumn{id: id, tableId: gf.TableId(), col: e.Name(), db: gf.Database(), table: gf.Table(), typ: gf.Type(), scalar: e, nullable: gf.IsNullable()}
139139
} else if sq, ok := e.Child.(*plan.Subquery); ok {
140140
col = scopeColumn{col: e.Name(), scalar: e, typ: sq.Type(), nullable: sq.IsNullable()}
141141
} else {

sql/planbuilder/scalar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (b *Builder) buildScalar(inScope *scope, e ast.Expr) (ex sql.Expression) {
125125
if !ok {
126126
alias, ok := inScope.selectColumnAliases[colName]
127127
if ok {
128-
return alias.scalarGf()
128+
return alias.scalar
129129
}
130130
sysVar, scope, ok := b.buildSysVar(v, ast.SetScope_None)
131131
if ok {

sql/planbuilder/scope.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ func (s *scope) copy() *scope {
443443
if !s.colset.Empty() {
444444
ret.colset = s.colset.Copy()
445445
}
446+
if s.selectColumnAliases != nil {
447+
ret.selectColumnAliases = make(map[string]scopeColumn, len(s.selectColumnAliases))
448+
for k, v := range s.selectColumnAliases {
449+
ret.selectColumnAliases[k] = v
450+
}
451+
}
446452

447453
return &ret
448454
}
@@ -650,7 +656,7 @@ func (c scopeColumn) scalarGf() sql.Expression {
650656
case *expression.ProcedureParam:
651657
return e
652658
case *expression.Alias:
653-
return e.Child
659+
return e
654660
}
655661
}
656662
if c.originalCol != "" {

0 commit comments

Comments
 (0)