systemcatalog

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsChunkEvent

func IsChunkEvent(
	relation *pgtypes.RelationMessage,
) bool

IsChunkEvent returns true if the given relation represents a chunk system catalog entry, otherwise false

func IsContinuousAggregateHypertable

func IsContinuousAggregateHypertable(
	hypertableName string,
) bool

IsContinuousAggregateHypertable returns true if the given hypertable name is a backing hypertable for a continuous aggregate, otherwise false

func IsHypertableEvent

func IsHypertableEvent(
	relation *pgtypes.RelationMessage,
) bool

IsHypertableEvent returns true if the given relation represents a hypertable system catalog entry, otherwise false

func IsVanillaTable added in v0.10.0

func IsVanillaTable(
	relation *pgtypes.RelationMessage,
) bool

func MakeRelationKey

func MakeRelationKey(
	schemaName, tableName string,
) string

Types

type BaseTable added in v0.10.0

type BaseTable interface {
	SystemEntity
	Columns() Columns
	TableColumns() []schema.ColumnAlike
	KeyIndexColumns() []schema.ColumnAlike
	ReplicaIdentity() pgtypes.ReplicaIdentity
	SchemaBuilder() schema.Builder
	ApplyTableSchema(newColumns []Column) (changes map[string]string)
}

type Chunk

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

func NewChunk

func NewChunk(
	id, hypertableId int32, schemaName, tableName string, dropped bool, status int32, compressedChunkId *int32,
) *Chunk

func (*Chunk) ApplyChanges

func (c *Chunk) ApplyChanges(
	schemaName, tableName string, dropped bool, status int32, compressedChunkId *int32,
) (*Chunk, map[string]string)

func (Chunk) CanonicalName

func (bse Chunk) CanonicalName() string

func (*Chunk) CompressedChunkId

func (c *Chunk) CompressedChunkId() *int32

func (*Chunk) Dropped

func (c *Chunk) Dropped() bool

func (*Chunk) HypertableId

func (c *Chunk) HypertableId() int32

func (*Chunk) Id

func (c *Chunk) Id() int32

func (*Chunk) IsCompressed

func (c *Chunk) IsCompressed() bool

func (*Chunk) IsPartiallyCompressed

func (c *Chunk) IsPartiallyCompressed() bool

func (Chunk) SchemaName

func (bse Chunk) SchemaName() string

func (*Chunk) Status

func (c *Chunk) Status() int32

func (*Chunk) String added in v0.0.10

func (c *Chunk) String() string

func (Chunk) TableName

func (bse Chunk) TableName() string

type Column

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

Column represents a column from a hypertable or index

func NewColumn

func NewColumn(
	name string, dataType uint32, modifiers int, pgType pgtypes.PgType, nullable bool, defaultValue *string,
) Column

NewColumn instantiates a new Column instance which isn't part of any index. This method is a shorthand version of NewIndexColumn

func NewIndexColumn

func NewIndexColumn(
	name string, dataType uint32, modifiers int, pgType pgtypes.PgType,
	nullable, primaryKey bool, keySeq *int, defaultValue *string, isReplicaIdent bool,
	indexName *string, sortOrder IndexSortOrder, nullsOrder IndexNullsOrder,
	dimension, dimAligned bool, dimType *string, dimSeq, maxCharLength *int,
) Column

NewIndexColumn instantiates a new Column instance

func (Column) DataType

func (c Column) DataType() uint32

DataType returns the PostgreSQL OID of the column

func (Column) DefaultValue

func (c Column) DefaultValue() *string

DefaultValue returns the default value of the column, otherwise nil if no default value is defined

func (Column) DimensionType

func (c Column) DimensionType() *string

DimensionType returns the type (`space` or `time`) of the dimension. If not a dimension, this function returns nil.

func (Column) Format added in v0.3.1

func (c Column) Format() string

func (Column) IsDimension

func (c Column) IsDimension() bool

IsDimension returns true if the column is used as a dimension of the hypertable

func (Column) IsDimensionAligned

func (c Column) IsDimensionAligned() bool

IsDimensionAligned returns true if the range of the dimension is aligned

func (Column) IsNullable

func (c Column) IsNullable() bool

IsNullable returns true if the column is nullable

func (Column) IsPrimaryKey

func (c Column) IsPrimaryKey() bool

IsPrimaryKey returns true if the columns is part of a primary key index

func (Column) IsReplicaIdent

func (c Column) IsReplicaIdent() bool

IsReplicaIdent returns true if the columns is part of a replica identity index

func (Column) MaxCharLength added in v0.3.1

func (c Column) MaxCharLength() *int

