fix: error instead of panic for statement rewrite failure (#21792)

pull/21795/head
Sam Arnold 2021-07-06 11:05:21 -04:00 committed by GitHub
parent 639527cd57
commit 98361e2073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -11,8 +11,9 @@
- [#21666](https://github.com/influxdata/influxdb/pull/21666): fix: do not panic on cleaning up failed iterators
- [#21693](https://github.com/influxdata/influxdb/pull/21693): fix: don't access a field in a nil struct
- [#21558](https://github.com/influxdata/influxdb/pull/21558): fix: do not send non-UTF-8 characters to subscriptions
- [#21750](https://github.com/influxdata/influxdb/pull/21750): fix: rename arm rpms with yum-compatible names
- [#21777](https://github.com/influxdata/influxdb/pull/21777): fix: convert arm arch names for rpms during builds via docker
- [#21750](https://github.com/influxdata/influxdb/pull/21750): fix: rename arm rpms with yum-compatible names
- [#21777](https://github.com/influxdata/influxdb/pull/21777): fix: convert arm arch names for rpms during builds via docker
- [#21792](https://github.com/influxdata/influxdb/pull/21792): fix: error instead of panic for statement rewrite failure
v1.9.2 [unreleased]
- [#21631](https://github.com/influxdata/influxdb/pull/21631): fix: group by returns multiple results per group in some circumstances

View File

@ -103,7 +103,7 @@ func newCompiler(opt CompileOptions) *compiledStatement {
}
}
func Compile(stmt *influxql.SelectStatement, opt CompileOptions) (Statement, error) {
func Compile(stmt *influxql.SelectStatement, opt CompileOptions) (_ Statement, err error) {
c := newCompiler(opt)
c.stmt = stmt.Clone()
if err := c.preprocess(c.stmt); err != nil {
@ -115,6 +115,17 @@ func Compile(stmt *influxql.SelectStatement, opt CompileOptions) (Statement, err
c.stmt.TimeAlias = c.TimeFieldName
c.stmt.Condition = c.Condition
defer func() {
if e := recover(); e != nil && err == nil {
var ok bool
err, ok = e.(error)
if !ok {
err = fmt.Errorf("panic: %v", e)
}
err = fmt.Errorf("likely malformed statement, unable to rewrite: %w", err)
}
}()
// Convert DISTINCT into a call.
c.stmt.RewriteDistinct()

View File

@ -361,6 +361,7 @@ func TestCompile_Failures(t *testing.T) {
{s: `SELECT atan2(value, 3, 3) FROM cpu`, err: `invalid number of arguments for atan2, expected 2, got 3`},
{s: `SELECT sin(1.3) FROM cpu`, err: `field must contain at least one variable`},
{s: `SELECT nofunc(1.3) FROM cpu`, err: `undefined function nofunc()`},
{s: `SELECT * FROM cpu WHERE ( host =~ /foo/ ^ other AND env =~ /bar/ ) and time >= now()-15m`, err: `likely malformed statement, unable to rewrite: interface conversion: influxql.Expr is *influxql.BinaryExpr, not *influxql.RegexLiteral`},
} {
t.Run(tt.s, func(t *testing.T) {
stmt, err := influxql.ParseStatement(tt.s)