Permalink
Browse files

Run through the parser code.

  • Loading branch information...
1 parent 1bcd54a commit f2960ce848aa8f1bd8e92b55305c853aaedb7a98 @umitanuki committed Feb 4, 2013
Showing with 27 additions and 8 deletions.
  1. +2 −2 src/bigpot/parser/gram.y
  2. +8 −6 src/bigpot/parser/query.go
  3. +17 −0 src/bigpot/parser/query_test.go
View
@@ -92,13 +92,13 @@ statement: SELECT column_list FROM table_list
column_list: IDENT
{
- ref := ColumnRef{name: $1}
+ ref := &ColumnRef{name: $1}
n := &ResTarget{name: $1, val: Node(ref)}
$$ = append(make([]Node, 0), Node(n))
}
| column_list ',' IDENT
{
- ref := ColumnRef{name: $3}
+ ref := &ColumnRef{name: $3}
n := &ResTarget{name: $3, val: Node(ref)}
$$ = append($1, Node(n))
}
View
@@ -8,7 +8,7 @@ import "bigpot/system"
type CommandType int
const (
- CMD_SELECT = iota
+ CMD_SELECT = CommandType(iota)
CMD_INSERT
CMD_UPDATE
CMD_DELETE
@@ -31,6 +31,7 @@ type Expr interface {
type Var struct {
resultType system.Oid
+ // TODO: AttributeId is int32?
VarNo uint16
VarAttNo uint16
}
@@ -44,7 +45,7 @@ type TargetEntry struct {
type RteType int
const (
- RTE_RELATION = iota
+ RTE_RELATION = RteType(iota)
RTE_SUBQUERY
RTE_JOIN
RTE_VALUES
@@ -88,12 +89,11 @@ func parseError(msg string) error {
return ParserError{msg: msg}
}
-func (parser *ParserImpl) Parse(query_string string) *Query {
+func (parser *ParserImpl) Parse(query_string string) (*Query, error) {
lexer := newLexer(query_string)
yyParse(lexer)
- query := &Query{}
-
- return query
+ node := TopList[0]
+ return parser.transformStmt(node)
}
func (parser *ParserImpl) transformStmt(node Node) (*Query, error) {
@@ -117,6 +117,8 @@ func (parser *ParserImpl) transformSelectStmt(stmt *SelectStmt) (query *Query, e
return
}
+ query.RangeTables = parser.namespace
+
return
}
@@ -7,6 +7,10 @@ import (
"bigpot/system"
)
+func init() {
+ access.DatabaseDir = "../access/testdata"
+}
+
var _ = Suite(&MySuite{})
func (s *MySuite) TestBuildAlias(c *C) {
relation := access.Relation{
@@ -25,3 +29,16 @@ func (s *MySuite) TestBuildAlias(c *C) {
c.Check(alias.ColumnNames[0], Equals, "mycol1")
c.Check(alias.ColumnNames[1], Equals, "mycol2")
}
+
+func (s *MySuite) TestTransform(c *C) {
+ parser := ParserImpl{}
+ query, err := parser.Parse("select oid, relname from bp_class")
+ if err != nil {
+ c.Error(err)
+ }
+
+ c.Check(query.TargetList[0].Expr.(*Var).VarAttNo, Equals, uint16(1))
+ c.Check(query.TargetList[1].Expr.(*Var).VarAttNo, Equals, uint16(2))
+ c.Check(query.RangeTables[0].RteType, Equals, RTE_RELATION)
+ c.Check(query.RangeTables[0].RelId, Equals, access.ClassRelId)
+}

0 comments on commit f2960ce

Please sign in to comment.