Skip to content

Commit

Permalink
planner/builder: make the code easy to understand #480
Browse files Browse the repository at this point in the history
[summary]
replace the verbose variables with meaningful variables
[test case]
N/A
[patch codecov]
N/A
  • Loading branch information
andyli029 authored and BohuTANG committed Dec 2, 2019
1 parent b689ebe commit 8f7a4c5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/planner/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func processSelect(log *xlog.Log, router *router.Router, database string, node *
}

if node.Having != nil {
if err = pushHavings(root, node.Having.Expr, tbInfos); err != nil {
if err = pushHavings(root, node.Having.Expr); err != nil {
return nil, err
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/planner/builder/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func checkJoinOn(lpn, rpn PlanNode, join exprInfo) (exprInfo, error) {

// parseHaving used to check the having exprs and parse into tuples.
// unsupport: `select sum(t2.id) as tmp, t1.id from t2,t1 having tmp=1`.
func parseHaving(exprs sqlparser.Expr, tbInfos map[string]*tableInfo, fields []selectTuple) ([]exprInfo, error) {
func parseHaving(exprs sqlparser.Expr, fields []selectTuple) ([]exprInfo, error) {
var tuples []exprInfo
filters := splitAndExpression(nil, exprs)
for _, filter := range filters {
Expand Down Expand Up @@ -394,18 +394,18 @@ func getTbsInExpr(expr sqlparser.Expr) []string {
func replaceCol(info exprInfo, colMap map[string]selectTuple) (exprInfo, error) {
var tables []string
var columns []*sqlparser.ColName
for _, col := range info.cols {
field, err := getMatchedField(col.Name.String(), colMap)
for _, old := range info.cols {
new, err := getMatchedField(old.Name.String(), colMap)
if err != nil {
return info, err
}
if field.aggrFuc != "" {
if new.aggrFuc != "" {
return info, errors.New("unsupported: aggregation.field.in.subquery.is.used.in.clause")
}

info.expr = sqlparser.ReplaceExpr(info.expr, col, field.info.expr)
columns = append(columns, field.info.cols...)
for _, referTable := range field.info.referTables {
info.expr = sqlparser.ReplaceExpr(info.expr, old, new.info.expr)
columns = append(columns, new.info.cols...)
for _, referTable := range new.info.referTables {
if !isContainKey(tables, referTable) {
tables = append(tables, referTable)
}
Expand Down
4 changes: 2 additions & 2 deletions src/planner/builder/expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestParserHaving(t *testing.T) {
err = p.pushSelectExprs(fields, nil, sel, aggTyp)
assert.Nil(t, err)

err = pushHavings(p, sel.Having.Expr, p.getReferTables())
err = pushHavings(p, sel.Having.Expr)
assert.Nil(t, err)
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestParserHavingError(t *testing.T) {
err = p.pushSelectExprs(fields, nil, sel, aggTyp)
assert.Nil(t, err)

err = pushHavings(p, sel.Having.Expr, p.getReferTables())
err = pushHavings(p, sel.Having.Expr)
got := err.Error()
assert.Equal(t, wants[i], got)
}
Expand Down
4 changes: 2 additions & 2 deletions src/planner/builder/plan_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func pushFilters(s PlanNode, expr sqlparser.Expr) (PlanNode, error) {
}

// pushHavings push a HAVING clause down.
func pushHavings(s PlanNode, expr sqlparser.Expr, tbInfos map[string]*tableInfo) error {
havings, err := parseHaving(expr, tbInfos, s.getFields())
func pushHavings(s PlanNode, expr sqlparser.Expr) error {
havings, err := parseHaving(expr, s.getFields())
if err != nil {
return err
}
Expand Down

0 comments on commit 8f7a4c5

Please sign in to comment.