Beispiel #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]
}
Beispiel #2
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]
	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")
		}
	}
}
Beispiel #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")
		}
	}
}
Beispiel #4
0
func (e *Evaluator) position(v *ast.PositionExpr) bool {
	v.SetDatum(*v.Refer.Expr.GetDatum())
	return true
}