Files
chaisql/internal/sql/parser/explain_test.go
Asdine El Hrychy 9918cd6f55 Thread safe statements (#406)
Previously, expressions and params were evaluated
during the planning phase. This change builds the query
plan without evaluating params and expressions
which are then evaluated only during the execution phase.
2021-06-04 10:56:23 +04:00

40 lines
1.0 KiB
Go

package parser_test
import (
"testing"
"github.com/genjidb/genji/internal/expr"
"github.com/genjidb/genji/internal/query/statement"
"github.com/genjidb/genji/internal/sql/parser"
"github.com/genjidb/genji/internal/stream"
"github.com/stretchr/testify/require"
)
func TestParserExplain(t *testing.T) {
tests := []struct {
name string
s string
expected statement.Statement
errored bool
}{
{"Explain create table", "EXPLAIN SELECT * FROM test", &statement.ExplainStmt{Statement: &statement.StreamStmt{
ReadOnly: true,
Stream: stream.New(stream.SeqScan("test")).Pipe(stream.Project(expr.Wildcard{})),
}}, false},
{"Multiple Explains", "EXPLAIN EXPLAIN CREATE TABLE test", nil, true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
q, err := parser.ParseQuery(test.s)
if test.errored {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Len(t, q.Statements, 1)
require.EqualValues(t, test.expected, q.Statements[0])
})
}
}