Skip to content

Commit

Permalink
Merge pull request #338 from pingcap/siddontang/update-as
Browse files Browse the repository at this point in the history
parser: update as option
  • Loading branch information
shenli committed Oct 10, 2015
2 parents bf01d51 + b1f1335 commit e9433e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
27 changes: 22 additions & 5 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,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 @@ -1537,15 +1538,22 @@ Field1:
}

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

FieldList:
Field
Expand Down Expand Up @@ -2927,11 +2935,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 @@ -2944,11 +2952,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 @@ -499,6 +499,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

0 comments on commit e9433e5

Please sign in to comment.