catalog

package
v0.0.0-...-068cd59 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

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.

Index

Constants

View Source
const (
	// ManagedCommentPrefix is the prefix for comments that are managed by the catalog.
	ManagedCommentPrefix = "base64:"
	// SequenceNamePrefix is the prefix for sequence names that are managed by the catalog.
	SequenceNamePrefix = "__sys_table_seq_"
)
View Source
const DuckDBDecimalTypeMaxPrecision = 38

Variables

View Source
var (
	ErrDuckDB     = errors.NewKind("duckdb: %v")
	ErrTranspiler = errors.NewKind("transpiler: %v")
)
View Source
var (
	SchemaNameSYS           string = "__sys__"
	MacroNameMyListContains string = "my_list_contains"

	MacroNameMySplitListStr string = "my_split_list_str"
)
View Source
var InitialDataTables = struct {
	PGNamespace [][]any
	PGRange     [][]any
}{
	PGNamespace: [][]any{
		{"99", "pg_toast", "10", ""},
		{"11", "pg_catalog", "10", "{postgres=UC/postgres,=U/postgres}"},
		{"2200", "public", "6171", "{pg_database_owner,=UC/pg_database_owner,=U/pg_database_owner}"},
		{"13219", "information_schema", "10", "{postgres=UC/postgres,=U/postgres}"},
		{"16395", "test_schema", "10", ""},
	},
	PGRange: [][]any{
		{"3904", "23", "4451", "0", "1978", "int4range_canonical", "int4range_subdiff"},
		{"3906", "1700", "4532", "0", "3125", "-", "numrange_subdiff"},
		{"3908", "1114", "4533", "0", "3128", "-", "tsrange_subdiff"},
		{"3910", "1184", "4534", "0", "3127", "-", "tstzrange_subdiff"},
		{"3912", "1082", "4535", "0", "3122", "daterange_canonical", "daterange_subdiff"},
		{"3926", "20", "4536", "0", "3124", "int8range_canonical", "int8range_subdiff"},
	},
}
View Source
var InternalMacros = []InternalMacro{
	{
		Schema:       "information_schema",
		Name:         "_pg_expandarray",
		IsTableMacro: true,
		Definitions: []MacroDefinition{
			{
				Params: []string{"a"},
				DDL: `SELECT STRUCT_PACK(
    x := unnest(a),
    n := generate_series(1, array_length(a))
) AS item`,
			},
		},
	},
	{
		Schema:       "pg_catalog",
		Name:         "pg_get_indexdef",
		IsTableMacro: false,
		Definitions: []MacroDefinition{
			{
				Params: []string{"index_oid"},

				DDL: `''`,
			},
			{
				Params: []string{"index_oid", "column_no", "pretty_bool"},

				DDL: `''`,
			},
		},
	},
	{
		Schema:       "pg_catalog",
		Name:         "pg_get_expr",
		IsTableMacro: false,
		Definitions: []MacroDefinition{
			{
				Params: []string{"pg_node_tree", "relation_oid"},

				DDL: `pg_catalog.pg_get_expr(pg_node_tree, relation_oid)`,
			},
			{
				Params: []string{"pg_node_tree", "relation_oid", "pretty_bool"},

				DDL: `pg_catalog.pg_get_expr(pg_node_tree, relation_oid)`,
			},
		},
	},
	{
		Schema:       SchemaNameSYS,
		Name:         MacroNameMyListContains,
		IsTableMacro: false,
		Definitions: []MacroDefinition{
			{
				Params: []string{"l", "v"},
				DDL: `CASE
    WHEN typeof(l) = 'VARCHAR' THEN
        list_contains(regexp_split_to_array(l::VARCHAR, '[{},\s]+'), v)
    ELSE
        list_contains(l::text[], v)
    END`,
			},
		},
	},
	{
		Schema:       SchemaNameSYS,
		Name:         MacroNameMySplitListStr,
		IsTableMacro: false,
		Definitions: []MacroDefinition{
			{
				Params: []string{"l"},
				DDL:    `regexp_split_to_array(l::VARCHAR, '[{},\s]+')`,
			},
		},
	},
}
View Source
var InternalSchemas = struct {
	SYS   InternalSchema
	MySQL InternalSchema
}{
	SYS: InternalSchema{
		Schema: "__sys__",
	},
	MySQL: InternalSchema{
		Schema: "mysql",
	},
}
View Source
var InternalTables = struct {
	PersistentVariable InternalTable
	BinlogPosition     InternalTable
	PgSubscription     InternalTable
	GlobalStatus       InternalTable
	// TODO(sean): This is a temporary work around for clients that query the 'pg_catalog.pg_stat_replication'.
	//             Once we add 'pg_catalog' and support views for PG, replace this by a view.
	//             https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-REPLICATION-VIEW
	PGStatReplication InternalTable
	PGRange           InternalTable
	PGType            InternalTable
	PGProc            InternalTable
	PGClass           InternalTable
	PGNamespace       InternalTable
	PGMatViews        InternalTable
}{
	PersistentVariable: InternalTable{
		Schema:       "__sys__",
		Name:         "persistent_variable",
		KeyColumns:   []string{"name"},
		ValueColumns: []string{"value", "vtype"},
		DDL:          "name TEXT PRIMARY KEY, value TEXT, vtype TEXT",
	},
	BinlogPosition: InternalTable{
		Schema:       "__sys__",
		Name:         "binlog_position",
		KeyColumns:   []string{"channel"},
		ValueColumns: []string{"position"},
		DDL:          "channel TEXT PRIMARY KEY, position TEXT",
	},
	PgSubscription: InternalTable{
		Schema:       "__sys__",
		Name:         "pg_subscription",
		KeyColumns:   []string{"subname"},
		ValueColumns: []string{"subconninfo", "subpublication", "subskiplsn", "subenabled"},
		DDL:          "subname TEXT PRIMARY KEY, subconninfo TEXT, subpublication TEXT, subskiplsn TEXT, subenabled BOOLEAN",
	},
	GlobalStatus: InternalTable{
		Schema:       "performance_schema",
		Name:         "global_status",
		KeyColumns:   []string{"VARIABLE_NAME"},
		ValueColumns: []string{"VARIABLE_VALUE"},
		DDL:          "VARIABLE_NAME TEXT PRIMARY KEY, VARIABLE_VALUE TEXT",
		InitialData: [][]any{
			{"Innodb_redo_log_enabled", "OFF"},
		},
	},

	PGStatReplication: InternalTable{

		Schema: "__sys__",
		Name:   "pg_stat_replication",
		KeyColumns: []string{
			"pid",
		},
		ValueColumns: []string{
			"usesysid",
			"usename",
			"application_name",
			"client_addr",
			"client_hostname",
			"client_port",
			"backend_start",
			"backend_xmin",
			"state",
			"sent_lsn",
			"write_lsn",
			"flush_lsn",
			"replay_lsn",
			"write_lag",
			"flush_lag",
			"replay_lag",
			"sync_priority",
			"sync_state",
			"reply_time",
		},
		DDL: "pid INTEGER PRIMARY KEY, usesysid TEXT, usename TEXT, application_name TEXT, client_addr TEXT, client_hostname TEXT, client_port INTEGER, backend_start TIMESTAMP, backend_xmin INTEGER, state TEXT, sent_lsn TEXT, write_lsn TEXT, flush_lsn TEXT, replay_lsn TEXT, write_lag INTERVAL, flush_lag INTERVAL, replay_lag INTERVAL, sync_priority INTEGER, sync_state TEXT, reply_time TIMESTAMP",
	},
	PGRange: InternalTable{
		Schema:       "__sys__",
		Name:         "pg_range",
		KeyColumns:   []string{"rngtypid"},
		ValueColumns: []string{"rngsubtype", "rngmultitypid", "rngcollation", "rngsubopc", "rngcanonical", "rngsubdiff"},
		DDL:          "rngtypid BIGINT PRIMARY KEY, rngsubtype BIGINT, rngmultitypid BIGINT, rngcollation BIGINT, rngsubopc BIGINT, rngcanonical VARCHAR, rngsubdiff VARCHAR",
		InitialData:  InitialDataTables.PGRange,
	},

	PGType: InternalTable{
		Schema: "__sys__",
		Name:   "pg_type",
		KeyColumns: []string{
			"oid",
		},
		ValueColumns: []string{
			"typname", "typnamespace", "typowner", "typlen", "typbyval",
			"typtype", "typcategory", "typispreferred", "typisdefined", "typdelim",
			"typrelid", "typsubscript", "typelem", "typarray", "typinput",
			"typoutput", "typreceive", "typsend", "typmodin", "typmodout",
			"typanalyze", "typalign", "typstorage", "typnotnull", "typbasetype",
			"typtypmod", "typndims", "typcollation", "typdefaultbin", "typdefault",
			"typacl",
		},
		DDL: "oid BIGINT NOT NULL PRIMARY KEY, " +
			"typname VARCHAR , " +
			"typnamespace BIGINT , " +
			"typowner BIGINT , " +
			"typlen SMALLINT , " +
			"typbyval BOOLEAN , " +
			"typtype CHAR , " +
			"typcategory CHAR , " +
			"typispreferred BOOLEAN , " +
			"typisdefined BOOLEAN , " +
			"typdelim CHAR , " +
			"typrelid BIGINT , " +
			"typsubscript BIGINT , " +
			"typelem BIGINT , " +
			"typarray BIGINT , " +
			"typinput BIGINT , " +
			"typoutput BIGINT , " +
			"typreceive BIGINT , " +
			"typsend BIGINT , " +
			"typmodin BIGINT , " +
			"typmodout BIGINT , " +
			"typanalyze BIGINT , " +
			"typalign CHAR , " +
			"typstorage CHAR , " +
			"typnotnull BOOLEAN , " +
			"typbasetype BIGINT , " +
			"typtypmod INTEGER , " +
			"typndims INTEGER , " +
			"typcollation BIGINT , " +
			"typdefaultbin VARCHAR, " +
			"typdefault TEXT, " +
			"typacl TEXT",
	},

	PGProc: InternalTable{
		Schema: "__sys__",
		Name:   "pg_proc",
		KeyColumns: []string{
			"oid",
		},
		ValueColumns: []string{
			"proname",
			"pronamespace",
			"proowner",
			"prolang",
			"procost",
			"prorows",
			"provariadic",
			"prosupport",
			"prokind",
			"prosecdef",
			"proleakproof",
			"proisstrict",
			"proretset",
			"provolatile",
			"proparallel",
			"pronargs",
			"pronargdefaults",
			"prorettype",
			"proargtypes",
			"proallargtypes",
			"proargmodes",
			"proargnames",
			"proargdefaults",
			"protrftypes",
			"prosrc",
			"probin",
			"prosqlbody",
			"proconfig",
			"proacl",
		},
		DDL: "oid BIGINT NOT NULL PRIMARY KEY," +
			"proname VARCHAR ," +
			"pronamespace BIGINT ," +
			"proowner BIGINT ," +
			"prolang BIGINT ," +
			"procost FLOAT ," +
			"prorows FLOAT ," +
			"provariadic BIGINT ," +
			"prosupport BIGINT ," +
			"prokind CHAR ," +
			"prosecdef BOOLEAN ," +
			"proleakproof BOOLEAN ," +
			"proisstrict BOOLEAN ," +
			"proretset BOOLEAN ," +
			"provolatile CHAR ," +
			"proparallel CHAR ," +
			"pronargs SMALLINT ," +
			"pronargdefaults SMALLINT ," +
			"prorettype BIGINT ," +
			"proargtypes VARCHAR ," +
			"proallargtypes VARCHAR," +
			"proargmodes VARCHAR," +
			"proargnames VARCHAR," +
			"proargdefaults TEXT," +
			"protrftypes VARCHAR," +
			"prosrc TEXT ," +
			"probin TEXT," +
			"prosqlbody TEXT," +
			"proconfig VARCHAR," +
			"proacl VARCHAR",
	},

	PGClass: InternalTable{
		Schema: "__sys__",
		Name:   "pg_class",
		KeyColumns: []string{
			"oid",
		},
		ValueColumns: []string{
			"relname",
			"relnamespace",
			"reltype",
			"reloftype",
			"relowner",
			"relam",
			"relfilenode",
			"reltablespace",
			"relpages",
			"reltuples",
			"relallvisible",
			"reltoastrelid",
			"relhasindex",
			"relisshared",
			"relpersistence",
			"relkind",
			"relnatts",
			"relchecks",
			"relhasrules",
			"relhastriggers",
			"relhassubclass",
			"relrowsecurity",
			"relforcerowsecurity",
			"relispopulated",
			"relreplident",
			"relispartition",
			"relrewrite",
			"relfrozenxid",
			"relminmxid",
			"relacl",
			"reloptions",
			"relpartbound",
		},
		DDL: "oid BIGINT NOT NULL PRIMARY KEY," +
			"relname VARCHAR ," +
			"relnamespace BIGINT ," +
			"reltype BIGINT ," +
			"reloftype BIGINT ," +
			"relowner BIGINT ," +
			"relam BIGINT ," +
			"relfilenode BIGINT ," +
			"reltablespace BIGINT ," +
			"relpages INTEGER ," +
			"reltuples FLOAT ," +
			"relallvisible INTEGER ," +
			"reltoastrelid BIGINT ," +
			"relhasindex BOOLEAN ," +
			"relisshared BOOLEAN ," +
			"relpersistence CHAR ," +
			"relkind CHAR ," +
			"relnatts SMALLINT ," +
			"relchecks SMALLINT ," +
			"relhasrules BOOLEAN ," +
			"relhastriggers BOOLEAN ," +
			"relhassubclass BOOLEAN ," +
			"relrowsecurity BOOLEAN ," +
			"relforcerowsecurity BOOLEAN ," +
			"relispopulated BOOLEAN ," +
			"relreplident CHAR ," +
			"relispartition BOOLEAN ," +
			"relrewrite BIGINT ," +
			"relfrozenxid BIGINT ," +
			"relminmxid BIGINT ," +
			"relacl TEXT," +
			"reloptions TEXT," +
			"relpartbound TEXT",
	},

	PGNamespace: InternalTable{
		Schema: "__sys__",
		Name:   "pg_namespace",
		KeyColumns: []string{
			"oid",
		},
		ValueColumns: []string{
			"nspname",
			"nspowner",
			"nspacl",
		},
		DDL: "oid BIGINT NOT NULL PRIMARY KEY," +
			"nspname VARCHAR NOT NULL," +
			"nspowner BIGINT NOT NULL," +
			"nspacl TEXT",
		InitialData: InitialDataTables.PGNamespace,
	},

	PGMatViews: InternalTable{
		Schema: "__sys__",
		Name:   "pg_matviews",
		KeyColumns: []string{
			"schemaname",
			"matviewname",
		},
		ValueColumns: []string{
			"matviewowner",
			"tablespace",
			"hasindexes",
			"ispopulated",
			"definition",
		},
		DDL: "schemaname VARCHAR NOT NULL, " +
			"matviewname VARCHAR NOT NULL, " +
			"matviewowner VARCHAR, " +
			"tablespace VARCHAR, " +
			"hasindexes BOOLEAN, " +
			"ispopulated BOOLEAN, " +
			"definition TEXT",
	},
}
View Source
var InternalViews = []InternalView{
	{
		Schema: "__sys__",
		Name:   "pg_stat_user_tables",
		DDL: `SELECT
    t.table_schema || '.' || t.table_name AS relid, -- Create a unique ID for the table
    t.table_schema AS schemaname,                  -- Schema name
    t.table_name AS relname,                       -- Table name
    0 AS seq_scan,                                 -- Default to 0 (DuckDB doesn't track this)
    NULL AS last_seq_scan,                         -- Placeholder (DuckDB doesn't track this)
    0 AS seq_tup_read,                             -- Default to 0
    0 AS idx_scan,                                 -- Default to 0
    NULL AS last_idx_scan,                         -- Placeholder
    0 AS idx_tup_fetch,                            -- Default to 0
    0 AS n_tup_ins,                                -- Default to 0 (inserted tuples not tracked)
    0 AS n_tup_upd,                                -- Default to 0 (updated tuples not tracked)
    0 AS n_tup_del,                                -- Default to 0 (deleted tuples not tracked)
    0 AS n_tup_hot_upd,                            -- Default to 0 (HOT updates not tracked)
    0 AS n_tup_newpage_upd,                        -- Default to 0 (new page updates not tracked)
    0 AS n_live_tup,                               -- Default to 0 (live tuples not tracked)
    0 AS n_dead_tup,                               -- Default to 0 (dead tuples not tracked)
    0 AS n_mod_since_analyze,                      -- Default to 0
    0 AS n_ins_since_vacuum,                       -- Default to 0
    NULL AS last_vacuum,                           -- Placeholder
    NULL AS last_autovacuum,                       -- Placeholder
    NULL AS last_analyze,                          -- Placeholder
    NULL AS last_autoanalyze,                      -- Placeholder
    0 AS vacuum_count,                             -- Default to 0
    0 AS autovacuum_count,                         -- Default to 0
    0 AS analyze_count,                            -- Default to 0
    0 AS autoanalyze_count                         -- Default to 0
FROM
    information_schema.tables t
WHERE
    t.table_type = 'BASE TABLE'; -- Include only base tables (not views)`,
	},
	{
		Schema: "__sys__",
		Name:   "pg_index",
		DDL: `SELECT
    ROW_NUMBER() OVER () AS indexrelid,                -- Simulated unique ID for the index
    t.table_oid AS indrelid,                          -- OID of the table
    COUNT(k.column_name) AS indnatts,                 -- Number of columns included in the index
    COUNT(k.column_name) AS indnkeyatts,              -- Number of key columns in the index (same as indnatts here)
    CASE
        WHEN c.constraint_type = 'UNIQUE' THEN TRUE
        ELSE FALSE
    END AS indisunique,                               -- Indicates if the index is unique
    CASE
        WHEN c.constraint_type = 'PRIMARY KEY' THEN TRUE
        ELSE FALSE
    END AS indisprimary,                              -- Indicates if the index is a primary key
    ARRAY_AGG(k.ordinal_position ORDER BY k.ordinal_position) AS indkey,  -- Array of column positions
    ARRAY[]::BIGINT[] AS indcollation,                -- DuckDB does not support collation, set to default
    ARRAY[]::BIGINT[] AS indclass,                    -- DuckDB does not support index class, set to default
    ARRAY[]::INTEGER[] AS indoption,                  -- DuckDB does not support index options, set to default
    NULL AS indexprs,                                 -- DuckDB does not support expression indexes, set to NULL
    NULL AS indpred                                   -- DuckDB does not support partial indexes, set to NULL
FROM
    information_schema.key_column_usage k
JOIN
    information_schema.table_constraints c
    ON k.constraint_name = c.constraint_name
    AND k.table_name = c.table_name
JOIN
    duckdb_tables() t
    ON k.table_name = t.table_name
    AND k.table_schema = t.schema_name
WHERE
    c.constraint_type IN ('PRIMARY KEY', 'UNIQUE')    -- Only select primary key and unique constraints
GROUP BY
    t.table_oid, c.constraint_type, c.constraint_name
ORDER BY
    t.table_oid;`,
	},
}
View Source
var SystemViews = map[string]struct{}{
	"duckdb_columns":       {},
	"duckdb_constraints":   {},
	"duckdb_databases":     {},
	"duckdb_indexes":       {},
	"duckdb_schemas":       {},
	"duckdb_tables":        {},
	"duckdb_types":         {},
	"duckdb_views":         {},
	"pragma_database_list": {},
	"sqlite_master":        {},
	"sqlite_schema":        {},
	"sqlite_temp_master":   {},
	"sqlite_temp_schema":   {},
}

