예제 #1
0
파일: having.go 프로젝트: lovedboy/tidb
func (v *havingVisitor) VisitCall(c *expression.Call) (expression.Expression, error) {
	isAggregate := expression.IsAggregateFunc(c.F)

	if v.inAggregate && isAggregate {
		// aggregate function can't contain aggregate function
		return nil, errors.Errorf("Invalid use of group function")
	}

	if isAggregate {
		// set true to let outer know we are in aggregate function.
		v.inAggregate = true
	}

	var err error
	for i, e := range c.Args {
		c.Args[i], err = e.Accept(v)
		if err != nil {
			return nil, errors.Trace(err)
		}
	}

	if isAggregate {
		v.inAggregate = false
	}

	return c, nil
}
예제 #2
0
파일: groupby.go 프로젝트: lovedboy/tidb
func (v *groupByVisitor) VisitCall(c *expression.Call) (expression.Expression, error) {
	ok := expression.IsAggregateFunc(c.F)
	if ok {
		return nil, errors.Errorf("group by cannot contain aggregate function %s", c)
	}

	var err error
	for i, e := range c.Args {
		c.Args[i], err = e.Accept(v)
		if err != nil {
			return nil, errors.Trace(err)
		}
	}

	return c, nil
}