check for empty values in query

This commit is contained in:
Todd Gruben 2014-07-28 16:56:40 +00:00
parent a55c6cb2f3
commit 671036432f
2 changed files with 27 additions and 1 deletions

View file

@ -214,7 +214,20 @@ ArgLoop:
if query.Operation == "get" && query.Args["frame"] == nil {
query.Args["frame"] = "general"
}
if len(query.Args) == 0 && len(query.Subqueries) == 0 {
if query.Operation == "count" {
return nil, fmt.Errorf("No Args Given")
}
if query.Operation == "intersect" {
return nil, fmt.Errorf("No Args Given")
}
if query.Operation == "union" {
return nil, fmt.Errorf("No Args Given")
}
if query.Operation == "difference" {
return nil, fmt.Errorf("No Args Given")
}
}
return query, nil
}

View file

@ -5,6 +5,7 @@ import (
"pilosa/db"
"pilosa/util"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
@ -202,4 +203,16 @@ func TestQueryPlanner(t *testing.T) {
So(qp[3].(*TopNQueryStep).Input, ShouldEqual, qp[2].(GetQueryStep).Id)
So(qp[3].(*TopNQueryStep).N, ShouldEqual, 50)
})
Convey("Get query plan - including parsing", t, func() {
_, err := QueryForPQL("count()")
So(err, ShouldNotEqual, nil)
_, err = QueryForPQL("count(intersect())")
So(err, ShouldNotEqual, nil)
_, err = QueryForPQL("count(get(10, default))")
So(err, ShouldEqual, nil)
_, err = QueryForPQL("count(union())")
So(err, ShouldNotEqual, nil)
})
}