Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add only expr of aliasedExpr to weightstring function #7165

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion go/vt/vtgate/planbuilder/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,17 @@ func (rb *route) SupplyWeightString(colNumber int) (weightcolNumber int, err err
return 0, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "unexpected AST struct for query")
}

aliasExpr, ok := s.SelectExprs[colNumber].(*sqlparser.AliasedExpr)
if !ok {
return 0, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "unexpected AST struct for query %T", s.SelectExprs[colNumber])
}
expr := &sqlparser.AliasedExpr{
Expr: &sqlparser.FuncExpr{
Name: sqlparser.NewColIdent("weight_string"),
Exprs: []sqlparser.SelectExpr{
s.SelectExprs[colNumber],
&sqlparser.AliasedExpr{
Expr: aliasExpr.Expr,
},
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@

# scatter aggregate with memory sort and order by number, reuse weight_string
# we have to use a meaningless construct to test this.
"select textcol1, count(*) k from user group by textcol1 order by textcol1, k, textcol1"
"select textcol1 as t, count(*) k from user group by textcol1 order by textcol1, k, textcol1"
{
"QueryType": "SELECT",
"Original": "select textcol1, count(*) k from user group by textcol1 order by textcol1, k, textcol1",
"Original": "select textcol1 as t, count(*) k from user group by textcol1 order by textcol1, k, textcol1",
"Instructions": {
"OperatorType": "Sort",
"Variant": "Memory",
Expand All @@ -205,9 +205,9 @@
"Name": "user",
"Sharded": true
},
"FieldQuery": "select textcol1, count(*) as k, weight_string(textcol1) from user where 1 != 1 group by textcol1",
"FieldQuery": "select textcol1 as t, count(*) as k, weight_string(textcol1) from user where 1 != 1 group by textcol1",
"OrderBy": "2 ASC, 2 ASC",
"Query": "select textcol1, count(*) as k, weight_string(textcol1) from user group by textcol1 order by textcol1 asc, textcol1 asc",
"Query": "select textcol1 as t, count(*) as k, weight_string(textcol1) from user group by textcol1 order by textcol1 asc, textcol1 asc",
"Table": "user"
}
]
Expand Down