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

parser: update as option #338

Merged
merged 3 commits into from
Oct 10, 2015
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
27 changes: 22 additions & 5 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ import (
SubSelect "Sub Select"
Symbol "Constraint Symbol"
SystemVariable "System defined variable name"
TableAsOpt "table as option"
TableConstraint "table constraint definition"
TableElement "table definition element"
TableElementList "table definition element list"
Expand Down Expand Up @@ -1536,15 +1537,22 @@ Field1:
}

AsOpt:
identifier
Identifier
{
// TODO: check potential bug
$$ = $1
}
| "AS" Identifier
{
$$ = $2
}
| stringLit
{
$$ = $1
}
| "AS" stringLit
{
$$ = $2
}

FieldList:
Field
Expand Down Expand Up @@ -2911,11 +2919,11 @@ TableFactor:
{
$$ = &rsets.TableSource{Source: $1, Name: $2.(string)}
}
| '(' SelectStmt ')' AsOpt
| '(' SelectStmt ')' TableAsOpt
{
$$ = &rsets.TableSource{Source: $2, Name: $4.(string)}
}
| '(' UnionStmt ')' AsOpt
| '(' UnionStmt ')' TableAsOpt
{
$$ = &rsets.TableSource{Source: $2, Name: $4.(string)}
}
Expand All @@ -2928,11 +2936,20 @@ TableIdentOpt:
{
$$ = ""
}
| AsOpt
| TableAsOpt
{
$$ = $1
}

TableAsOpt:
Identifier
{
$$ = $1
}
| "AS" Identifier
{
$$ = $2
}

JoinTable:
/* Use %prec to evaluate production TableRef before cross join */
Expand Down
10 changes: 10 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,16 @@ func (s *testParserSuite) TestParser0(c *C) {

// For check clause
{"CREATE TABLE Customer (SD integer CHECK (SD > 0), First_Name varchar(30));", true},

// For as
{"select 1 as a, 1 as `a`, 1 as \"a\", 1 as 'a'", true},
{`select 1 as a, 1 as "a", 1 as 'a'`, true},
{`select 1 a, 1 "a", 1 'a'`, true},
{`select * from t as "a"`, false},
{`select * from t a`, true},
{`select * from t as a`, true},
{"select 1 full, 1 row, 1 abs", true},
{"select * from t full, t1 row, t2 abs", true},
}

for _, t := range table {
Expand Down