enginetest

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"
	"io"

	sqle "github.com/dolthub/go-mysql-server"
	"github.com/dolthub/go-mysql-server/memory"
	"github.com/dolthub/go-mysql-server/sql"
	"github.com/dolthub/go-mysql-server/sql/types"
)

func main() {
	// Create a test memory database and register it to the default engine.
	pro := createTestDatabase()
	e := sqle.NewDefault(pro)

	session := memory.NewSession(sql.NewBaseSession(), pro)
	ctx := sql.NewContext(context.Background(), sql.WithSession(session))
	ctx.SetCurrentDatabase("mydb")

	_, r, err := e.Query(ctx, `SELECT name, count(*) FROM mytable
	WHERE name = 'John Doe'
	GROUP BY name`)
	checkIfError(err)

	// Iterate results and print them.
	for {
		row, err := r.Next(ctx)
		if err == io.EOF {
			break
		}
		checkIfError(err)

		name := row[0]
		count := row[1]

		fmt.Println(name, count)
	}

}

func checkIfError(err error) {
	if err != nil {
		panic(err)
	}
}

func createTestDatabase() *memory.DbProvider {
	db := memory.NewDatabase("mydb")
	pro := memory.NewDBProvider(db)
	session := memory.NewSession(sql.NewBaseSession(), pro)
	ctx := sql.NewContext(context.Background(), sql.WithSession(session))

	table := memory.NewTable(db.BaseDatabase, "mytable", sql.NewPrimaryKeySchema(sql.Schema{
		{Name: "name", Type: types.Text, Source: "mytable"},
		{Name: "email", Type: types.Text, Source: "mytable"},
	}), db.GetForeignKeyCollection())
	db.AddTable("mytable", table)

	rows := []sql.Row{
		sql.NewRow("John Doe", "john@doe.com"),
		sql.NewRow("John Doe", "johnalt@doe.com"),
		sql.NewRow("Jane Doe", "jane@doe.com"),
		sql.NewRow("Evil Bob", "evilbob@gmail.com"),
	}

	for _, row := range rows {
		table.Insert(ctx, row)
	}

	return pro
}
Output:

John Doe 2

Index

Examples

Constants

This section is empty.

Variables

View Source
var DebugQueryPlan = sql.DescribeOptions{
	Analyze:   false,
	Estimates: false,
	Debug:     true,
}
View Source
var DefaultJoinOpTests = []joinOpTest{
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
}
View Source
var EngineOnlyJoinOpTests = []joinOpTest{
	{
		// contains filtered or unexported fields
	},
}
View Source
var JoinPlanningTests = []struct {
	name  string
	setup []string
	tests []JoinPlanTest
}{
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
}
View Source
var JoinStatTests = []struct {
	name  string
	setup []string
	tests []JoinPlanTest
}{
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
}
View Source
var SpatialIndexTests = []SpatialIndexPlanTest{
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
}

Functions

func AddColumn

func AddColumn(t *testing.T, ctx *sql.Context, table sql.AlterableTable, column *sql.Column)

AddColumn adds a column to the specified table

func AssertErr

func AssertErr(t *testing.T, e QueryEngine, harness Harness, query string, expectedErrKind *errors.Kind, errStrs ...string)

AssertErr asserts that the given query returns an error during its execution, optionally specifying a type of error.

func AssertErrPrepared

func AssertErrPrepared(t *testing.T, e QueryEngine, harness Harness, query string, expectedErrKind *errors.Kind, errStrs ...string)

AssertErrPrepared asserts that the given query returns an error during its execution, optionally specifying a type of error.

func AssertErrPreparedWithCtx

func AssertErrPreparedWithCtx(t *testing.T, e QueryEngine, harness Harness, ctx *sql.Context, query string, expectedErrKind *errors.Kind, errStrs ...string)

AssertErrPreparedWithCtx is the same as AssertErr, but uses the context given instead of creating one from a harness

func AssertErrWithBindings

func AssertErrWithBindings(t *testing.T, e QueryEngine, harness Harness, query string, bindings map[string]*querypb.BindVariable, expectedErrKind *errors.Kind, errStrs ...string)

AssertErrWithBindings asserts that the given query returns an error during its execution, optionally specifying a type of error.

func AssertErrWithCtx

func AssertErrWithCtx(t *testing.T, e QueryEngine, harness Harness, ctx *sql.Context, query string, expectedErrKind *errors.Kind, errStrs ...string)

AssertErrWithCtx is the same as AssertErr, but uses the context given instead of creating one from a harness

func AssertWarningAndTestQuery

func AssertWarningAndTestQuery(
	t *testing.T,
	e QueryEngine,
	ctx *sql.Context,
	harness Harness,
	query string,
	expected []sql.Row,
	expectedCols []*sql.Column,
	expectedCode int,
	expectedWarningsCount int,
	expectedWarningMessageSubstring string,
	skipResultsCheck bool,
)

AssertWarningAndTestQuery tests the query and asserts an expected warning code. If |ctx| is provided, it will be used. Otherwise the harness will be used to create a fresh context.

func CheckIndexedAccess

func CheckIndexedAccess(n sql.Node) bool

func CreateNewConnectionForServerEngine

func CreateNewConnectionForServerEngine(ctx *sql.Context, e QueryEngine) error

CreateNewConnectionForServerEngine creates a new connection in the server engine. If there was an existing one, it gets closed before the new gets created. This function should be called when needing to use new session for the server.

func CreateVersionedTestData

func CreateVersionedTestData(t *testing.T, harness VersionedDBHarness) []sql.Database

CreateVersionedTestData uses the provided harness to create test tables and data for many of the other tests.

func DeleteRows

func DeleteRows(t *testing.T, ctx *sql.Context, table sql.DeletableTable, rows ...sql.Row)

