Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix AS OF clause panic for certain expressions #2779

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading