Merge pull request #1170 from influxdb/parse-select-star

Make influxql parse SELECT *
pull/1192/head
Ben Johnson 2014-11-30 15:09:23 -07:00
commit 7bd3613b72
3 changed files with 25 additions and 2 deletions

View File

@ -47,6 +47,7 @@ func (_ *TimeLiteral) node() {}
func (_ *DurationLiteral) node() {}
func (_ *BinaryExpr) node() {}
func (_ *ParenExpr) node() {}
func (_ *Wildcard) node() {}
// Query represents a collection of order statements.
type Query struct {
@ -85,6 +86,7 @@ func (_ *TimeLiteral) expr() {}
func (_ *DurationLiteral) expr() {}
func (_ *BinaryExpr) expr() {}
func (_ *ParenExpr) expr() {}
func (_ *Wildcard) expr() {}
// Source represents a source of data for a statement.
type Source interface {
@ -234,6 +236,10 @@ type ParenExpr struct {
Expr Expr
}
// Wildcard represents a wild card expression.
type Wildcard struct {
}
// Visitor can be called by Walk to traverse an AST hierarchy.
// The Visit() function is called once per node.
type Visitor interface {

View File

@ -90,8 +90,6 @@ func (p *Parser) ParseStatement() (Statement, error) {
func (p *Parser) parseSelectStatement() (*SelectStatement, error) {
stmt := &SelectStatement{}
// TODO: handle SELECT *
// Parse fields: "SELECT FIELD+".
fields, err := p.parseFields()
if err != nil {
@ -264,6 +262,14 @@ func (p *Parser) parseDropContinuousQueryStatement() (*DropContinuousQueryStatem
// parseFields parses a list of one or more fields.
func (p *Parser) parseFields() (Fields, error) {
var fields Fields
// Check for "*" (i.e., "all fields")
if tok, _, _ := p.scanIgnoreWhitespace(); tok == MUL {
fields = append(fields, &Field{&Wildcard{}, ""})
return fields, nil
}
p.unscan()
for {
// Parse the field.
f, err := p.parseField()

View File

@ -45,6 +45,17 @@ func TestParser_ParseStatement(t *testing.T) {
stmt influxql.Statement
err string
}{
// SELECT * statement
{
s: `SELECT * FROM myseries`,
stmt: &influxql.SelectStatement{
Fields: influxql.Fields{
&influxql.Field{Expr: &influxql.Wildcard{}},
},
Source: &influxql.Series{Name: "myseries"},
},
},
// SELECT statement
{
s: `SELECT field1, field2 ,field3 AS field_x FROM myseries WHERE host = 'hosta.influxdb.org' GROUP BY 10h LIMIT 20 ORDER BY ASC;`,