func DrainIterator

func DrainIterator(ctx *sql.Context, iter sql.RowIter) error

func DrainIteratorIgnoreErrors

func DrainIteratorIgnoreErrors(ctx *sql.Context, iter sql.RowIter)

This shouldn't be necessary -- the fact that an iterator can return an error but not clean up after itself in all cases is a bug.

func ExecuteNode

func ExecuteNode(ctx *sql.Context, engine QueryEngine, node sql.Node) error

ExecuteNode builds an iterator and then drains it. This is useful for populating actual row counts for `DESCRIBE ANALYZE`.

func ExtractQueryNode

func ExtractQueryNode(node sql.Node) sql.Node

func GetFilterIndex

func GetFilterIndex(n sql.Node) sql.IndexLookup

func InsertRows

func InsertRows(t *testing.T, ctx *sql.Context, table sql.InsertableTable, rows ...sql.Row)

func IsServerEngine

func IsServerEngine(e QueryEngine) bool

func MustQuery

func MustQuery(ctx *sql.Context, e QueryEngine, q string) (sql.Schema, []sql.Row)

func NewBaseSession

func NewBaseSession() *sql.BaseSession

NewBaseSession returns a new BaseSession compatible with these tests. Most tests will work with any session implementation, but for full compatibility use a session based on this one.

func NewColumnDefaultValue

func NewColumnDefaultValue(expr sql.Expression, outType sql.Type, representsLiteral, isParenthesized, mayReturnNil bool) *sql.ColumnDefaultValue

func NewContext

func NewContext(harness Harness) *sql.Context

func NewContextWithClient

func NewContextWithClient(harness ClientHarness, client sql.Client) *sql.Context

func NewContextWithEngine

func NewContextWithEngine(harness Harness, engine QueryEngine) *sql.Context

TODO: remove

func NewEngine

func NewEngine(t *testing.T, harness Harness, dbProvider sql.DatabaseProvider, setupData []setup.SetupScript, statsProvider sql.StatsProvider) (*sqle.Engine, error)

NewEngine creates an engine and sets it up for testing using harness, provider, and setup data given.

func NewEngineWithProvider

func NewEngineWithProvider(_ *testing.T, harness Harness, provider sql.DatabaseProvider) *sqle.Engine

NewEngineWithProvider returns a new engine with the specified provider

func NewSession

func NewSession(harness Harness) *sql.Context

func RunQueryTests

func RunQueryTests(t *testing.T, harness Harness, queries []queries.QueryTest)

RunQueryTests runs the query tests given after setting up the engine. Useful for testing out a smaller subset of queries during debugging.

func RunQueryWithContext

func RunQueryWithContext(t *testing.T, e QueryEngine, harness Harness, ctx *sql.Context, query string)

RunQueryWithContext runs the query given and asserts that it doesn't result in an error. If |ctx| is nil, this function creates new context using `NewContext()` method on given harness.

func RunSetupScripts

func RunSetupScripts(ctx *sql.Context, e *sqle.Engine, scripts []setup.SetupScript, createIndexes bool) (*sqle.Engine, error)

RunSetupScripts runs the given setup scripts on the given engine, returning any error

func RunWriteQueryTest

func RunWriteQueryTest(t *testing.T, harness Harness, tt queries.WriteQueryTest)

RunWriteQueryTest runs the specified |tt| WriteQueryTest using the specified harness.

func RunWriteQueryTestWithEngine

func RunWriteQueryTestWithEngine(t *testing.T, harness Harness, e QueryEngine, tt queries.WriteQueryTest)

RunWriteQueryTestWithEngine runs the specified |tt| WriteQueryTest, using the specified harness and engine. Callers are still responsible for closing the engine.

func TestAddColumn

func TestAddColumn(t *testing.T, harness Harness)

func TestAddDropPks

func TestAddDropPks(t *testing.T, harness Harness)

func TestAlterTable

func TestAlterTable(t *testing.T, harness Harness)

func TestAmbiguousColumnResolution

func TestAmbiguousColumnResolution(t *testing.T, harness Harness)

func TestAnsiQuotesSqlMode

func TestAnsiQuotesSqlMode(t *testing.T, harness Harness)

func TestAnsiQuotesSqlModePrepared

func TestAnsiQuotesSqlModePrepared(t *testing.T, harness Harness)

func TestBlobs

func TestBlobs(t *testing.T, h Harness)

func TestBrokenInsertScripts

func TestBrokenInsertScripts(t *testing.T, harness Harness)

func TestBrokenJSONTableScripts

func TestBrokenJSONTableScripts(t *testing.T, harness Harness)

func TestBrokenQueries

func TestBrokenQueries(t *testing.T, harness Harness)

func TestCharsetCollationEngine

func TestCharsetCollationEngine(t *testing.T, harness Harness)

func TestCharsetCollationWire

func TestCharsetCollationWire(t *testing.T, h Harness, sessionBuilder server.SessionBuilder)

func TestChecksOnInsert

func TestChecksOnInsert(t *testing.T, harness Harness)

func TestChecksOnUpdate

func TestChecksOnUpdate(t *testing.T, harness Harness)

func TestClearWarnings

func TestClearWarnings(t *testing.T, harness Harness)

func TestColumnAliases

func TestColumnAliases(t *testing.T, harness Harness)

TestColumnAliases exercises the logic for naming and referring to column aliases, and unlike other tests in this file checks that the name of the columns in the result schema is correct.

func TestColumnDefaults

func TestColumnDefaults(t *testing.T, harness Harness)

func TestComplexIndexQueries

func TestComplexIndexQueries(t *testing.T, harness Harness)

func TestComplexIndexQueriesPrepared

func TestComplexIndexQueriesPrepared(t *testing.T, harness Harness)