MaxCharLength returns the maximum number of characters necessary to represent the value as a string (if the type is type limited), otherwise it returns nil

func (Column) Modifiers added in v0.3.1

func (c Column) Modifiers() int

Modifiers returns the type specific modifiers for this column. If no specific modifiers is set, -1 is returned

func (Column) Name

func (c Column) Name() string

Name returns the column name

func (Column) PgType added in v0.2.0

func (c Column) PgType() pgtypes.PgType

PgType returns the PG type of the column

func (Column) SchemaBuilder added in v0.3.0

func (c Column) SchemaBuilder() schema.Builder

SchemaBuilder returns a schema builder based on the column's PgType and internal state (default value, nullable, name, etc).

func (Column) SchemaType added in v0.3.1

func (c Column) SchemaType() schema.Type

func (Column) String added in v0.0.10

func (c Column) String() string

type Columns

type Columns []Column

Columns represents a collection of columns which may or may not represent an index

func (Columns) HasPrimaryKey

func (c Columns) HasPrimaryKey() bool

HasPrimaryKey returns true if the collection of columns contains one or more primary key column(s)

func (Columns) HasReplicaIdentity

func (c Columns) HasReplicaIdentity() bool

HasReplicaIdentity returns true if the collection of columns contains one or more replica identity column(s)

func (Columns) PrimaryKeyIndex

func (c Columns) PrimaryKeyIndex() (index *Index, present bool)

PrimaryKeyIndex returns an Index instance which represents the primary key definition of the collection of columns and true, otherwise present will be false, meaning, that there isn't a primary key available in this collection

func (Columns) ReplicaIdentityIndex

func (c Columns) ReplicaIdentityIndex() (index *Index, present bool)

ReplicaIdentityIndex returns an Index instance which represents the primary key definition of the collection of columns and true, otherwise present will be false, meaning, that there isn't a primary key available in this collection

func (Columns) SnapshotIndex

func (c Columns) SnapshotIndex() (index *Index, present bool)

SnapshotIndex returns the index used for snapshot watermarks. This can either be an actual index, such as a primary key, or a virtual index based on the dimensions of the hypertable.

type Hypertable

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

Hypertable represents a TimescaleDB hypertable definition in the system catalog

func NewHypertable

func NewHypertable(
	id int32, schemaName, tableName, associatedSchemaName, associatedTablePrefix string,
	compressedHypertableId *int32, compressionState int16, distributed bool,
	viewSchema, viewName *string, replicaIdentity pgtypes.ReplicaIdentity,
) *Hypertable

NewHypertable instantiates a new Hypertable entity

func (*Hypertable) ApplyChanges

func (h *Hypertable) ApplyChanges(
	schemaName, tableName, associatedSchemaName, associatedTablePrefix string,
	compressedHypertableId *int32, compressionState int16,
	replicaIdentity pgtypes.ReplicaIdentity,
) (applied *Hypertable, changes map[string]string)

ApplyChanges applies catalog changes to a copy of the hypertable instance (not updating the current one) and returns the new instance and a collection of applied changes.

func (Hypertable) ApplyTableSchema

func (bt Hypertable) ApplyTableSchema(
	newColumns []Column,
) (changes map[string]string)

ApplyTableSchema applies a new table schema to this table and returns changes to the previously known schema layout.

func (*Hypertable) CanonicalContinuousAggregateName

func (h *Hypertable) CanonicalContinuousAggregateName() string

CanonicalContinuousAggregateName returns the canonical continuous aggregate name of the hypertable in the form of <<schema.view>>. This method panics if the hypertable doesn't back a continuous aggregate. A check using IsContinuousAggregate before calling this method is advised.

func (Hypertable) Columns

func (bt Hypertable) Columns() Columns

Columns returns a slice with the column definitions of the table

func (*Hypertable) CompressedHypertableId

func (h *Hypertable) CompressedHypertableId() (compressedHypertableId int32, present bool)

CompressedHypertableId returns the id of a hypertable which is used to represent the compressed chunks and true, otherwise present will be false

func (*Hypertable) Id

func (h *Hypertable) Id() int32

Id returns the hypertable id

func (*Hypertable) IsCompressedTable

func (h *Hypertable) IsCompressedTable() bool

IsCompressedTable returns true if the hypertable is a compressed hypertable (not if the hypertable has compression enabled), otherwise false

func (*Hypertable) IsCompressionEnabled

func (h *Hypertable) IsCompressionEnabled() bool

IsCompressionEnabled returns true if the hypertable has compression enabled (not if the hypertable is a compressed hypertable), otherwise false

func (*Hypertable) IsContinuousAggregate

func (h *Hypertable) IsContinuousAggregate() bool

IsContinuousAggregate returns true if the hypertable is a backing hypertable for a continues aggregate, otherwise false

func (*Hypertable) IsDistributed

func (h *Hypertable) IsDistributed() bool

IsDistributed returns true if the hypertable is a distributed hypertable, otherwise false

func (*Hypertable) KeyIndexColumns added in v0.4.0

func (h *Hypertable) KeyIndexColumns() []schema.ColumnAlike

KeyIndexColumns returns a slice of ColumnAlike entries representing the snapshot index, or nil. A snapshot index is either the (composite) primary key or a "virtual" index built from the hypertable's dimensions

func (Hypertable) ReplicaIdentity

func (bt Hypertable) ReplicaIdentity() pgtypes.ReplicaIdentity

ReplicaIdentity returns the replica identity (if available), otherwise a pgtypes.UNKNOWN is returned

func (Hypertable) SchemaBuilder added in v0.3.0

func (bt Hypertable) SchemaBuilder() schema.Builder

SchemaBuilder returns a SchemaBuilder instance, preconfigured for this table

func (*Hypertable) String added in v0.0.10

func (h *Hypertable) String() string

func (Hypertable) TableColumns added in v0.3.1

func (bt Hypertable) TableColumns() []schema.ColumnAlike

TableColumns returns a slice of ColumnAlike entries representing the columns of this table

func (*Hypertable) ViewName

func (h *Hypertable) ViewName() (viewName string, present bool)

ViewName returns the view name and true if the hypertable is a backing hypertable for a continuous aggregate, otherwise the present will be false

func (*Hypertable) ViewSchema

func (h *Hypertable) ViewSchema() (viewSchemaName string, present bool)

ViewSchema returns the view schema name and true if the hypertable is a backing hypertable for a continuous aggregate, otherwise the present will be false

type Index

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

Index represents either a (compound) primary key index or replica identity index in the database and attached to a hypertable (and its chunks)

func (*Index) AsSqlOrderBy

func (i *Index) AsSqlOrderBy(
	desc bool,
) string

AsSqlOrderBy creates a string for ORDER BY clauses with all parts of the index being ordered in descending direction

func (*Index) AsSqlTuple

func (i *Index) AsSqlTuple() string

AsSqlTuple creates a string to be used as a tuple definition in a WHERE-clause: (col1, col2, col3, ...)

func (*Index) Columns

func (i *Index) Columns() []Column

Columns returns an array of colum instances representing the columns of the index (in order of definition)

func (*Index) Name

func (i *Index) Name() string

Name returns the index name

func (*Index) PrimaryKey

func (i *Index) PrimaryKey() bool

PrimaryKey returns true if the index represents a primary key, otherwise false

func (*Index) ReplicaIdentity

func (i *Index) ReplicaIdentity() bool

ReplicaIdentity returns true if the index represents a replica identity index, otherwise false

func (*Index) String added in v0.0.10

func (i *Index) String() string

func (*Index) WhereTupleEQ

func (i *Index) WhereTupleEQ(
	params map[string]any,
) (string, bool)

WhereTupleEQ creates a WHERE-clause string which selects all values equal to the given set of index parameter values

func (*Index) WhereTupleGE

func (i *Index) WhereTupleGE(
	params map[string]any,
) (string, bool)

WhereTupleGE creates a WHERE-clause string which selects all values greater or equal to the given set of index parameter values

func (*Index) WhereTupleGT

func (i *Index) WhereTupleGT(
	params map[string]any,
) (string, bool)

WhereTupleGT creates a WHERE-clause string which selects all values greater than to the given set of index parameter values

func (*Index) WhereTupleLE

func (i *Index) WhereTupleLE(
	params map[string]any,
) (string, bool)

WhereTupleLE creates a WHERE-clause string which selects all values less or equal to the given set of index parameter values

func (*Index) WhereTupleLT

func (i *Index) WhereTupleLT(
	params map[string]any,
) (string, bool)

WhereTupleLT creates a WHERE-clause string which selects all values less than to the given set of index parameter values

type IndexNullsOrder

type IndexNullsOrder string
const (
	NULLS_FIRST IndexNullsOrder = "NULLS FIRST"
	NULLS_LAST  IndexNullsOrder = "NULLS LAST"
)

type IndexSortOrder

type IndexSortOrder string
const (
	ASC  IndexSortOrder = "ASC"
	DESC IndexSortOrder = "DESC"
)

type PgTable added in v0.10.0

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

