Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #754 from erizocosmico/fix/error-count-distinct
Browse files Browse the repository at this point in the history
sql/parse: error for unsupported distinct on aggregations
  • Loading branch information
ajnavarro authored Jun 19, 2019
2 parents b6dc0ee + 6ddeaf8 commit eaab179
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ var queries = []struct {
FROM (
SELECT
i,
COUNT(DISTINCT s) AS foo
COUNT(s) AS foo
FROM mytable
GROUP BY i
) AS q
Expand Down
6 changes: 5 additions & 1 deletion sql/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"strings"

opentracing "github.com/opentracing/opentracing-go"
"gopkg.in/src-d/go-errors.v1"
"github.com/src-d/go-mysql-server/sql"
"github.com/src-d/go-mysql-server/sql/expression"
"github.com/src-d/go-mysql-server/sql/expression/function"
"github.com/src-d/go-mysql-server/sql/plan"
"gopkg.in/src-d/go-errors.v1"
"vitess.io/vitess/go/vt/sqlparser"
)

Expand Down Expand Up @@ -765,6 +765,10 @@ func exprToExpression(e sqlparser.Expr) (sql.Expression, error) {
return nil, err
}

if v.Distinct {
return nil, ErrUnsupportedSyntax.New("DISTINCT on aggregations")
}

return expression.NewUnresolvedFunction(v.Name.Lowered(),
v.IsAggregate(), exprs...), nil
case *sqlparser.ParenExpr:
Expand Down
5 changes: 3 additions & 2 deletions sql/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package parse
import (
"testing"

errors "gopkg.in/src-d/go-errors.v1"
"github.com/src-d/go-mysql-server/sql/expression"
"github.com/src-d/go-mysql-server/sql/plan"
errors "gopkg.in/src-d/go-errors.v1"

"github.com/stretchr/testify/require"
"github.com/src-d/go-mysql-server/sql"
"github.com/stretchr/testify/require"
)

var fixtures = map[string]sql.Node{
Expand Down Expand Up @@ -1166,6 +1166,7 @@ var fixturesErrors = map[string]*errors.Kind{
`SELECT '2018-05-01' / INTERVAL 1 DAY`: ErrUnsupportedSyntax,
`SELECT INTERVAL 1 DAY + INTERVAL 1 DAY`: ErrUnsupportedSyntax,
`SELECT '2018-05-01' + (INTERVAL 1 DAY + INTERVAL 1 DAY)`: ErrUnsupportedSyntax,
`SELECT COUNT(DISTINCT foo) FROM b`: ErrUnsupportedSyntax,
}

func TestParseErrors(t *testing.T) {
Expand Down

0 comments on commit eaab179

Please sign in to comment.