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
Vinai/group concat #366
Vinai/group concat #366
Conversation
sql/analyzer/validation_rules.go
Outdated
@@ -80,7 +80,7 @@ var ( | |||
// ErrSubqueryMultipleColumns is returned when an expression subquery returns | |||
// more than a single column. | |||
ErrSubqueryMultipleColumns = errors.NewKind( | |||
"subquery expressions can only return a single column", | |||
"operand contains more than one column", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should create a new package for errors. That way errors like these can be properly associated with their MySQL code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an error is user facing, put it in the sql package in errors.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a bunch of places that break this rule in the analyzer, fix them when you find them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally quite good, just a few comments. Nice work!
Expected: []sql.Row{{"2"}}, | ||
}, | ||
{ | ||
Query: `SELECT group_concat(DISTINCT attribute ORDER BY attribute ASC) FROM t`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a few test queries with WHERE clauses as well
sql/analyzer/validation_rules.go
Outdated
@@ -80,7 +80,7 @@ var ( | |||
// ErrSubqueryMultipleColumns is returned when an expression subquery returns | |||
// more than a single column. | |||
ErrSubqueryMultipleColumns = errors.NewKind( | |||
"subquery expressions can only return a single column", | |||
"operand contains more than one column", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an error is user facing, put it in the sql package in errors.go
sql/analyzer/validation_rules.go
Outdated
@@ -80,7 +80,7 @@ var ( | |||
// ErrSubqueryMultipleColumns is returned when an expression subquery returns | |||
// more than a single column. | |||
ErrSubqueryMultipleColumns = errors.NewKind( | |||
"subquery expressions can only return a single column", | |||
"operand contains more than one column", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a bunch of places that break this rule in the analyzer, fix them when you find them
|
||
sb := strings.Builder{} | ||
for i, row := range rows { | ||
lastIdx := len(row) - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is called the fencepost problem, and it's usually solved in the opposite way: print the separator unless this is the first element. Then print the element.
} | ||
ret := sb.String() | ||
|
||
if len(ret) > g.maxLen { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to do this during the loop (and exit early), rather than at the end. Otherwise you blow up memory for no reason
} | ||
|
||
func (g *GroupConcat) Resolved() bool { | ||
for _, se := range g.selectExprs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the sort fields? They might not be resolved
} | ||
|
||
func (g *GroupConcat) Children() []sql.Expression { | ||
arr := g.sf.ToExpressions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well inline this var
} | ||
|
||
// Get the order by expression using the length of the sort fields. | ||
delim := len(g.sf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delim is a bad name here, considering the context
This PR adds support for the Group_Concat Aggregation Function