func TestConcurrentProcessList

func TestConcurrentProcessList(t *testing.T, harness Harness)

func TestConcurrentTransactions

func TestConcurrentTransactions(t *testing.T, harness Harness)

TestConcurrentTransactions tests that two concurrent processes/transactions can successfully execute without early cancellation.

func TestConvert

func TestConvert(t *testing.T, harness Harness)

func TestConvertPrepared

func TestConvertPrepared(t *testing.T, harness Harness)

func TestCreateCheckConstraints

func TestCreateCheckConstraints(t *testing.T, harness Harness)

func TestCreateCheckConstraintsScriptsPrepared

func TestCreateCheckConstraintsScriptsPrepared(t *testing.T, harness Harness)

func TestCreateDatabase

func TestCreateDatabase(t *testing.T, harness Harness)

func TestCreateForeignKeys

func TestCreateForeignKeys(t *testing.T, harness Harness)

func TestCreateTable

func TestCreateTable(t *testing.T, harness Harness)

func TestCurrentTimestamp

func TestCurrentTimestamp(t *testing.T, harness Harness)

func TestDatabaseCollationWire

func TestDatabaseCollationWire(t *testing.T, h Harness, sessionBuilder server.SessionBuilder)

func TestDateParse

func TestDateParse(t *testing.T, harness Harness)

func TestDelete

func TestDelete(t *testing.T, harness Harness)

func TestDeleteErrors

func TestDeleteErrors(t *testing.T, harness Harness)

func TestDeleteQueriesPrepared

func TestDeleteQueriesPrepared(t *testing.T, harness Harness)

func TestDerivedTableOuterScopeVisibility

func TestDerivedTableOuterScopeVisibility(t *testing.T, harness Harness)

func TestDisallowedCheckConstraints

func TestDisallowedCheckConstraints(t *testing.T, harness Harness)

func TestDropCheckConstraints

func TestDropCheckConstraints(t *testing.T, harness Harness)

func TestDropColumn

func TestDropColumn(t *testing.T, harness Harness)

func TestDropColumnKeylessTables

func TestDropColumnKeylessTables(t *testing.T, harness Harness)

func TestDropDatabase

func TestDropDatabase(t *testing.T, harness Harness)

func TestDropForeignKeys

func TestDropForeignKeys(t *testing.T, harness Harness)

func TestDropTable

func TestDropTable(t *testing.T, harness Harness)

func TestEvents

func TestEvents(t *testing.T, h Harness)

func TestForeignKeys

func TestForeignKeys(t *testing.T, harness Harness)

func TestFulltextIndexes

func TestFulltextIndexes(t *testing.T, harness Harness)

func TestGeneratedColumnPlans

func TestGeneratedColumnPlans(t *testing.T, harness Harness)

func TestGeneratedColumns

func TestGeneratedColumns(t *testing.T, harness Harness)

func TestIgnoreIntoWithDuplicateUniqueKeyKeyless

func TestIgnoreIntoWithDuplicateUniqueKeyKeyless(t *testing.T, harness Harness)

func TestIgnoreIntoWithDuplicateUniqueKeyKeylessPrepared

func TestIgnoreIntoWithDuplicateUniqueKeyKeylessPrepared(t *testing.T, harness Harness)

func TestImdbPlans

func TestImdbPlans(t *testing.T, harness Harness)

func TestIndexPrefix

func TestIndexPrefix(t *testing.T, h Harness)

func TestIndexQueryPlans

func TestIndexQueryPlans(t *testing.T, harness Harness)

func TestIndexes

func TestIndexes(t *testing.T, h Harness)

func TestInfoSchema

func TestInfoSchema(t *testing.T, h Harness)

TestInfoSchema runs tests of the information_schema database

func TestInfoSchemaPrepared

func TestInfoSchemaPrepared(t *testing.T, harness Harness)

TestInfoSchemaPrepared runs tests of the information_schema database

func TestInnerNestedInNaturalJoins

func TestInnerNestedInNaturalJoins(t *testing.T, harness Harness)

func TestInsertDuplicateKeyKeyless

func TestInsertDuplicateKeyKeyless(t *testing.T, harness Harness)

func TestInsertDuplicateKeyKeylessPrepared

func TestInsertDuplicateKeyKeylessPrepared(t *testing.T, harness Harness)

func TestInsertErrorScriptsPrepared

func TestInsertErrorScriptsPrepared(t *testing.T, harness Harness)

func TestInsertIgnoreInto

func TestInsertIgnoreInto(t *testing.T, harness Harness)

func TestInsertIgnoreScriptsPrepared

func TestInsertIgnoreScriptsPrepared(t *testing.T, harness Harness)

func TestInsertInto

func TestInsertInto(t *testing.T, harness Harness)

func TestInsertIntoErrors

func TestInsertIntoErrors(t *testing.T, harness Harness)

func TestInsertQueriesPrepared

func TestInsertQueriesPrepared(t *testing.T, harness Harness)

func TestInsertScriptsPrepared

func TestInsertScriptsPrepared(t *testing.T, harness Harness)

func TestIntegrationPlans

func TestIntegrationPlans(t *testing.T, harness Harness)

func TestJSONTableQueries

func TestJSONTableQueries(t *testing.T, harness Harness)

func TestJSONTableQueriesPrepared

func TestJSONTableQueriesPrepared(t *testing.T, harness Harness)

func TestJSONTableScripts

func TestJSONTableScripts(t *testing.T, harness Harness)

func TestJSONTableScriptsPrepared

func TestJSONTableScriptsPrepared(t *testing.T, harness Harness)

func TestJoinOps

func TestJoinOps(t *testing.T, harness Harness, tests []joinOpTest)

func TestJoinPlanning

