Skip to content

Commit

Permalink
fix AS OF clause panic for certain expressions (#2779)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Dec 4, 2024
1 parent 29d5096 commit 6ffe4b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions enginetest/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -10751,6 +10751,10 @@ var ErrorQueries = []QueryErrorTest{
Query: "SELECT i FROM myhistorytable AS OF MAX(i)",
ExpectedErr: sql.ErrInvalidAsOfExpression,
},
{
Query: "SELECT i FROM myhistorytable AS OF (SELECT 1)",
ExpectedErrStr: "invalid AS OF expression type",
},
{
Query: "SELECT pk FROM one_pk WHERE pk > ?",
ExpectedErr: sql.ErrUnboundPreparedStatementVariable,
Expand Down
8 changes: 8 additions & 0 deletions sql/plan/subquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ func (s *Subquery) evalMultiple(ctx *sql.Context, row sql.Row) ([]interface{}, e
return nil, err
}

if s.b == nil {
return nil, fmt.Errorf("attempted to evaluate uninitialized subquery")
}

iter, err := s.b.Build(ctx, q, row)
if err != nil {
return nil, err
Expand Down Expand Up @@ -434,6 +438,10 @@ func (s *Subquery) HasResultRow(ctx *sql.Context, row sql.Row) (bool, error) {
return false, err
}

if s.b == nil {
return false, fmt.Errorf("attempted to evaluate uninitialized subquery")
}

iter, err := s.b.Build(ctx, q, row)
if err != nil {
return false, err
Expand Down
3 changes: 3 additions & 0 deletions sql/planbuilder/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,10 @@ func (b *Builder) buildAsOfExpr(inScope *scope, time ast.Expr) sql.Expression {
err := sql.ErrInvalidAsOfExpression.New(v)
b.handleErr(err)
}
case *ast.ConvertExpr:
case ast.InjectedExpr:
default:
b.handleErr(fmt.Errorf("invalid AS OF expression type"))
}
return b.buildScalar(b.newScope(), time)
}
Expand Down

0 comments on commit 6ffe4b8

Please sign in to comment.