示例#1
0
func (e *havingAndOrderbyResolver) Enter(inNode ast.Node) (ast.Node, bool) {
	switch v := inNode.(type) {
	case *ast.ValueExpr, *ast.ColumnName, *ast.ParenthesesExpr:
	case *ast.ColumnNameExpr:
		var first, second expression.Schema
		var col *expression.Column
		fromSchema := e.proj.GetChildByIndex(0).GetSchema()
		fromSchemaFirst := e.orderBy && e.inExpr
		if fromSchemaFirst {
			first, second = fromSchema, e.proj.GetSchema()
			col, e.err = first.FindColumn(v.Name)
		} else {
			first, second = e.proj.GetSchema(), fromSchema
			col, e.err = first.FindSelectFieldColumn(v.Name, e.proj.Exprs)
		}
		if e.err != nil {
			return inNode, true
		}
		if col == nil {
			if fromSchemaFirst {
				col, e.err = second.FindSelectFieldColumn(v.Name, e.proj.Exprs)
			} else {
				col, e.err = second.FindColumn(v.Name)
			}

			if e.err != nil {
				return inNode, true
			}
			if col == nil {
				e.err = errors.Errorf("Can't find Column %s", v.Name.Name)
				return inNode, true
			}
			if !fromSchemaFirst {
				e.addProjectionExpr(v, col)
			} else {
				e.mapper[v] = col
			}
		} else if fromSchemaFirst {
			e.addProjectionExpr(v, col)
		} else {
			e.mapper[v] = col
		}
	case *ast.SubqueryExpr, *ast.CompareSubqueryExpr, *ast.ExistsSubqueryExpr:
		return inNode, true
	default:
		e.inExpr = true
	}
	return inNode, false
}