func TestJoinPlanning(t *testing.T, harness Harness)

func TestJoinQueries

func TestJoinQueries(t *testing.T, harness Harness)

TestJoinQueries tests join queries against a provided harness.

func TestJoinQueriesPrepared

func TestJoinQueriesPrepared(t *testing.T, harness Harness)

TestJoinQueriesPrepared tests join queries as prepared statements against a provided harness.

func TestJoinStats

func TestJoinStats(t *testing.T, harness Harness)

func TestJsonScripts

func TestJsonScripts(t *testing.T, harness Harness, skippedTests []string)

func TestJsonScriptsPrepared

func TestJsonScriptsPrepared(t *testing.T, harness Harness, skippedTests []string)

func TestLateralJoinQueries

func TestLateralJoinQueries(t *testing.T, harness Harness)

func TestLoadData

func TestLoadData(t *testing.T, harness Harness)

func TestLoadDataErrors

func TestLoadDataErrors(t *testing.T, harness Harness)

func TestLoadDataFailing

func TestLoadDataFailing(t *testing.T, harness Harness)

func TestLoadDataPrepared

func TestLoadDataPrepared(t *testing.T, harness Harness)

func TestModifyColumn

func TestModifyColumn(t *testing.T, harness Harness)

func TestMySqlDb

func TestMySqlDb(t *testing.T, harness Harness)

func TestMySqlDbPrepared

func TestMySqlDbPrepared(t *testing.T, harness Harness)

func TestNamedWindows

func TestNamedWindows(t *testing.T, harness Harness)

func TestNaturalJoin

func TestNaturalJoin(t *testing.T, harness Harness)

func TestNaturalJoinDisjoint

func TestNaturalJoinDisjoint(t *testing.T, harness Harness)

func TestNaturalJoinEqual

func TestNaturalJoinEqual(t *testing.T, harness Harness)

func TestNoDatabaseSelected

func TestNoDatabaseSelected(t *testing.T, harness Harness)

func TestNullRanges

func TestNullRanges(t *testing.T, harness Harness)

func TestOnUpdateExprScripts

func TestOnUpdateExprScripts(t *testing.T, harness Harness)

func TestOrderByGroupBy

func TestOrderByGroupBy(t *testing.T, harness Harness)

func TestParallelismQueries

func TestParallelismQueries(t *testing.T, harness Harness)

func TestPersist

func TestPersist(t *testing.T, harness Harness, newPersistableSess func(ctx *sql.Context) sql.PersistableSession)

func TestPkOrdinalsDDL

func TestPkOrdinalsDDL(t *testing.T, harness Harness)

func TestPkOrdinalsDML

func TestPkOrdinalsDML(t *testing.T, harness Harness)

func TestPrepared

func TestPrepared(t *testing.T, harness Harness)

func TestPreparedInsert

func TestPreparedInsert(t *testing.T, harness Harness)

func TestPreparedQuery

func TestPreparedQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column)

TestPreparedQuery runs a prepared query on the engine given and asserts that results are as expected.

func TestPreparedQueryWithContext

func TestPreparedQueryWithContext(t *testing.T, ctx *sql.Context, e QueryEngine, h Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindVars map[string]*querypb.BindVariable, checkIndexedAccess bool)

func TestPreparedQueryWithEngine

func TestPreparedQueryWithEngine(t *testing.T, harness Harness, e QueryEngine, tt queries.QueryTest)

func TestPreparedStatements

func TestPreparedStatements(t *testing.T, harness Harness)

func TestPrivilegePersistence

func TestPrivilegePersistence(t *testing.T, h Harness)

func TestQueries

func TestQueries(t *testing.T, harness Harness)

TestQueries tests a variety of queries against databases and tables provided by the given harness.

func TestQueriesPrepared

func TestQueriesPrepared(t *testing.T, harness Harness)

func TestQuery

func TestQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]*querypb.BindVariable)

TestQuery runs a query on the engine given and asserts that results are as expected. TODO: this should take en engine

func TestQuery2

func TestQuery2(t *testing.T, harness Harness, e QueryEngine, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]*querypb.BindVariable)

TestQuery runs a query on the engine given and asserts that results are as expected.

func TestQueryErrors

func TestQueryErrors(t *testing.T, harness Harness)

func TestQueryPlan

func TestQueryPlan(t *testing.T, harness Harness, e QueryEngine, query, expectedPlan string, options sql.DescribeOptions)

TestQueryPlan analyzes the query given and asserts that its printed plan matches the expected one.

func TestQueryPlanWithEngine

func TestQueryPlanWithEngine(t *testing.T, harness Harness, e QueryEngine, tt queries.QueryPlanTest, verbose bool)

func TestQueryPlanWithName

func TestQueryPlanWithName(t *testing.T, name string, harness Harness, e QueryEngine, query, expectedPlan string, options sql.DescribeOptions)

func TestQueryPlans

func TestQueryPlans(t *testing.T, harness Harness, planTests []queries.QueryPlanTest)

TestQueryPlans tests generating the correct query plans for various queries using databases and tables provided by the given harness.

func TestQueryWithContext

func TestQueryWithContext(t *testing.T, ctx *sql.Context, e QueryEngine, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]*querypb.BindVariable)

func TestQueryWithEngine

func TestQueryWithEngine(t *testing.T, harness Harness, e QueryEngine, tt queries.QueryTest)

TODO: collapse into TestQuery

func TestQueryWithIndexCheck

func TestQueryWithIndexCheck(t *testing.T, ctx *sql.Context, e QueryEngine, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]*querypb.BindVariable)

func TestReadOnly

func TestReadOnly(t *testing.T, harness Harness, testStoredProcedures bool)

func TestReadOnlyDatabases

func TestReadOnlyDatabases(t *testing.T, harness ReadOnlyDatabaseHarness)

