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

sql/parse: support more than 2 tables on cross join #49

Merged
merged 1 commit into from
Feb 26, 2018
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: 4 additions & 4 deletions sql/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ func tableExprsToTable(te sqlparser.TableExprs) (sql.Node, error) {
return nodes[0], nil
}

if len(nodes) == 2 {
return plan.NewCrossJoin(nodes[0], nodes[1]), nil
join := plan.NewCrossJoin(nodes[0], nodes[1])
Copy link
Contributor

@ajnavarro ajnavarro Feb 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check the len of nodes before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i := 2; i < len(nodes); i++ {
join = plan.NewCrossJoin(join, nodes[i])
}

//TODO: Support N tables in JOIN.
return nil, errUnsupportedFeature("more than 2 tables in JOIN")
return join, nil
}

func tableExprToTable(te sqlparser.TableExpr) (sql.Node, error) {
Expand Down
13 changes: 13 additions & 0 deletions sql/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ var fixtures = map[string]sql.Node{
plan.NewUnresolvedTable("foo"),
),
),
`SELECT * FROM foo, bar, baz, qux`: plan.NewProject(
[]sql.Expression{expression.NewStar()},
plan.NewCrossJoin(
plan.NewCrossJoin(
plan.NewCrossJoin(
plan.NewUnresolvedTable("foo"),
plan.NewUnresolvedTable("bar"),
),
plan.NewUnresolvedTable("baz"),
),
plan.NewUnresolvedTable("qux"),
),
),
}

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