Documentation
¶
Overview ¶
Copyright 2024-2025 ApeCloud, Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2024-2025 ApeCloud, Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2024-2025 ApeCloud, Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func ApplyQueryRowLimit(ctx *sql.Context, schema sql.Schema, iter sql.RowIter) sql.RowIter
- func IsPureDataQuery(ctx *sql.Context, n sql.Node) bool
- func IsWriteQueryText(query string) bool
- func NewSessionBuilder(provider *catalog.DatabaseProvider, opts ...SessionOption) func(ctx context.Context, conn *mysql.Conn, addr string) (sql.Session, error)
- func QueryForJSONScan(query string, schema sql.Schema) string
- func RemoveAllPipes(dataDir string) error
- func RewriteIncomingQuery(query string) string
- func WrapHandler(provider *catalog.DatabaseProvider, engine *sqle.Engine, ...) server.HandlerWrapper
- type DuckBuilder
- type MyHandler
- func (h *MyHandler) ComBind(ctx context.Context, c *mysql.Conn, query string, ...) (mysql.BoundQuery, []*querypb.Field, error)
- func (h *MyHandler) ComExecuteBound(ctx context.Context, c *mysql.Conn, query string, boundQuery mysql.BoundQuery, ...) (returnErr error)
- func (h *MyHandler) ComInitDB(c *mysql.Conn, schemaName string) error
- func (h *MyHandler) ComMultiQuery(ctx context.Context, c *mysql.Conn, query string, callback mysql.ResultSpoolFn) (rest string, returnErr error)
- func (h *MyHandler) ComParsedQuery(ctx context.Context, c *mysql.Conn, query string, parsed sqlparser.Statement, ...) (returnErr error)
- func (h *MyHandler) ComPrepare(ctx context.Context, c *mysql.Conn, query string, prepare *mysql.PrepareData) ([]*querypb.Field, error)
- func (h *MyHandler) ComPrepareParsed(ctx context.Context, c *mysql.Conn, query string, parsed sqlparser.Statement, ...) (mysql.ParsedQuery, []*querypb.Field, error)
- func (h *MyHandler) ComQuery(ctx context.Context, c *mysql.Conn, query string, callback mysql.ResultSpoolFn) (returnErr error)
- func (h *MyHandler) ComStmtExecute(ctx context.Context, c *mysql.Conn, prepare *mysql.PrepareData, ...) (returnErr error)
- func (h *MyHandler) ConnectionClosed(c *mysql.Conn)
- type QueryAudit
- type RequestModifier
- type ResultModifier
- type SQLRowIter
- type Session
- func (sess *Session) CloseConn()
- func (sess *Session) CloseTxn()
- func (sess *Session) CommitTransaction(ctx *sql.Context, tx sql.Transaction) error
- func (sess *Session) CurrentSchemaOfUnderlyingConn() string
- func (sess *Session) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error)
- func (sess *Session) GetCatalogConn(ctx context.Context) (*stdsql.Conn, error)
- func (sess *Session) GetCatalogTxn(ctx context.Context, options *stdsql.TxOptions) (*stdsql.Tx, error)
- func (sess *Session) GetConn(ctx context.Context) (*stdsql.Conn, error)
- func (sess *Session) GetCurrentCatalog() string
- func (sess *Session) GetCurrentSchema() string
- func (sess *Session) GetPersistedValue(k string) (interface{}, error)
- func (sess *Session) GetTxn(ctx context.Context, options *stdsql.TxOptions) (*stdsql.Tx, error)
- func (sess *Session) PersistGlobal(ctx *sql.Context, sysVarName string, value interface{}) error
- func (sess *Session) Provider() *catalog.DatabaseProvider
- func (sess *Session) QueryRow(ctx context.Context, query string, args ...any) *stdsql.Row
- func (sess *Session) QueryRowLimit() uint64
- func (sess *Session) RemoveAllPersistedGlobals() error
- func (sess *Session) RemovePersistedGlobal(sysVarName string) error
- func (sess *Session) Rollback(ctx *sql.Context, tx sql.Transaction) error
- func (sess *Session) SetSessionVariable(ctx *sql.Context, name string, value interface{}) error
- func (sess *Session) StartTransaction(ctx *sql.Context, tCharacteristic sql.TransactionCharacteristic) (sql.Transaction, error)
- func (sess *Session) TryGetTxn() *stdsql.Tx
- type SessionOption
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyQueryRowLimit ¶
ApplyQueryRowLimit wraps result rows with the limit configured on the current session. Non-row results and sessions with no limit are unchanged.
func IsPureDataQuery ¶
IsPureDataQuery inspects if the plan is a pure data query, i.e., it operates on (>=1) data tables and does not touch any system tables. The following examples are NOT pure data queries: - `SELECT * FROM mysql.*` - `TRUNCATE mysql.user` - `SELECT DATABASE()`
func IsWriteQueryText ¶
IsWriteQueryText classifies statements that could not be parsed by the protocol-specific engine. Parsed statements should use their AST instead.
func NewSessionBuilder ¶
func NewSessionBuilder(provider *catalog.DatabaseProvider, opts ...SessionOption) func(ctx context.Context, conn *mysql.Conn, addr string) (sql.Session, error)
NewSessionBuilder returns a session builder for the given database provider.
func QueryForJSONScan ¶
QueryForJSONScan casts JSON result columns to VARCHAR before the DuckDB Go driver can collapse JSON null into SQL NULL.
func RemoveAllPipes ¶
func RewriteIncomingQuery ¶
RewriteIncomingQuery applies the default request modifiers. Tests and protocol handlers use this so replica-dump DDL is rewritten the same way as live MySQL connections.
Types ¶
type DuckBuilder ¶
type DuckBuilder struct {
FlushDeltaBuffer func(*sql.Context) error
// contains filtered or unexported fields
}
func NewDuckBuilder ¶
func NewDuckBuilder(base *rowexec.BaseBuilder, provider *catalog.DatabaseProvider) *DuckBuilder
func NewEngine ¶
func NewEngine(provider *catalog.DatabaseProvider) (*sqle.Engine, *DuckBuilder)
NewEngine constructs the MySQL engine with MyDuck's parser and executor compatibility boundaries installed consistently.
func (*DuckBuilder) CreatePipe ¶
func (*DuckBuilder) Provider ¶
func (b *DuckBuilder) Provider() *catalog.DatabaseProvider
type MyHandler ¶
func (*MyHandler) ComBind ¶
func (h *MyHandler) ComBind(ctx context.Context, c *mysql.Conn, query string, parsedQuery mysql.ParsedQuery, prepare *mysql.PrepareData) (mysql.BoundQuery, []*querypb.Field, error)
func (*MyHandler) ComExecuteBound ¶
func (*MyHandler) ComMultiQuery ¶
func (*MyHandler) ComParsedQuery ¶
func (*MyHandler) ComPrepare ¶
func (*MyHandler) ComPrepareParsed ¶
func (*MyHandler) ComQuery ¶
func (h *MyHandler) ComQuery( ctx context.Context, c *mysql.Conn, query string, callback mysql.ResultSpoolFn, ) (returnErr error)
Naive query rewriting. This is just a temporary solution and should be replaced with a more robust implementation.
func (*MyHandler) ComStmtExecute ¶
func (*MyHandler) ConnectionClosed ¶
type QueryAudit ¶
type QueryAudit struct {
// contains filtered or unexported fields
}
QueryAudit records the outcome of one ordinary protocol query.
func NewQueryAudit ¶
func NewQueryAudit(conn *mysql.Conn, protocol, query string) *QueryAudit
NewQueryAudit starts an audit record for a user-facing protocol query.
func (*QueryAudit) AddRows ¶
func (audit *QueryAudit) AddRows(rows int)
AddRows records rows successfully handed to the protocol callback.
func (*QueryAudit) Complete ¶
func (audit *QueryAudit) Complete(err error)
Complete emits the query's single structured audit record.
type RequestModifier ¶
type RequestModifier func(string, *[]ResultModifier) string
RequestModifier is a function type that transforms a query string
type ResultModifier ¶
ResultModifier transforms a Result.
type SQLRowIter ¶
type SQLRowIter struct {
// contains filtered or unexported fields
}
SQLRowIter wraps a standard sql.Rows as a RowIter.
func NewSQLRowIter ¶
type Session ¶
func NewSession ¶
func NewSession(base *memory.Session, provider *catalog.DatabaseProvider, opts ...SessionOption) *Session
func (*Session) CloseConn ¶
func (sess *Session) CloseConn()
CloseConn implements adapter.ConnectionHolder.
func (*Session) CloseTxn ¶
func (sess *Session) CloseTxn()
CloseTxn implements adapter.ConnectionHolder.
func (*Session) CommitTransaction ¶
CommitTransaction implements sql.TransactionSession.
func (*Session) CurrentSchemaOfUnderlyingConn ¶
func (*Session) ExecContext ¶
func (*Session) GetCatalogConn ¶
GetCatalogConn implements adapter.ConnectionHolder.
func (*Session) GetCatalogTxn ¶
func (sess *Session) GetCatalogTxn(ctx context.Context, options *stdsql.TxOptions) (*stdsql.Tx, error)
GetCatalogTxn implements adapter.ConnectionHolder.
func (*Session) GetCurrentCatalog ¶
GetCurrentCatalog implements adapter.ConnectionHolder.
func (*Session) GetCurrentSchema ¶
GetCurrentSchema implements adapter.ConnectionHolder.
func (*Session) GetPersistedValue ¶
GetPersistedValue implements sql.PersistableSession.
func (*Session) PersistGlobal ¶
PersistGlobal implements sql.PersistableSession.
func (*Session) Provider ¶
func (sess *Session) Provider() *catalog.DatabaseProvider
Provider returns the database provider for the session.
func (*Session) QueryRowLimit ¶
QueryRowLimit returns the maximum number of rows a query may return. Zero means unlimited.
func (*Session) RemoveAllPersistedGlobals ¶
RemoveAllPersistedGlobals implements sql.PersistableSession.
func (*Session) RemovePersistedGlobal ¶
RemovePersistedGlobal implements sql.PersistableSession.
func (*Session) SetSessionVariable ¶
func (*Session) StartTransaction ¶
func (sess *Session) StartTransaction(ctx *sql.Context, tCharacteristic sql.TransactionCharacteristic) (sql.Transaction, error)
StartTransaction implements sql.TransactionSession.
type SessionOption ¶
type SessionOption func(*Session)
func WithQueryRowLimit ¶
func WithQueryRowLimit(limit uint64) SessionOption
WithQueryRowLimit limits the number of rows returned by queries in a session. A limit of zero leaves query results unlimited.
type Transaction ¶
type Transaction struct {
memory.Transaction
// contains filtered or unexported fields
}