func TestReadOnlyVersionedQueries

func TestReadOnlyVersionedQueries(t *testing.T, harness Harness)

func TestRecursiveViewDefinition

func TestRecursiveViewDefinition(t *testing.T, harness Harness)

func TestRenameColumn

func TestRenameColumn(t *testing.T, harness Harness)

func TestRenameTable

func TestRenameTable(t *testing.T, harness Harness)

func TestReplaceInto

func TestReplaceInto(t *testing.T, harness Harness)

func TestReplaceIntoErrors

func TestReplaceIntoErrors(t *testing.T, harness Harness)

func TestReplaceQueriesPrepared

func TestReplaceQueriesPrepared(t *testing.T, harness Harness)

func TestRollbackTriggers

func TestRollbackTriggers(t *testing.T, harness Harness)

func TestRowLimit

func TestRowLimit(t *testing.T, harness Harness)

func TestSQLLogicTests

func TestSQLLogicTests(t *testing.T, harness Harness)

func TestScript

func TestScript(t *testing.T, harness Harness, script queries.ScriptTest)

TestScript runs the test script given, making any assertions given

func TestScriptPrepared

func TestScriptPrepared(t *testing.T, harness Harness, script queries.ScriptTest) bool

TestScriptPrepared substitutes literals for bindvars, runs the test script given, and makes any assertions given

func TestScriptWithEngine

func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script queries.ScriptTest)

TestScriptWithEngine runs the test script given with the engine provided.

func TestScriptWithEnginePrepared

func TestScriptWithEnginePrepared(t *testing.T, e QueryEngine, harness Harness, script queries.ScriptTest)

TestScriptWithEnginePrepared runs the test script with bindvars substituted for literals using the engine provided.

func TestScripts

func TestScripts(t *testing.T, harness Harness)

func TestScriptsPrepared

func TestScriptsPrepared(t *testing.T, harness Harness)

func TestSelectIntoFile

func TestSelectIntoFile(t *testing.T, harness Harness)

func TestSessionSelectLimit

func TestSessionSelectLimit(t *testing.T, harness Harness)

func TestShowTableStatus

func TestShowTableStatus(t *testing.T, harness Harness)

Runs tests on SHOW TABLE STATUS queries.

func TestShowTableStatusPrepared

func TestShowTableStatusPrepared(t *testing.T, harness Harness)

func TestShowTriggers

func TestShowTriggers(t *testing.T, harness Harness)

func TestSpatialDelete

func TestSpatialDelete(t *testing.T, harness Harness)

func TestSpatialIndexPlans

func TestSpatialIndexPlans(t *testing.T, harness Harness)

func TestSpatialIndexScripts

func TestSpatialIndexScripts(t *testing.T, harness Harness)

func TestSpatialIndexScriptsPrepared

func TestSpatialIndexScriptsPrepared(t *testing.T, harness Harness)

func TestSpatialInsertInto

func TestSpatialInsertInto(t *testing.T, harness Harness)

func TestSpatialQueries

func TestSpatialQueries(t *testing.T, harness Harness)

TestSpatialQueries tests a variety of geometry queries against databases and tables provided by the given harness.

func TestSpatialQueriesPrepared

func TestSpatialQueriesPrepared(t *testing.T, harness Harness)

TestSpatialQueriesPrepared tests a variety of geometry queries against databases and tables provided by the given harness.

func TestSpatialScripts

func TestSpatialScripts(t *testing.T, harness Harness)

func TestSpatialScriptsPrepared

func TestSpatialScriptsPrepared(t *testing.T, harness Harness)

func TestSpatialUpdate

func TestSpatialUpdate(t *testing.T, harness Harness)

func TestStatisticIndexFilters

func TestStatisticIndexFilters(t *testing.T, harness Harness)

TestStatisticIndexFilters tests index histogram costing

func TestStatistics

func TestStatistics(t *testing.T, harness Harness)

TestStatistics tests the statistics from ANALYZE TABLE

func TestStatisticsPrepared

func TestStatisticsPrepared(t *testing.T, harness Harness)

TestStatisticsPrepared tests the statistics from ANALYZE TABLE

func TestStoredProcedures

func TestStoredProcedures(t *testing.T, harness Harness)

func TestSysbenchPlans

func TestSysbenchPlans(t *testing.T, harness Harness)

func TestTpccPlans

func TestTpccPlans(t *testing.T, harness Harness)

func TestTpcdsPlans

func TestTpcdsPlans(t *testing.T, harness Harness)

func TestTpchPlans

func TestTpchPlans(t *testing.T, harness Harness)

func TestTracing

func TestTracing(t *testing.T, harness Harness)

func TestTransactionScript

func TestTransactionScript(t *testing.T, harness Harness, script queries.TransactionTest) bool

TestTransactionScript runs the test script given, making any assertions given

func TestTransactionScriptWithEngine

func TestTransactionScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script queries.TransactionTest)

TestTransactionScriptWithEngine runs the transaction test script given with the engine provided.

func TestTransactionScripts

func TestTransactionScripts(t *testing.T, harness Harness)

func TestTriggerErrors

func TestTriggerErrors(t *testing.T, harness Harness)

func TestTriggers

func TestTriggers(t *testing.T, harness Harness)

func TestTruncate

func TestTruncate(t *testing.T, harness Harness)

func TestTypesOverWire

func TestTypesOverWire(t *testing.T, harness ClientHarness, sessionBuilder server.SessionBuilder)

func TestUpdate

func TestUpdate(t *testing.T, harness Harness)

func TestUpdateErrors

func TestUpdateErrors(t *testing.T, harness Harness)

func TestUpdateIgnore

func TestUpdateIgnore(t *testing.T, harness Harness)