PgTable represents a vanilla PostgreSQL table definition in the system catalog

func NewPgTable added in v0.10.0

func NewPgTable(
	relId uint32, schemaName, tableName string, replicaIdentity pgtypes.ReplicaIdentity,
) *PgTable

NewPgTable instantiates a new PgTable entity

func (*PgTable) ApplyChanges added in v0.10.0

func (t *PgTable) ApplyChanges(
	schemaName, tableName string, replicaIdentity pgtypes.ReplicaIdentity,
) (applied *PgTable, changes map[string]string)

ApplyChanges applies catalog changes to a copy of the table (not updating the current one) and returns the new instance and a collection of applied changes.

func (PgTable) ApplyTableSchema added in v0.11.0

func (bt PgTable) ApplyTableSchema(
	newColumns []Column,
) (changes map[string]string)

ApplyTableSchema applies a new table schema to this table and returns changes to the previously known schema layout.

func (PgTable) Columns added in v0.11.0

func (bt PgTable) Columns() Columns

Columns returns a slice with the column definitions of the table

func (*PgTable) KeyIndexColumns added in v0.10.0

func (t *PgTable) KeyIndexColumns() []schema.ColumnAlike

KeyIndexColumns returns a slice of ColumnAlike entries representing the snapshot index, or nil. A snapshot index must be the (composite) primary key of the table, since no dimensions exists (as with hypertables),

func (*PgTable) RelId added in v0.10.0

func (t *PgTable) RelId() uint32

RelId returns the table's relation id

func (PgTable) ReplicaIdentity added in v0.11.0

func (bt PgTable) ReplicaIdentity() pgtypes.ReplicaIdentity

ReplicaIdentity returns the replica identity (if available), otherwise a pgtypes.UNKNOWN is returned

func (PgTable) SchemaBuilder added in v0.11.0

func (bt PgTable) SchemaBuilder() schema.Builder

SchemaBuilder returns a SchemaBuilder instance, preconfigured for this table

func (*PgTable) String added in v0.10.0

func (t *PgTable) String() string

func (PgTable) TableColumns added in v0.11.0

func (bt PgTable) TableColumns() []schema.ColumnAlike

TableColumns returns a slice of ColumnAlike entries representing the columns of this table

type SystemCatalog added in v0.4.0

type SystemCatalog interface {
	FindVanillaTableById(
		relId uint32,
	) (table *PgTable, present bool)

	FindVanillaTableByName(
		schemaName, tableName string,
	) (table *PgTable, present bool)

	FindHypertableById(
		hypertableId int32,
	) (hypertable *Hypertable, present bool)

	FindHypertableByName(
		schemaName, tableName string,
	) (hypertable *Hypertable, present bool)

	FindHypertableByChunkId(
		chunkId int32,
	) (hypertable *Hypertable, present bool)

	FindHypertableByCompressedHypertableId(
		compressedHypertableId int32,
	) (hypertable *Hypertable, present bool)

	FindCompressedHypertableByHypertableId(
		hypertableId int32,
	) (hypertable *Hypertable, present bool)

	FindChunkById(
		id int32,
	) (chunk *Chunk, present bool)

	FindChunkByName(
		schemaName, tableName string,
	) (chunk *Chunk, present bool)

	ResolveOriginHypertable(
		chunk *Chunk,
	) (hypertable *Hypertable, present bool)

	ResolveUncompressedHypertable(
		hypertableId int32,
	) (uncompressedHypertable, compressedHypertable *Hypertable, present bool)

	IsHypertableSelectedForReplication(
		hypertableId int32,
	) bool

	RegisterHypertable(
		hypertable *Hypertable,
	) error

	UnregisterHypertable(
		hypertable *Hypertable,
	) error

	RegisterChunk(
		chunk *Chunk,
	) error

	UnregisterChunk(
		chunk *Chunk,
	) error

	ApplySchemaUpdate(
		table SystemEntity, columns []Column,
	) error

	GetAllChunks() []SystemEntity

	GetAllVanillaTables() []SystemEntity

	GetAllHypertables() []SystemEntity
}

type SystemEntity

type SystemEntity interface {
	// SchemaName returns the schema name of the entity
	SchemaName() string
	// TableName returns the table name of the entity
	TableName() string
	// CanonicalName returns the canonical name of the entity >>schema.table<<
	CanonicalName() string
}

SystemEntity represents an entity defined by its canonical elements (schema and table names)

func NewSystemEntity

func NewSystemEntity(
	schemaName, tableName string,
) SystemEntity

NewSystemEntity instantiates a new basic SystemEntity

Jump to

Keyboard shortcuts

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