Skip to content
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
12 changes: 6 additions & 6 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ func (e *Engine) analyzeQuery(ctx *sql.Context, query string, parsed sql.Node, b
return nil, err
}

analyzed, err = e.Analyzer.Analyze(ctx, parsed, nil)
if err != nil {
return nil, err
}

if len(bindings) > 0 {
analyzed, err = plan.ApplyBindings(analyzed, bindings)
parsed, err = plan.ApplyBindings(parsed, bindings)
if err != nil {
return nil, err
}
}

analyzed, err = e.Analyzer.Analyze(ctx, parsed, nil)
if err != nil {
return nil, err
}

return analyzed, nil
}

Expand Down
4 changes: 4 additions & 0 deletions enginetest/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ func TestQueryWithEngine(t *testing.T, harness Harness, e *sqle.Engine, tt queri
func TestQueryWithContext(t *testing.T, ctx *sql.Context, e *sqle.Engine, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]sql.Expression) {
ctx = ctx.WithQuery(q)
require := require.New(t)
if len(bindings) > 0 {
_, err := e.PrepareQuery(ctx, q)
require.NoError(err)
}
sch, iter, err := e.QueryWithBindings(ctx, q, bindings)
require.NoError(err, "Unexpected error for query %s", q)

Expand Down
39 changes: 37 additions & 2 deletions enginetest/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func RunEngineScripts(ctx *sql.Context, e *sqle.Engine, scripts []setup.SetupScr
return e, nil
}

func MustQuery(ctx *sql.Context, e *sqle.Engine, q string) []sql.Row {
func MustQuery(ctx *sql.Context, e *sqle.Engine, q string) (sql.Schema, []sql.Row) {
sch, iter, err := e.Query(ctx, q)
if err != nil {
panic(err)
Expand All @@ -186,7 +186,42 @@ func MustQuery(ctx *sql.Context, e *sqle.Engine, q string) []sql.Row {
if err != nil {
panic(err)
}
return rows
return sch, rows
}

func MustQueryWithBindings(ctx *sql.Context, e *sqle.Engine, q string, bindings map[string]sql.Expression) (sql.Schema, []sql.Row) {
ctx = ctx.WithQuery(q)
sch, iter, err := e.QueryWithBindings(ctx, q, bindings)
if err != nil {
panic(err)
}

rows, err := sql.RowIterToRows(ctx, sch, iter)
if err != nil {
panic(err)
}

return sch, rows
}

func MustQueryWithPreBindings(ctx *sql.Context, e *sqle.Engine, q string, bindings map[string]sql.Expression) (sql.Node, sql.Schema, []sql.Row) {
ctx = ctx.WithQuery(q)
pre, err := e.PrepareQuery(ctx, q)
if err != nil {
panic(err)
}

sch, iter, err := e.QueryWithBindings(ctx, q, bindings)
if err != nil {
panic(err)
}

rows, err := sql.RowIterToRows(ctx, sch, iter)
if err != nil {
panic(err)
}

return pre, sch, rows
}

func mustNewEngine(t *testing.T, h Harness) *sqle.Engine {
Expand Down
4 changes: 2 additions & 2 deletions enginetest/testgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func TestWriteCreateTableQueries(t *testing.T) {
for _, tt := range queries.CreateTableQueries {
ctx := NewContext(harness)
engine := mustNewEngine(t, harness)
_ = MustQuery(ctx, engine, tt.WriteQuery)
res := MustQuery(ctx, engine, tt.SelectQuery)
_, _ = MustQuery(ctx, engine, tt.WriteQuery)
_, res := MustQuery(ctx, engine, tt.SelectQuery)

w.WriteString(" {\n")
w.WriteString(fmt.Sprintf(" WriteQuery:`%s`,\n", tt.WriteQuery))
Expand Down
6 changes: 5 additions & 1 deletion sql/analyzer/resolve_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ func reresolveTables(ctx *sql.Context, a *Analyzer, node sql.Node, scope *Scope,
if n.Database != nil {
db = n.Database.Name()
}
to, err = resolveTable(ctx, plan.NewUnresolvedTable(n.Name(), db), a)
var asof sql.Expression
if n.AsOf != nil {
asof = expression.NewLiteral(n.AsOf, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this conversion step necessary? Why not just resolveTable(plan.NewUnresolvedTableAsOf(n.name, db, n.AsOf)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this conversion step necessary? Why not just resolveTable(plan.NewUnresolvedTableAsOf(n.name, db, n.AsOf)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor expected an sql.Expression argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could do more work to clean up asof handling/do a type inference if you want

}
to, err = resolveTable(ctx, plan.NewUnresolvedTableAsOf(n.Name(), db, asof), a)
if err != nil {
return nil, transform.SameTree, err
}
Expand Down