func TestUpdateQueriesPrepared

func TestUpdateQueriesPrepared(t *testing.T, harness Harness)

func TestUse

func TestUse(t *testing.T, harness Harness)

func TestUserAuthentication

func TestUserAuthentication(t *testing.T, h Harness)

func TestUserPrivileges

func TestUserPrivileges(t *testing.T, harness ClientHarness)

func TestValidateSession

func TestValidateSession(t *testing.T, harness Harness, newSessFunc func(ctx *sql.Context) sql.PersistableSession, count *int)

func TestVariableErrors

func TestVariableErrors(t *testing.T, harness Harness)

func TestVariables

func TestVariables(t *testing.T, harness Harness)

func TestVersionedQueries

func TestVersionedQueries(t *testing.T, harness VersionedDBHarness)

TestVersionedQueries tests a variety of versioned queries

func TestVersionedQueriesPrepared

func TestVersionedQueriesPrepared(t *testing.T, harness VersionedDBHarness)

TestVersionedQueriesPrepared tests a variety of queries against databases and tables provided by the given harness.

func TestVersionedViews

func TestVersionedViews(t *testing.T, harness VersionedDBHarness)

func TestVersionedViewsPrepared

func TestVersionedViewsPrepared(t *testing.T, harness VersionedDBHarness)

func TestViews

func TestViews(t *testing.T, harness Harness)

func TestViewsPrepared

func TestViewsPrepared(t *testing.T, harness Harness)

func TestWarnings

func TestWarnings(t *testing.T, harness Harness)

func TestWindowFunctions

func TestWindowFunctions(t *testing.T, harness Harness)

func TestWindowRangeFrames

func TestWindowRangeFrames(t *testing.T, harness Harness)

func TestWindowRowFrames

func TestWindowRowFrames(t *testing.T, harness Harness)

func WidenRow

func WidenRow(sch sql.Schema, row sql.Row) sql.Row

WidenRow returns a row with all values widened to their widest type

func WidenRows

func WidenRows(sch sql.Schema, rows []sql.Row) []sql.Row

WidenRows returns a slice of rows with all values widened to their widest type. For a variety of reasons, the widths of various primitive types can vary when passed through different SQL queries (and different database implementations). We may eventually decide that this undefined behavior is a problem, but for now it's mostly just an issue when comparing results in tests. To get around this, we widen every type to its widest value in actual and expected results.

Types

type ClientHarness

type ClientHarness interface {
	Harness

	// NewContextWithClient returns a context that will return the given client when requested from the session.
	NewContextWithClient(client sql.Client) *sql.Context
}

ClientHarness allows for integrators to test user privileges, as mock clients are used to test functionality.

type CustomValueValidator

type CustomValueValidator interface {
	Validate(interface{}) (bool, error)
}

CustomValueValidator is an interface for custom validation of values in the result set

type ForeignKeyHarness

type ForeignKeyHarness interface {
	Harness

	// SupportsForeignKeys returns whether this harness should accept CREATE FOREIGN KEY statements as part of test
	// setup.
	SupportsForeignKeys() bool
}

ForeignKeyHarness is an extension to Harness that lets an integrator test their implementation with foreign keys. Integrator tables must implement sql.ForeignKeyTable.

type Harness

type Harness interface {
	// Parallelism returns how many parallel go routines to use when constructing an engine for test.
	Parallelism() int
	// NewContext allows a harness to specify any sessions or context variables necessary for the proper functioning of
	// their engine implementation. Every harnessed engine test uses the context created by this method, with some
	// additional information (e.g. current DB) set uniformly. To replicate the behavior of tests during setup,
	// harnesses should generally dispatch to enginetest.NewContext(harness), rather than calling this method themselves.
	NewContext() *sql.Context
	// Setup supplies a test suite's setup scripts, which must be stored and used to create a new Engine on demand via
	// calls to the NewEngine method.
	Setup(...[]setup.SetupScript)
	// NewEngine creates a new sqle.Engine. The state of the engine returned must match what was previous specified
	// by Setup, with no other data. See enginetest.NewEngine for help creating an engine suitable in tests.
	NewEngine(*testing.T) (QueryEngine, error)
}

Harness provides a way for database integrators to validate their implementation against the standard set of queries used to develop and test the engine itself. See memory_engine_test.go for an example. The typical harness lifecycle during test setup looks like this: 1) Harness is instantiated, which should create a sql.MutableDatabaseProvider to use for the rest of setup 2) Harness.NewDatabase or Harness.NewTable is called to create the database and tables that will be used for the test 3) For some tests, harness.Setup() is called instead of Harness.NewDatabase and Harness.NewTable 4) Harness.NewEngine() is called to create an engine with the setup data provided prior. It can be called multiple times during a single test run, and must return a "fresh" engine instance each time, i.e. an instance that contains exactly the test data provided via other setup methods.

type IndexDriverHarness

type IndexDriverHarness interface {
	Harness

	// InitializeIndexDriver initializes the index driver for this test run with the databases given
	InitializeIndexDriver(dbs []sql.Database)
}

IndexDriverHarness is an extension to Harness that lets an integrator test their implementation alongside an index driver they provide.

type IndexDriverInitializer

type IndexDriverInitializer func([]sql.Database) sql.IndexDriver

type IndexHarness

type IndexHarness interface {
	Harness

	// SupportsNativeIndexCreation returns whether this harness should accept CREATE INDEX statements as part of test
	// setup.
	SupportsNativeIndexCreation() bool
}

IndexHarness is an extension to Harness that lets an integrator test their implementation with native (table-supplied) indexes. Integrator tables must implement sql.IndexAlterableTable.

type JoinOpTests

type JoinOpTests struct {
	Query    string
	Expected []sql.Row
	Skip     bool
}

type JoinPlanTest

