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

Vinai/group concat #366

Merged
merged 23 commits into from Apr 18, 2021
Merged

Vinai/group concat #366

merged 23 commits into from Apr 18, 2021

Conversation

VinaiRachakonda
Copy link
Contributor

@VinaiRachakonda VinaiRachakonda commented Apr 11, 2021

This PR adds support for the Group_Concat Aggregation Function

@@ -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",
Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Member

@zachmu zachmu left a 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`,
Copy link
Member

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

@@ -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",
Copy link
Member

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

@@ -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",
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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()
Copy link
Member

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)
Copy link
Member

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

@VinaiRachakonda VinaiRachakonda merged commit b78e941 into master Apr 18, 2021
@Hydrocharged Hydrocharged deleted the vinai/group-concat branch December 8, 2021 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants