Skip to content

Commit

Permalink
add more parameter checks, improve error messages to user
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed May 18, 2016
1 parent c2ac637 commit 5181c6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions influxql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1619,10 +1619,13 @@ func (s *SelectStatement) validateAggregates(tr targetRequirement) error {
} else if !ok {
return fmt.Errorf("must use aggregate function with %s", expr.Name)
}
for i, arg := range expr.Args[1:3] {
if _, ok := arg.(*IntegerLiteral); !ok {
return fmt.Errorf("expected integer argument as %dth arg in %s", i+1, expr.Name)
}
if arg, ok := expr.Args[1].(*IntegerLiteral); !ok {
return fmt.Errorf("expected integer argument as second arg in %s", expr.Name)
} else if arg.Val <= 0 {
return fmt.Errorf("second arg to %s must be greater than 0, got %d", expr.Name, arg.Val)
}
if _, ok := expr.Args[2].(*IntegerLiteral); !ok {
return fmt.Errorf("expected integer argument as third arg in %s", expr.Name)
}
default:
if err := s.validSelectWithAggregate(); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion influxql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,15 @@ func (r *FloatHoltWintersReducer) roundTime(t int64) int64 {
}

func (r *FloatHoltWintersReducer) Emit() []FloatPoint {
if l := len(r.points); l < 2 || r.seasonal && l < r.m {
if l := len(r.points); l < 2 || r.seasonal && l < r.m || r.h <= 0 {
return nil
}
// First fill in r.y with values and NaNs for missing values
start, stop := r.roundTime(r.points[0].Time), r.roundTime(r.points[len(r.points)-1].Time)
count := (stop - start) / r.interval
if count <= 0 {
return nil
}
r.y = make([]float64, 1, count)
r.y[0] = r.points[0].Value
t := r.roundTime(r.points[0].Time)
Expand Down
3 changes: 3 additions & 0 deletions influxql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,9 @@ func TestParser_ParseStatement(t *testing.T) {
{s: `SELECT holt_winters(value) FROM myseries where time < now() and time > now() - 1d`, err: `invalid number of arguments for holt_winters, expected 3, got 1`},
{s: `SELECT holt_winters(value, 10, 2) FROM myseries where time < now() and time > now() - 1d`, err: `must use aggregate function with holt_winters`},
{s: `SELECT holt_winters(min(value), 10, 2) FROM myseries where time < now() and time > now() - 1d`, err: `holt_winters aggregate requires a GROUP BY interval`},
{s: `SELECT holt_winters(min(value), 0, 2) FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `second arg to holt_winters must be greater than 0, got 0`},
{s: `SELECT holt_winters(min(value), false, 2) FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `expected integer argument as second arg in holt_winters`},
{s: `SELECT holt_winters(min(value), 10, 'string') FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `expected integer argument as third arg in holt_winters`},
{s: `SELECT field1 from myseries WHERE host =~ 'asd' LIMIT 1`, err: `found asd, expected regex at line 1, char 42`},
{s: `SELECT value > 2 FROM cpu`, err: `invalid operator > in SELECT clause at line 1, char 8; operator is intended for WHERE clause`},
{s: `SELECT value = 2 FROM cpu`, err: `invalid operator = in SELECT clause at line 1, char 8; operator is intended for WHERE clause`},
Expand Down

0 comments on commit 5181c6b

Please sign in to comment.