type JoinPlanTest struct {
	// contains filtered or unexported fields
}

type KeylessTableHarness

type KeylessTableHarness interface {
	Harness

	// SupportsKeylessTables indicates integrator support for keyless tables.
	SupportsKeylessTables() bool
}

KeylessTableHarness is an extension to Harness that lets an integrator test their implementation with keyless tables.

type MemoryHarness

type MemoryHarness struct {
	// contains filtered or unexported fields
}

func NewDefaultMemoryHarness

func NewDefaultMemoryHarness() *MemoryHarness

func NewMemoryHarness

func NewMemoryHarness(name string, parallelism int, numTablePartitions int, useNativeIndexes bool, driverInitializer IndexDriverInitializer) *MemoryHarness

func NewReadOnlyMemoryHarness

func NewReadOnlyMemoryHarness() *MemoryHarness

func (*MemoryHarness) ExternalStoredProcedure

func (m *MemoryHarness) ExternalStoredProcedure(_ *sql.Context, name string, numOfParams int) (*sql.ExternalStoredProcedureDetails, error)

ExternalStoredProcedure implements the sql.ExternalStoredProcedureProvider interface

func (*MemoryHarness) ExternalStoredProcedures

func (m *MemoryHarness) ExternalStoredProcedures(_ *sql.Context, name string) ([]sql.ExternalStoredProcedureDetails, error)

ExternalStoredProcedures implements the sql.ExternalStoredProcedureProvider interface

func (*MemoryHarness) IndexDriver

func (m *MemoryHarness) IndexDriver(dbs []sql.Database) sql.IndexDriver

func (*MemoryHarness) InitializeIndexDriver

func (m *MemoryHarness) InitializeIndexDriver(dbs []sql.Database)

func (*MemoryHarness) IsUsingServer

func (m *MemoryHarness) IsUsingServer() bool

func (*MemoryHarness) NewContext

func (m *MemoryHarness) NewContext() *sql.Context

func (*MemoryHarness) NewContextWithClient

func (m *MemoryHarness) NewContextWithClient(client sql.Client) *sql.Context

func (*MemoryHarness) NewDatabaseProvider

func (m *MemoryHarness) NewDatabaseProvider() sql.MutableDatabaseProvider

func (*MemoryHarness) NewDatabases

func (m *MemoryHarness) NewDatabases(names ...string) []sql.Database

func (*MemoryHarness) NewEngine

func (m *MemoryHarness) NewEngine(t *testing.T) (QueryEngine, error)

func (*MemoryHarness) NewReadOnlyEngine

func (m *MemoryHarness) NewReadOnlyEngine(provider sql.DatabaseProvider) (QueryEngine, error)

func (*MemoryHarness) NewSession

func (m *MemoryHarness) NewSession() *sql.Context

func (*MemoryHarness) NewTableAsOf

func (m *MemoryHarness) NewTableAsOf(db sql.VersionedDatabase, name string, schema sql.PrimaryKeySchema, asOf interface{}) sql.Table

func (*MemoryHarness) Parallelism

func (m *MemoryHarness) Parallelism() int

func (*MemoryHarness) Provider

func (m *MemoryHarness) Provider() *memory.DbProvider

func (*MemoryHarness) QueriesToSkip

func (m *MemoryHarness) QueriesToSkip(queries ...string)

func (*MemoryHarness) SessionBuilder

func (m *MemoryHarness) SessionBuilder() server.SessionBuilder

func (*MemoryHarness) Setup

func (m *MemoryHarness) Setup(setupData ...[]setup.SetupScript)

func (*MemoryHarness) SkipQueryTest

func (m *MemoryHarness) SkipQueryTest(query string) bool

func (*MemoryHarness) SnapshotTable

func (m *MemoryHarness) SnapshotTable(db sql.VersionedDatabase, name string, asOf interface{}) error

func (*MemoryHarness) SupportsForeignKeys

func (m *MemoryHarness) SupportsForeignKeys() bool

func (*MemoryHarness) SupportsKeylessTables

func (m *MemoryHarness) SupportsKeylessTables() bool

func (*MemoryHarness) SupportsNativeIndexCreation

func (m *MemoryHarness) SupportsNativeIndexCreation() bool

func (*MemoryHarness) UseServer

func (m *MemoryHarness) UseServer()

func (*MemoryHarness) ValidateEngine

func (m *MemoryHarness) ValidateEngine(ctx *sql.Context, e *sqle.Engine) error

func (*MemoryHarness) WithProvider

func (m *MemoryHarness) WithProvider(provider sql.DatabaseProvider) *MemoryHarness

type MySQLPersister

type MySQLPersister struct {
	Data []byte
}

MySQLPersister is an example struct which handles the persistence of the data in the "mysql" database.

func (*MySQLPersister) Persist

func (m *MySQLPersister) Persist(ctx *sql.Context, data []byte) error

Persist implements the interface mysql_db.MySQLDbPersistence. This function is simple, in that it simply stores the given data inside itself. A real application would persist to the file system.

type QueryEngine

type QueryEngine interface {
	PrepareQuery(*sql.Context, string) (sql.Node, error)
	AnalyzeQuery(*sql.Context, string) (sql.Node, error)
	Query(ctx *sql.Context, query string) (sql.Schema, sql.RowIter, error)
	// TODO: get rid of this, should not be exposed to engine tests
	EngineAnalyzer() *analyzer.Analyzer
	// TODO: get rid of this, should not be exposed to engine tests
	EnginePreparedDataCache() *sqle.PreparedDataCache
	QueryWithBindings(ctx *sql.Context, query string, parsed sqlparser.Statement, bindings map[string]*query.BindVariable) (sql.Schema, sql.RowIter, error)
	CloseSession(connID uint32)
	Close() error
}