Functions

func ConnectIdentifiersANSI

func ConnectIdentifiersANSI(identifiers ...string) string

func DecodeCreateindex

func DecodeCreateindex(createIndexSQL string) ([]string, error)

func DecodeIndexName

func DecodeIndexName(encodedName string) (string, string)

func EncodeIndexName

func EncodeIndexName(table, index string) string

EncodeIndexName uses a simple encoding scheme (table$$index) for better visibility which is useful for debugging.

func FullColumnName

func FullColumnName(catalog, schema, table, column string) string

func FullIndexName

func FullIndexName(catalog, schema, index string) string

func FullSchemaName

func FullSchemaName(catalog, schema string) string

func FullTableName

func FullTableName(catalog, schema, table string) string

func IsDuckDBCatalogError

func IsDuckDBCatalogError(err error) bool

func IsDuckDBIndexAlreadyExistsError

func IsDuckDBIndexAlreadyExistsError(err error) bool

ERROR 1105 (HY000): duckdb: Catalog Error: Index with name "x_idx" already exists!

func IsDuckDBNotNullConstraintViolationError

func IsDuckDBNotNullConstraintViolationError(err error) (bool, string)

Constraint Error: NOT NULL constraint failed: <column>

func IsDuckDBSetSchemaNotFoundError

func IsDuckDBSetSchemaNotFoundError(err error) bool

ERROR 1105 (HY000): unknown error: Catalog Error: SET schema: No catalog + schema named "mysql.db0" found.

func IsDuckDBTableAlreadyExistsError

func IsDuckDBTableAlreadyExistsError(err error) bool

func IsDuckDBTableNotFoundError

func IsDuckDBTableNotFoundError(err error) bool

func IsDuckDBUniqueConstraintViolationError

func IsDuckDBUniqueConstraintViolationError(err error) bool

ERROR 1105 (HY000): duckdb: Constraint Error: Data contains duplicates on indexed column(s)

func IsDuckDBViewNotFoundError

func IsDuckDBViewNotFoundError(err error) bool

func IsSystemView

func IsSystemView(viewName string) bool

func QuoteIdentifierANSI

func QuoteIdentifierANSI(identifier string) string

Types

type AnnotatedDuckType

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

func DuckdbDataType

func DuckdbDataType(mysqlType sql.Type) (AnnotatedDuckType, error)

func (AnnotatedDuckType) MySQL

func (t AnnotatedDuckType) MySQL() MySQLType

func (AnnotatedDuckType) Name

func (t AnnotatedDuckType) Name() string

type ColumnInfo

type ColumnInfo struct {
	ColumnName    string
	ColumnIndex   int
	DataType      sql.Type
	IsNullable    bool
	ColumnDefault stdsql.NullString
	Comment       stdsql.NullString
}

type Comment

type Comment[T any] struct {
	Text string `json:"text,omitempty"`
	Meta T      `json:"meta,omitempty"` // extra information, e.g. the original MySQL column type, etc.
}

func DecodeComment

func DecodeComment[T any](encodedOrRawText string) *Comment[T]

func NewComment

func NewComment[T any](text string) *Comment[T]

func NewCommentWithMeta

func NewCommentWithMeta[T any](text string, meta T) *Comment[T]

func (*Comment[T]) Encode

func (c *Comment[T]) Encode() string

type ConnectionPool

type ConnectionPool struct {
	*stdsql.DB
	// contains filtered or unexported fields
}

func NewConnectionPool

func NewConnectionPool(connector *duckdb.Connector, db *stdsql.DB) *ConnectionPool

func (*ConnectionPool) Close

func (p *ConnectionPool) Close() error

func (*ConnectionPool) CloseConn

func (p *ConnectionPool) CloseConn(id uint32) error

func (*ConnectionPool) CloseTxn

func (p *ConnectionPool) CloseTxn(id uint32)

func (*ConnectionPool) Connector

func (p *ConnectionPool) Connector() *duckdb.Connector

func (*ConnectionPool) CurrentCatalog

func (p *ConnectionPool) CurrentCatalog(id uint32) string

CurrentCatalog retrieves the current catalog of the connection. Returns an empty string if the connection is not established or the catalog cannot be retrieved.

func (*ConnectionPool) CurrentSchema

func (p *ConnectionPool) CurrentSchema(id uint32) string

CurrentSchema retrieves the current schema of the connection. Returns an empty string if the connection is not established or the schema cannot be retrieved.

func (*ConnectionPool) GetConn

func (p *ConnectionPool) GetConn(ctx context.Context, id uint32) (*stdsql.Conn, error)

func (*ConnectionPool) GetConnForSchema

func (p *ConnectionPool) GetConnForSchema(ctx context.Context, id uint32, schemaName string) (*stdsql.Conn, error)

func (*ConnectionPool) GetTxn

func (p *ConnectionPool) GetTxn(ctx context.Context, id uint32, schemaName string, options *stdsql.TxOptions) (*stdsql.Tx, error)

func (*ConnectionPool) Reset

func (p *ConnectionPool) Reset(connector *duckdb.Connector, db *stdsql.DB) error

func (*ConnectionPool) TryGetTxn

func (p *ConnectionPool) TryGetTxn(id uint32) *stdsql.Tx

type Database

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

func NewDatabase

func NewDatabase(name string, catalogName string) *Database

func (*Database) AllViews

func (d *Database) AllViews(ctx *sql.Context) ([]sql.ViewDefinition, error)

AllViews implements sql.ViewDatabase.

func (*Database) CopyTableData

func (d *Database) CopyTableData(ctx *sql.Context, sourceTable string, destinationTable string) (uint64, error)

CopyTableData implements sql.TableCopierDatabase interface.

func (*Database) CreateTable

func (d *Database) CreateTable(ctx *sql.Context, name string, schema sql.PrimaryKeySchema, collation sql.CollationID, comment string) error

CreateTable implements sql.TableCreator.

func (*Database) CreateTemporaryTable

func (d *Database) CreateTemporaryTable(ctx *sql.Context, name string, schema sql.PrimaryKeySchema, collation sql.CollationID) error

CreateTemporaryTable implements sql.CreateTemporaryTable.

func (*Database) CreateTrigger

func (d *Database) CreateTrigger(ctx *sql.Context, definition sql.TriggerDefinition) error

CreateTrigger implements sql.TriggerDatabase.

func (*Database) CreateView

func (d *Database) CreateView(ctx *sql.Context, name string, selectStatement string, createViewStmt string) error

CreateView implements sql.ViewDatabase.

func (*Database) DropTable

func (d *Database) DropTable(ctx *sql.Context, name string) error

DropTable implements sql.TableDropper.

func (*Database) DropTrigger

func (d *Database) DropTrigger(ctx *sql.Context, name string) error

DropTrigger implements sql.TriggerDatabase.

func (*Database) DropView

func (d *Database) DropView(ctx *sql.Context, name string) error

DropView implements sql.ViewDatabase.

func (*Database) GetCollation

func (d *Database) GetCollation(ctx *sql.Context) sql.CollationID

GetCollation implements sql.CollatedDatabase.

func (*Database) GetTableInsensitive

func (d *Database) GetTableInsensitive(ctx *sql.Context, tblName string) (sql.Table, bool, error)

GetTableInsensitive implements sql.Database.

func (*Database) GetTableNames

func (d *Database) GetTableNames(ctx *sql.Context) ([]string, error)

GetTableNames implements sql.Database.

func (*Database) GetTriggers

func (d *Database) GetTriggers(ctx *sql.Context) ([]sql.TriggerDefinition, error)

GetTriggers implements sql.TriggerDatabase.

func (*Database) GetViewDefinition

func (d *Database) GetViewDefinition(ctx *sql.Context, viewName string) (sql.ViewDefinition, bool, error)

GetViewDefinition implements sql.ViewDatabase.

func (*Database) Name

func (d *Database) Name() string

Name implements sql.Database.

func (*Database) RenameTable

func (d *Database) RenameTable(ctx *sql.Context, oldName string, newName string) error

RenameTable implements sql.TableRenamer.

func (*Database) SetCollation

func (d *Database) SetCollation(ctx *sql.Context, collation sql.CollationID) error

SetCollation implements sql.CollatedDatabase.

type DatabaseProvider

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

func NewDBProvider

func NewDBProvider(defaultTimeZone, dataDir, defaultDB string) (prov *DatabaseProvider, err error)

func NewInMemoryDBProvider

func NewInMemoryDBProvider() *DatabaseProvider

func (*DatabaseProvider) AllDatabases

func (prov *DatabaseProvider) AllDatabases(ctx *sql.Context) []sql.Database

AllDatabases implements sql.DatabaseProvider.

func (*DatabaseProvider) AttachCatalog

func (prov *DatabaseProvider) AttachCatalog(file interface {
	IsDir() bool
	Name() string
}, ignoreNonDB bool) error

func (*DatabaseProvider) Close

func (prov *DatabaseProvider) Close() error

func (*DatabaseProvider) Connector

func (prov *DatabaseProvider) Connector() *duckdb.Connector

func (*DatabaseProvider) CreateCatalog

func (prov *DatabaseProvider) CreateCatalog(name string, ifNotExists bool) error

func (*DatabaseProvider) CreateDatabase

func (prov *DatabaseProvider) CreateDatabase(ctx *sql.Context, name string) error

CreateDatabase implements sql.MutableDatabaseProvider.

func (*DatabaseProvider) DataDir

func (prov *DatabaseProvider) DataDir() string

func (*DatabaseProvider) Database

func (prov *DatabaseProvider) Database(ctx *sql.Context, name string) (sql.Database, error)

Database implements sql.DatabaseProvider.

func (*DatabaseProvider) DbFile

func (prov *DatabaseProvider) DbFile() string

func (*DatabaseProvider) DefaultCatalogName

func (prov *DatabaseProvider) DefaultCatalogName() string

func (*DatabaseProvider) DropCatalog

func (prov *DatabaseProvider) DropCatalog(name string, ifExists bool) error

func (*DatabaseProvider) DropDatabase

func (prov *DatabaseProvider) DropDatabase(ctx *sql.Context, name string) error

DropDatabase implements sql.MutableDatabaseProvider.

func (*DatabaseProvider) ExternalStoredProcedure

func (prov *DatabaseProvider) ExternalStoredProcedure(ctx *sql.Context, name string, numOfParams int) (*sql.ExternalStoredProcedureDetails, error)

ExternalStoredProcedure implements sql.ExternalStoredProcedureProvider.

func (*DatabaseProvider) ExternalStoredProcedures

func (prov *DatabaseProvider) ExternalStoredProcedures(ctx *sql.Context, name string) ([]sql.ExternalStoredProcedureDetails, error)

ExternalStoredProcedures implements sql.ExternalStoredProcedureProvider.

func (*DatabaseProvider) HasCatalog

func (prov *DatabaseProvider) HasCatalog(name string) bool

func (*DatabaseProvider) HasDatabase

func (prov *DatabaseProvider) HasDatabase(ctx *sql.Context, name string) bool

HasDatabase implements sql.DatabaseProvider.

func (*DatabaseProvider) IsReady

func (prov *DatabaseProvider) IsReady() bool

func (*DatabaseProvider) Pool

func (prov *DatabaseProvider) Pool() *ConnectionPool

func (*DatabaseProvider) Restart

func (prov *DatabaseProvider) Restart(readOnly bool) error

func (*DatabaseProvider) Storage

func (prov *DatabaseProvider) Storage() *stdsql.DB

type EmptyTableEditor

type EmptyTableEditor struct {
}

func (*EmptyTableEditor) Close

func (e *EmptyTableEditor) Close(*sql.Context) error

Close implements sql.RowUpdater.

func (*EmptyTableEditor) DiscardChanges

func (e *EmptyTableEditor) DiscardChanges(ctx *sql.Context, errorEncountered error) error

DiscardChanges implements sql.RowUpdater.

func (*EmptyTableEditor) StatementBegin

func (e *EmptyTableEditor) StatementBegin(ctx *sql.Context)

StatementBegin implements sql.RowUpdater.

func (*EmptyTableEditor) StatementComplete

func (e *EmptyTableEditor) StatementComplete(ctx *sql.Context) error

StatementComplete implements sql.RowUpdater.

func (*EmptyTableEditor) Update

func (e *EmptyTableEditor) Update(ctx *sql.Context, old sql.Row, new sql.Row) error

Update implements sql.RowUpdater.

type ExtraTableInfo

type ExtraTableInfo struct {
	PkOrdinals []int
	Replicated bool
	Sequence   string
	Checks     []sql.CheckDefinition
}

type Index

type Index struct {
	DbName     string
	TableName  string
	Exprs      []sql.Expression
	Name       string
	Unique     bool
	CommentObj *Comment[any]
	PrefixLens []uint16
}

func NewIndex

func NewIndex(dbName, tableName, name string, unique bool, comment *Comment[any], exprs []sql.Expression) *Index

func (*Index) CanSupport

func (idx *Index) CanSupport(ranges ...sql.Range) bool

CanSupport returns whether this index supports lookups on the given range filters.

func (*Index) CanSupportOrderBy

func (idx *Index) CanSupportOrderBy(expr sql.Expression) bool

CanSupportOrderBy returns whether this index can optimize ORDER BY a given expression type. Verifying that the expression's children match the index columns are done separately.

func (*Index) ColumnExpressionTypes

func (idx *Index) ColumnExpressionTypes() []sql.ColumnExpressionType

ColumnExpressionTypes returns each expression and its associated Type. Each expression string should exactly match the string returned from Index.Expressions(). ColumnExpressionTypes implements the interface sql.Index.

func (*Index) Comment

func (idx *Index) Comment() string

Comment returns the comment for this index

func (*Index) Database

func (idx *Index) Database() string

Database returns the database name this index belongs to.

func (*Index) Expressions

func (idx *Index) Expressions() []string

Expressions returns the indexed expressions. If the result is more than one expression, it means the index has multiple columns indexed. If it's just one, it means it may be an expression or a column.

func (*Index) ID

func (idx *Index) ID() string

ID returns the identifier of the index.

func (*Index) IndexType

func (idx *Index) IndexType() string

IndexType returns the type of this index, e.g. BTREE

func (*Index) IsFullText

func (idx *Index) IsFullText() bool

IsFullText returns whether this index is a Full-Text index

func (*Index) IsGenerated

func (idx *Index) IsGenerated() bool

IsGenerated returns whether this index was generated. Generated indexes are used for index access, but are not displayed (such as with SHOW INDEXES).

func (*Index) IsSpatial

func (idx *Index) IsSpatial() bool

IsSpatial returns whether this index is a spatial index

func (*Index) IsUnique

func (idx *Index) IsUnique() bool

IsUnique returns whether this index is unique

func (*Index) IsVector

func (idx *Index) IsVector() bool

IsVector returns whether this index is a vector index

func (*Index) PrefixLengths

func (idx *Index) PrefixLengths() []uint16

PrefixLengths returns the prefix lengths for each column in this index

func (*Index) Table

func (idx *Index) Table() string

Table returns the table name this index belongs to.

type IndexedTable

type IndexedTable struct {
	*Table
	Lookup sql.IndexLookup
}

func (*IndexedTable) LookupPartitions

func (t *IndexedTable) LookupPartitions(ctx *sql.Context, lookup sql.IndexLookup) (sql.PartitionIter, error)

type InternalMacro

type InternalMacro struct {
	Schema       string
	Name         string
	IsTableMacro bool
	// A macro can be overloaded with multiple definitions, each with a different set of parameters.
	// https://duckdb.org/docs/sql/statements/create_macro.html#overloading
	Definitions []MacroDefinition
}

func (*InternalMacro) QualifiedName

func (v *InternalMacro) QualifiedName() string

type InternalSchema

type InternalSchema struct {
	Schema string
}

type InternalTable

type InternalTable struct {
	Schema       string
	Name         string
	KeyColumns   []string
	ValueColumns []string
	DDL          string
	InitialData  [][]any
}

func GetInternalTables

func GetInternalTables() []InternalTable

func (*InternalTable) CountAllStmt

func (it *InternalTable) CountAllStmt() string

func (*InternalTable) DeleteAllStmt

func (it *InternalTable) DeleteAllStmt() string

func (*InternalTable) DeleteStmt

func (it *InternalTable) DeleteStmt() string

func (*InternalTable) QualifiedName

func (it *InternalTable) QualifiedName() string

func (*InternalTable) SelectAllStmt

func (it *InternalTable) SelectAllStmt() string

func (*InternalTable) SelectColumnsStmt

func (it *InternalTable) SelectColumnsStmt(valueColumns []string) string

func (*InternalTable) SelectStmt

func (it *InternalTable) SelectStmt() string

func (*InternalTable) UpdateAllStmt

func (it *InternalTable) UpdateAllStmt(valueColumns []string) string

func (*InternalTable) UpdateStmt

func (it *InternalTable) UpdateStmt(keyColumns []string, valueColumns []string) string

func (*InternalTable) UpsertStmt

func (it *InternalTable) UpsertStmt() string

type InternalView

type InternalView struct {
	Schema string
	Name   string
	DDL    string
}

func (*InternalView) QualifiedName

func (v *InternalView) QualifiedName() string

type MacroDefinition

type MacroDefinition struct {
	Params []string
	DDL    string
}

type MySQLType

type MySQLType struct {
	Name          string
	Length        uint32   `json:",omitempty"`
	Precision     uint8    `json:",omitempty"`
	Scale         uint8    `json:",omitempty"`
	Unsigned      bool     `json:",omitempty"`
	Display       uint8    `json:",omitempty"` // Display width for integer types
	Collation     uint16   `json:",omitempty"` // For string types
	Values        []string `json:",omitempty"` // For ENUM and SET
	Default       string   `json:",omitempty"` // Default value of column
	AutoIncrement bool     `json:",omitempty"` // Auto increment flag
}

type Table

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

func NewTable

func NewTable(db *Database, name string, hasPrimaryKey bool) *Table

func (*Table) AddColumn

func (t *Table) AddColumn(ctx *sql.Context, column *sql.Column, order *sql.ColumnOrder) error

AddColumn implements sql.AlterableTable.

func (*Table) AutoIncrementSetter

func (t *Table) AutoIncrementSetter(ctx *sql.Context) sql.AutoIncrementSetter

AutoIncrementSetter implements sql.AutoIncrementTable.

func (*Table) Collation

func (t *Table) Collation() sql.CollationID

Collation implements sql.Table.

func (*Table) Comment

func (t *Table) Comment() string

Comment implements sql.CommentedTable.

func (*Table) CreateCheck

func (t *Table) CreateCheck(ctx *sql.Context, check *sql.CheckDefinition) error

AddCheck implements sql.CheckAlterableTable.

func (*Table) CreateIndex

func (t *Table) CreateIndex(ctx *sql.Context, indexDef sql.IndexDef) error

CreateIndex implements sql.IndexAlterableTable.

func (*Table) Deleter

func (t *Table) Deleter(*sql.Context) sql.RowDeleter

Deleter implements sql.DeletableTable.

func (*Table) DropCheck

func (t *Table) DropCheck(ctx *sql.Context, checkName string) error

DropCheck implements sql.CheckAlterableTable.

func (*Table) DropColumn

func (t *Table) DropColumn(ctx *sql.Context, columnName string) error

DropColumn implements sql.AlterableTable.

func (*Table) DropIndex

func (t *Table) DropIndex(ctx *sql.Context, indexName string) error

DropIndex implements sql.IndexAlterableTable.

func (*Table) ExtraTableInfo

func (t *Table) ExtraTableInfo() ExtraTableInfo

func (*Table) GetChecks

func (t *Table) GetChecks(ctx *sql.Context) ([]sql.CheckDefinition, error)

CheckConstraints implements sql.CheckTable.

func (*Table) GetIndexes

func (t *Table) GetIndexes(ctx *sql.Context) ([]sql.Index, error)

GetIndexes implements sql.IndexAddressableTable. This is only used for show index in SHOW INDEX and SHOW CREATE TABLE.

func (*Table) GetNextAutoIncrementValue

func (t *Table) GetNextAutoIncrementValue(ctx *sql.Context, insertVal any) (uint64, error)

GetNextAutoIncrementValue implements sql.AutoIncrementTable.

func (*Table) HasPrimaryKey

func (t *Table) HasPrimaryKey() bool

func (*Table) IndexedAccess

func (t *Table) IndexedAccess(lookup sql.IndexLookup) sql.IndexedTable

IndexedAccess implements sql.IndexAddressableTable.

func (*Table) Inserter

func (t *Table) Inserter(*sql.Context) sql.RowInserter

Inserter implements sql.InsertableTable.

func (*Table) ModifyColumn

func (t *Table) ModifyColumn(ctx *sql.Context, columnName string, column *sql.Column, order *sql.ColumnOrder) error

ModifyColumn implements sql.AlterableTable.

func (*Table) Name

func (t *Table) Name() string

Name implements sql.Table.

func (*Table) PartitionRows

func (t *Table) PartitionRows(ctx *sql.Context, _ sql.Partition) (sql.RowIter, error)

PartitionRows implements sql.Table.

func (*Table) Partitions

func (t *Table) Partitions(ctx *sql.Context) (sql.PartitionIter, error)

Partitions implements sql.Table.

func (*Table) PeekNextAutoIncrementValue

func (t *Table) PeekNextAutoIncrementValue(ctx *sql.Context) (uint64, error)

PeekNextAutoIncrementValue implements sql.AutoIncrementTable.

func (*Table) PreciseMatch

func (t *Table) PreciseMatch() bool

PreciseMatch implements sql.IndexAddressableTable.

func (*Table) PrimaryKeySchema

func (t *Table) PrimaryKeySchema() sql.PrimaryKeySchema

PrimaryKeySchema implements sql.PrimaryKeyTable.

func (*Table) RenameIndex

func (t *Table) RenameIndex(ctx *sql.Context, fromIndexName string, toIndexName string) error

RenameIndex implements sql.IndexAlterableTable.

func (*Table) Replacer

func (t *Table) Replacer(*sql.Context) sql.RowReplacer

Replacer implements sql.ReplaceableTable.

func (*Table) Schema

func (t *Table) Schema() sql.Schema

Schema implements sql.Table.

func (*Table) String

func (t *Table) String() string

String implements sql.Table.

func (*Table) Truncate

func (t *Table) Truncate(ctx *sql.Context) (int, error)

Truncate implements sql.TruncateableTable.

func (*Table) Updater

func (t *Table) Updater(ctx *sql.Context) sql.RowUpdater

Updater implements sql.AlterableTable.

Jump to

Keyboard shortcuts

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