示例#1
0
func (nr *nameResolver) handlePosition(pos *ast.PositionExpr) {
	ctx := nr.currentContext()
	if pos.N < 1 || pos.N > len(ctx.fieldList) {
		nr.Err = errors.Errorf("Unknown column '%d'", pos.N)
		return
	}
	pos.Refer = ctx.fieldList[pos.N-1]
}
示例#2
0
文件: resolver.go 项目: mumubusu/tidb
func (nr *nameResolver) handlePosition(pos *ast.PositionExpr) {
	ctx := nr.currentContext()
	if pos.N < 1 || pos.N > len(ctx.fieldList) {
		nr.Err = errors.Errorf("Unknown column '%d'", pos.N)
		return
	}
	pos.Refer = ctx.fieldList[pos.N-1]
	if nr.currentContext().inGroupBy {
		// make sure item is not aggregate function
		if ast.HasAggFlag(pos.Refer.Expr) {
			nr.Err = errors.New("group by cannot contain aggregate function")
		}
	}
}
示例#3
0
func (nr *nameResolver) handlePosition(pos *ast.PositionExpr) {
	ctx := nr.currentContext()
	if pos.N < 1 || pos.N > len(ctx.fieldList) {
		nr.Err = errors.Errorf("Unknown column '%d'", pos.N)
		return
	}
	matched := ctx.fieldList[pos.N-1]
	nf := *matched
	expr := matched.Expr
	if cexpr, ok := expr.(*ast.ColumnNameExpr); ok {
		expr = cexpr.Refer.Expr
	}
	nf.Expr = expr
	pos.Refer = &nf
	if nr.currentContext().inGroupBy {
		// make sure item is not aggregate function
		if ast.HasAggFlag(pos.Refer.Expr) {
			nr.Err = errors.New("group by cannot contain aggregate function")
		}
	}
}