type ReadOnlyDatabaseHarness

type ReadOnlyDatabaseHarness interface {
	Harness

	// NewReadOnlyEngine returns a new engine with read-only versions of the databases supplied by the provider.
	// TODO: should this and NewEngine actually just be NewProvider?
	NewReadOnlyEngine(provider sql.DatabaseProvider) (QueryEngine, error)
}

type ServerHarness

type ServerHarness interface {
	Harness

	// SessionBuilder returns a function that creates a new session for connections to a server
	SessionBuilder() server.SessionBuilder
}

type ServerQueryEngine

type ServerQueryEngine struct {
	// contains filtered or unexported fields
}

func NewServerQueryEngine

func NewServerQueryEngine(t *testing.T, engine *sqle.Engine, builder server.SessionBuilder) (*ServerQueryEngine, error)

func (*ServerQueryEngine) AnalyzeQuery

func (s *ServerQueryEngine) AnalyzeQuery(ctx *sql.Context, query string) (sql.Node, error)

func (*ServerQueryEngine) Close

func (s *ServerQueryEngine) Close() error

func (*ServerQueryEngine) CloseSession

func (s *ServerQueryEngine) CloseSession(connID uint32)

func (*ServerQueryEngine) EngineAnalyzer

func (s *ServerQueryEngine) EngineAnalyzer() *analyzer.Analyzer

func (*ServerQueryEngine) EnginePreparedDataCache

func (s *ServerQueryEngine) EnginePreparedDataCache() *sqle.PreparedDataCache

func (*ServerQueryEngine) NewConnection

func (s *ServerQueryEngine) NewConnection(ctx *sql.Context) error

NewConnection creates a new connection to the server regardless of whether there is an existing connection. If there is an existing connection, it closes it and creates a new connection. New connection uses new session that the previous session state data will not persist. This function is also called when there is no connection when running a query.

func (*ServerQueryEngine) PrepareQuery

func (s *ServerQueryEngine) PrepareQuery(ctx *sql.Context, query string) (sql.Node, error)

func (*ServerQueryEngine) Query

func (s *ServerQueryEngine) Query(ctx *sql.Context, query string) (sql.Schema, sql.RowIter, error)

func (*ServerQueryEngine) QueryWithBindings

func (s *ServerQueryEngine) QueryWithBindings(ctx *sql.Context, query string, parsed sqlparser.Statement, bindings map[string]*query.BindVariable) (sql.Schema, sql.RowIter, error)

type SkippingHarness

type SkippingHarness interface {
	// SkipQueryTest returns whether to skip a test of the provided query string.
	SkipQueryTest(query string) bool
}

SkippingHarness provides a way for integrators to skip tests that are known to be broken. E.g., integrators that can't handle every possible SQL type.

type SkippingMemoryHarness

type SkippingMemoryHarness struct {
	MemoryHarness
}

func NewSkippingMemoryHarness

func NewSkippingMemoryHarness() *SkippingMemoryHarness

func (SkippingMemoryHarness) SkipQueryTest

func (s SkippingMemoryHarness) SkipQueryTest(query string) bool

type SpatialIndexPlanTest

type SpatialIndexPlanTest struct {
	// contains filtered or unexported fields
}

type SpatialIndexPlanTestAssertion

type SpatialIndexPlanTestAssertion struct {
	// contains filtered or unexported fields
}

type TestProvider

type TestProvider struct {
	sql.MutableDatabaseProvider
	// contains filtered or unexported fields
}

func NewTestProvider

func NewTestProvider(dbProvider *sql.MutableDatabaseProvider, tf ...sql.TableFunction) *TestProvider

func (TestProvider) Function

func (t TestProvider) Function(_ *sql.Context, name string) (sql.Function, error)

func (TestProvider) TableFunction

func (t TestProvider) TableFunction(_ *sql.Context, name string) (sql.TableFunction, error)

func (TestProvider) WithTableFunctions

func (t TestProvider) WithTableFunctions(fns ...sql.TableFunction) (sql.TableFunctionProvider, error)

type TransactionHarness

type TransactionHarness interface {
	Harness

	// NewSession returns a context with a new Session, rather than reusing an existing session from previous calls to
	// NewContext()
	NewSession() *sql.Context
}

type ValidatingHarness

type ValidatingHarness interface {
	Harness

	// ValidateEngine runs post-test assertions against an engine.
	ValidateEngine(ctx *sql.Context, e *sqle.Engine) error
}

type VersionedDBHarness

type VersionedDBHarness interface {
	Harness

	// NewDatabases returns a set of new databases used for the duration of a versioned test
	NewDatabases(names ...string) []sql.Database

	// NewTableAsOf creates a new table with the given name and schema, optionally handling snapshotting with the asOf
	// identifier. NewTableAsOf must ignore tables that already exist in the database. Tables returned by this method do
	// not need to have any previously created data in them, but they can. This behavior is implementation specific, and
	// the harness works either way.
	NewTableAsOf(db sql.VersionedDatabase, name string, schema sql.PrimaryKeySchema, asOf interface{}) sql.Table
	// SnapshotTable creates a snapshot of the table named with the given asOf label. Depending on the implementation,
	// NewTableAsOf might do all the necessary work to create such snapshots, so this could be a no-op.
	SnapshotTable(db sql.VersionedDatabase, name string, asOf interface{}) error
}

VersionedDBHarness is an extension to Harness that lets an integrator test their implementation of versioned (AS OF) queries. Integrators must implement sql.VersionedDatabase. For each table version being created, there will be a call to NewTableAsOf, some number of Delete and Insert operations, and then a call to SnapshotTable.

Directories

Path Synopsis
plangen
cmd/plangen command
scriptgen
cmd/scriptgen command
check command
convert command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL