mirror of
https://github.com/chaisql/chai.git
synced 2025-10-17 05:00:46 +08:00

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.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package parser_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"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"
|
|
)
|
|
|
|
func TestParserMultiStatement(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
s string
|
|
expected []statement.Statement
|
|
}{
|
|
{"OnlyCommas", ";;;", nil},
|
|
{"TrailingComma", "SELECT * FROM foo;;;DELETE FROM foo;", []statement.Statement{
|
|
&statement.StreamStmt{
|
|
Stream: stream.New(stream.SeqScan("foo")).Pipe(stream.Project(expr.Wildcard{})),
|
|
ReadOnly: true,
|
|
},
|
|
&statement.StreamStmt{
|
|
Stream: stream.New(stream.SeqScan("foo")).Pipe(stream.TableDelete("foo")),
|
|
},
|
|
}},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
q, err := parser.ParseQuery(test.s)
|
|
require.NoError(t, err)
|
|
require.EqualValues(t, test.expected, q.Statements)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParserDivideByZero(t *testing.T) {
|
|
// See https://github.com/genjidb/genji/issues/268
|
|
require.NotPanics(t, func() {
|
|
_, _ = parser.ParseQuery("SELECT * FROM t LIMIT 0 % .5")
|
|
})
|
|
}
|