Documentation ¶
Overview ¶
Package schema defines types supported by tables in source plugins
nolint:gocritic
Index ¶
- Constants
- Variables
- func CQColumnToArrowField(col *Column) arrow.Field
- func CQSchemaToArrow(table *Table) *arrow.Schema
- func CQTypesOneToRecord(mem memory.Allocator, c CQTypes, arrowSchema *arrow.Schema) arrow.Record
- func CQTypesToRecord(mem memory.Allocator, c []CQTypes, arrowSchema *arrow.Schema) arrow.Record
- func IsIncremental(s *arrow.Schema) bool
- func IsPk(f arrow.Field) bool
- func IsUnique(f arrow.Field) bool
- func NewFieldMetadataFromOptions(opts MetadataFieldOptions) arrow.Metadata
- func NewSchemaMetadataFromOptions(opts MetadataSchemaOptions) arrow.Metadata
- func PrimaryKeyIndices(sc *arrow.Schema) []int
- func SetPk(f *arrow.Field)
- func TableName(sc *arrow.Schema) string
- func TableNameFromSchema(schema *arrow.Schema) (string, error)
- func TransformWithTransformer(transformer CQTypeTransformer, values CQTypes) []any
- func UnsetPk(f *arrow.Field)
- func ValidateTable(t *Table) error
- type ArrayDimension
- type Bool
- type BoolTransformer
- type Bytea
- type ByteaTransformer
- type CIDR
- type CIDRArray
- type CIDRArrayTransformer
- type CIDRTransformer
- type CQType
- type CQTypeTransformer
- type CQTypes
- type ClientMeta
- type Column
- type ColumnCreationOptions
- type ColumnList
- type ColumnResolver
- type DefaultTransformer
- func (*DefaultTransformer) TransformBool(v *Bool) any
- func (*DefaultTransformer) TransformBytea(v *Bytea) any
- func (*DefaultTransformer) TransformCIDR(v *CIDR) any
- func (*DefaultTransformer) TransformCIDRArray(v *CIDRArray) any
- func (*DefaultTransformer) TransformFloat8(v *Float8) any
- func (*DefaultTransformer) TransformInet(v *Inet) any
- func (*DefaultTransformer) TransformInetArray(v *InetArray) any
- func (*DefaultTransformer) TransformInt8(v *Int8) any
- func (*DefaultTransformer) TransformInt8Array(v *Int8Array) any
- func (*DefaultTransformer) TransformJSON(v *JSON) any
- func (*DefaultTransformer) TransformMacaddr(v *Macaddr) any
- func (*DefaultTransformer) TransformMacaddrArray(v *MacaddrArray) any
- func (*DefaultTransformer) TransformText(v *Text) any
- func (*DefaultTransformer) TransformTextArray(v *TextArray) any
- func (*DefaultTransformer) TransformTimestamptz(v *Timestamptz) any
- func (*DefaultTransformer) TransformUUID(v *UUID) any
- func (*DefaultTransformer) TransformUUIDArray(v *UUIDArray) any
- type DestinationResource
- type FieldChange
- type Float8
- type Float8Transformer
- type Inet
- type InetArray
- type InetArrayTransformer
- type InetTransformer
- type InfinityModifier
- type Int8
- type Int8Array
- type Int8ArrayTransformer
- type Int8Transformer
- type JSON
- type JSONTransformer
- type LengthTableValidator
- type Macaddr
- type MacaddrArray
- type MacaddrArrayTransformer
- type MacaddrTransformer
- type MetadataFieldOptions
- type MetadataSchemaOptions
- type Multiplexer
- type Resource
- func (r *Resource) CalculateCQID(deterministicCQID bool) error
- func (r *Resource) Columns() []string
- func (r *Resource) Get(columnName string) CQType
- func (r *Resource) GetItem() any
- func (r *Resource) GetValues() CQTypes
- func (r *Resource) Set(columnName string, value any) error
- func (r *Resource) SetItem(item any)
- func (r *Resource) ToDestinationResource() DestinationResource
- func (r *Resource) Validate() error
- type Resources
- type RowResolver
- type Schemas
- type Status
- type SyncSummary
- type Table
- func (t *Table) Column(name string) *Column
- func (t *Table) Copy(parent *Table) *Table
- func (t *Table) GetChanges(old *Table) []TableColumnChange
- func (t *Table) IncrementalKeys() []string
- func (t *Table) OverwriteOrAddColumn(column *Column)
- func (t *Table) PrimaryKeys() []string
- func (t *Table) TableNames() []string
- func (t *Table) ToArrowSchema() *arrow.Schema
- func (t *Table) ValidateColumnNames() error
- func (t *Table) ValidateDuplicateColumns() error
- func (t *Table) ValidateName() error
- type TableColumnChange
- type TableColumnChangeType
- type TableResolver
- type TableValidator
- type Tables
- func (tt Tables) FilterDfs(tables, skipTables []string, skipDependentTables bool) (Tables, error)
- func (tt Tables) FilterDfsFunc(include, exclude func(*Table) bool, skipDependentTables bool) Tables
- func (tt Tables) FlattenTables() Tables
- func (tt Tables) Get(name string) *Table
- func (tt Tables) GetTopLevel(name string) *Table
- func (tt Tables) TableNames() []string
- func (tt Tables) ToArrowSchemas() Schemas
- func (tt Tables) ValidateColumnNames() error
- func (tt Tables) ValidateDuplicateColumns() error
- func (tt Tables) ValidateDuplicateTables() error
- func (tt Tables) ValidateTableNames() error
- type Text
- type TextArray
- type TextArrayTransformer
- type TextTransformer
- type Timestamptz
- func (dst *Timestamptz) DecodeText(src []byte) error
- func (dst *Timestamptz) Equal(src CQType) bool
- func (dst Timestamptz) Get() any
- func (dst *Timestamptz) GetStatus() Status
- func (dst *Timestamptz) Set(src any) error
- func (dst *Timestamptz) Size() int
- func (dst *Timestamptz) String() string
- func (*Timestamptz) Type() ValueType
- type TimestamptzTransformer
- type Transform
- type UUID
- type UUIDArray
- type UUIDArrayTransformer
- type UUIDTransformer
- type ValidationError
- type ValueType
Constants ¶
const ( MetadataUnique = "cq:extension:unique" MetadataPrimaryKey = "cq:extension:primary_key" MetadataConstraintName = "cq:extension:constraint_name" MetadataIncremental = "cq:extension:incremental" MetadataTrue = "true" MetadataFalse = "false" MetadataTableName = "cq:table_name" )
Variables ¶
var CqIDColumn = Column{ Name: "_cq_id", Type: TypeUUID, Description: "Internal CQ ID of the row", CreationOptions: ColumnCreationOptions{ NotNull: true, Unique: true, }, }
These columns are managed and populated by the source plugins
var CqIDField = arrow.Field{ Name: "_cq_id", Type: types.ExtensionTypes.UUID, Metadata: arrow.MetadataFrom(map[string]string{ MetadataUnique: MetadataTrue, }), }
var CqParentIDColumn = Column{ Name: "_cq_parent_id", Type: TypeUUID, Description: "Internal CQ ID of the parent row", Resolver: parentCqUUIDResolver(), IgnoreInTests: true, }
var CqSourceNameColumn = Column{ Name: "_cq_source_name", Type: TypeString, Description: "Internal CQ row that references the source plugin name data was retrieved", }
var CqSourceNameField = arrow.Field{ Name: "_cq_source_name", Type: arrow.BinaryTypes.String, }
var CqSyncTimeColumn = Column{ Name: "_cq_sync_time", Type: TypeTimestamp, Description: "Internal CQ row of when sync was started (this will be the same for all rows in a single fetch)", }
These columns are managed and populated by the destination plugin.
var CqSyncTimeField = arrow.Field{ Name: "_cq_sync_time", Type: arrow.FixedWidthTypes.Timestamp_us, }
Functions ¶
func CQColumnToArrowField ¶
func CQSchemaToArrow ¶
func CQTypesOneToRecord ¶
func CQTypesToRecord ¶
func IsIncremental ¶
func NewFieldMetadataFromOptions ¶
func NewFieldMetadataFromOptions(opts MetadataFieldOptions) arrow.Metadata
func NewSchemaMetadataFromOptions ¶
func NewSchemaMetadataFromOptions(opts MetadataSchemaOptions) arrow.Metadata
func PrimaryKeyIndices ¶
func TransformWithTransformer ¶
func TransformWithTransformer(transformer CQTypeTransformer, values CQTypes) []any
func ValidateTable ¶
Types ¶
type ArrayDimension ¶
type BoolTransformer ¶
type ByteaTransformer ¶
type CIDRArray ¶
type CIDRArray struct { Elements []CIDR Dimensions []ArrayDimension Status Status }
type CIDRArrayTransformer ¶
type CIDRTransformer ¶
type CQType ¶
type CQType interface { Set(v any) error Get() any String() string // Used only in testing Equal(CQType) bool Type() ValueType Size() int GetStatus() Status }
func NewCqTypeFromValueType ¶
type CQTypeTransformer ¶
type CQTypeTransformer interface { BoolTransformer ByteaTransformer CIDRArrayTransformer CIDRTransformer Float8Transformer InetArrayTransformer InetTransformer Int8ArrayTransformer Int8Transformer JSONTransformer MacaddrArrayTransformer MacaddrTransformer TextArrayTransformer TextTransformer TimestamptzTransformer UUIDArrayTransformer UUIDTransformer }
type CQTypes ¶
type CQTypes []CQType
func (CQTypes) MarshalJSON ¶
func (CQTypes) Size ¶
Size returns total number of bytes occupied by all values this useful to understand how much data is being transferred, rather than just number of resources.
func (*CQTypes) UnmarshalJSON ¶
type ClientMeta ¶
type ClientMeta interface {
ID() string
}
type Column ¶
type Column struct { // Name of column Name string `json:"name,omitempty"` // Value Type of column i.e String, UUID etc' Type ValueType `json:"type,omitempty"` // Description about column, this description is added as a comment in the database Description string `json:"-"` // Column Resolver allows to set your own data for a column; this can be an API call, setting multiple embedded values, etc Resolver ColumnResolver `json:"-"` // Creation options allow modifying how column is defined when table is created CreationOptions ColumnCreationOptions `json:"creation_options,omitempty"` // IgnoreInTests is used to skip verifying the column is non-nil in integration tests. // By default, integration tests perform a fetch for all resources in cloudquery's test account, and // verify all columns are non-nil. // If IgnoreInTests is true, verification is skipped for this column. // Used when it is hard to create a reproducible environment with this column being non-nil (e.g. various error columns). IgnoreInTests bool `json:"-"` }
Column definition for Table
func (Column) ToArrowField ¶
type ColumnCreationOptions ¶
type ColumnCreationOptions struct { PrimaryKey bool `json:"primary_key,omitempty"` NotNull bool `json:"not_null,omitempty"` // IncrementalKey is a flag that indicates if the column is used as part of an incremental key. // It is mainly used for documentation purposes, but may also be used as part of ensuring that // migrations are done correctly. IncrementalKey bool `json:"incremental_key"` Unique bool `json:"unique,omitempty"` }
ColumnCreationOptions allow modification of how column is defined when table is created
type ColumnList ¶
type ColumnList []Column
func (ColumnList) Get ¶
func (c ColumnList) Get(name string) *Column
func (ColumnList) Index ¶
func (c ColumnList) Index(col string) int
func (ColumnList) Names ¶
func (c ColumnList) Names() []string
func (ColumnList) String ¶
func (c ColumnList) String() string
func (*ColumnList) UnmarshalJSON ¶
func (c *ColumnList) UnmarshalJSON(data []byte) (err error)
type ColumnResolver ¶
ColumnResolver is called for each row received in TableResolver's data fetch. execution holds all relevant information regarding execution as well as the Column called. resource holds the current row we are resolving the column for.
func ParentColumnResolver ¶
func ParentColumnResolver(name string) ColumnResolver
ParentColumnResolver resolves a column from the parent's table data, if name isn't set the column will be set to null
func PathResolver ¶
func PathResolver(path string) ColumnResolver
PathResolver resolves a field in the Resource.Item
Examples: PathResolver("Field") PathResolver("InnerStruct.Field") PathResolver("InnerStruct.InnerInnerStruct.Field")
type DefaultTransformer ¶
type DefaultTransformer struct { }
func (*DefaultTransformer) TransformBool ¶
func (*DefaultTransformer) TransformBool(v *Bool) any
func (*DefaultTransformer) TransformBytea ¶
func (*DefaultTransformer) TransformBytea(v *Bytea) any
func (*DefaultTransformer) TransformCIDR ¶
func (*DefaultTransformer) TransformCIDR(v *CIDR) any
func (*DefaultTransformer) TransformCIDRArray ¶
func (*DefaultTransformer) TransformCIDRArray(v *CIDRArray) any
func (*DefaultTransformer) TransformFloat8 ¶
func (*DefaultTransformer) TransformFloat8(v *Float8) any
func (*DefaultTransformer) TransformInet ¶
func (*DefaultTransformer) TransformInet(v *Inet) any
func (*DefaultTransformer) TransformInetArray ¶
func (*DefaultTransformer) TransformInetArray(v *InetArray) any
func (*DefaultTransformer) TransformInt8 ¶
func (*DefaultTransformer) TransformInt8(v *Int8) any
func (*DefaultTransformer) TransformInt8Array ¶
func (*DefaultTransformer) TransformInt8Array(v *Int8Array) any
func (*DefaultTransformer) TransformJSON ¶
func (*DefaultTransformer) TransformJSON(v *JSON) any
func (*DefaultTransformer) TransformMacaddr ¶
func (*DefaultTransformer) TransformMacaddr(v *Macaddr) any
func (*DefaultTransformer) TransformMacaddrArray ¶
func (*DefaultTransformer) TransformMacaddrArray(v *MacaddrArray) any
func (*DefaultTransformer) TransformText ¶
func (*DefaultTransformer) TransformText(v *Text) any
func (*DefaultTransformer) TransformTextArray ¶
func (*DefaultTransformer) TransformTextArray(v *TextArray) any
func (*DefaultTransformer) TransformTimestamptz ¶
func (*DefaultTransformer) TransformTimestamptz(v *Timestamptz) any
func (*DefaultTransformer) TransformUUID ¶
func (*DefaultTransformer) TransformUUID(v *UUID) any
func (*DefaultTransformer) TransformUUIDArray ¶
func (*DefaultTransformer) TransformUUIDArray(v *UUIDArray) any
type DestinationResource ¶
This struct is what we send over the wire to destination. We dont want to reuse the same struct as otherwise we will have to comment on fields which don't get sent over the wire but still accessible code wise
type FieldChange ¶
type FieldChange struct { Type TableColumnChangeType ColumnName string Current arrow.Field Previous arrow.Field }
func GetSchemaChanges ¶
func GetSchemaChanges(target *arrow.Schema, source *arrow.Schema) []FieldChange
Get changes return changes between two schemas
type Float8Transformer ¶
type Inet ¶
Inet represents both inet and cidr PostgreSQL types.
func (*Inet) UnmarshalJSON ¶
workaround this Golang bug: https://github.com/golang/go/issues/35727
type InetArray ¶
type InetArray struct { Elements []Inet Dimensions []ArrayDimension Status Status }
type InetArrayTransformer ¶
type InetTransformer ¶
type InfinityModifier ¶
type InfinityModifier int8
const ( Infinity InfinityModifier = 1 None InfinityModifier = 0 NegativeInfinity InfinityModifier = -Infinity )
type Int8Array ¶
type Int8Array struct { Elements []Int8 Dimensions []ArrayDimension Status Status }
type Int8ArrayTransformer ¶
type Int8Transformer ¶
type JSONTransformer ¶
type LengthTableValidator ¶
type LengthTableValidator struct{}
func (LengthTableValidator) Validate ¶
func (LengthTableValidator) Validate(t *Table) error
type Macaddr ¶
type Macaddr struct { Addr net.HardwareAddr Status Status }
type MacaddrArray ¶
type MacaddrArray struct { Elements []Macaddr Dimensions []ArrayDimension Status Status }
func (*MacaddrArray) Equal ¶
func (dst *MacaddrArray) Equal(src CQType) bool
func (MacaddrArray) Get ¶
func (dst MacaddrArray) Get() any
func (*MacaddrArray) GetStatus ¶
func (dst *MacaddrArray) GetStatus() Status
func (*MacaddrArray) Set ¶
func (dst *MacaddrArray) Set(src any) error
func (*MacaddrArray) Size ¶
func (dst *MacaddrArray) Size() int
func (*MacaddrArray) String ¶
func (dst *MacaddrArray) String() string
func (*MacaddrArray) Type ¶
func (*MacaddrArray) Type() ValueType
type MacaddrArrayTransformer ¶
type MacaddrArrayTransformer interface {
TransformMacaddrArray(*MacaddrArray) any
}
type MacaddrTransformer ¶
type MetadataFieldOptions ¶
type MetadataSchemaOptions ¶
type MetadataSchemaOptions struct {
TableName string
}
type Multiplexer ¶
type Multiplexer func(meta ClientMeta) []ClientMeta
type Resource ¶
type Resource struct { // Original resource item that wa from prior resolve Item any // Set if this is an embedded table Parent *Resource // internal fields Table *Table // contains filtered or unexported fields }
Resource represents a row in it's associated table, it carries a reference to the original item, and automatically generates an Id based on Table's Columns. Resource data can be accessed by the Get and Set methods
func (*Resource) CalculateCQID ¶
func (*Resource) Set ¶
Set sets a column with value. This does validation and conversion to one of concrete it returns an error just for backward compatibility and panics in case it fails
func (*Resource) SetItem ¶
Override original item (this is useful for apis that follow list/details pattern)
func (*Resource) ToDestinationResource ¶
func (r *Resource) ToDestinationResource() DestinationResource
type RowResolver ¶
type RowResolver func(ctx context.Context, meta ClientMeta, resource *Resource) error
type SyncSummary ¶
This is deprecated
type Table ¶
type Table struct { // Name of table Name string `json:"name"` // Title to be used in documentation (optional: will be generated from name if not set) Title string `json:"title"` // table description Description string `json:"description"` // Columns are the set of fields that are part of this table Columns ColumnList `json:"columns"` // Relations are a set of related tables defines Relations Tables `json:"relations"` // Transform Transform Transform `json:"-"` // Resolver is the main entry point to fetching table data and Resolver TableResolver `json:"-"` // Multiplex returns re-purposed meta clients. The sdk will execute the table with each of them Multiplex Multiplexer `json:"-"` // PostResourceResolver is called after all columns have been resolved, but before the Resource is sent to be inserted. The ordering of resolvers is: // (Table) Resolver → PreResourceResolver → ColumnResolvers → PostResourceResolver PostResourceResolver RowResolver `json:"-"` // PreResourceResolver is called before all columns are resolved but after Resource is created. The ordering of resolvers is: // (Table) Resolver → PreResourceResolver → ColumnResolvers → PostResourceResolver PreResourceResolver RowResolver `json:"-"` // IsIncremental is a flag that indicates if the table is incremental or not. This flag mainly affects how the table is // documented. IsIncremental bool // IgnoreInTests is used to exclude a table from integration tests. // By default, integration tests fetch all resources from cloudquery's test account, and verify all tables // have at least one row. // When IgnoreInTests is true, integration tests won't fetch from this table. // Used when it is hard to create a reproducible environment with a row in this table. IgnoreInTests bool `json:"ignore_in_tests"` // Parent is the parent table in case this table is called via parent table (i.e. relation) Parent *Table `json:"-"` PkConstraintName string `json:"pk_constraint_name"` }
func (*Table) GetChanges ¶
func (t *Table) GetChanges(old *Table) []TableColumnChange
Get Changes returns changes between two tables when t is the new one and old is the old one.
func (*Table) IncrementalKeys ¶
func (*Table) OverwriteOrAddColumn ¶
If the column with the same name exists, overwrites it. Otherwise, adds the column to the beginning of the table.
func (*Table) PrimaryKeys ¶
func (*Table) TableNames ¶
func (*Table) ToArrowSchema ¶
func (*Table) ValidateColumnNames ¶
func (*Table) ValidateDuplicateColumns ¶
func (*Table) ValidateName ¶
type TableColumnChange ¶
type TableColumnChange struct { Type TableColumnChangeType ColumnName string Current Column Previous Column }
func (TableColumnChange) String ¶
func (t TableColumnChange) String() string
type TableColumnChangeType ¶
type TableColumnChangeType int
const ( TableColumnChangeTypeUnknown TableColumnChangeType = iota TableColumnChangeTypeAdd TableColumnChangeTypeUpdate TableColumnChangeTypeRemove )
func (TableColumnChangeType) String ¶
func (t TableColumnChangeType) String() string
type TableResolver ¶
type TableResolver func(ctx context.Context, meta ClientMeta, parent *Resource, res chan<- any) error
TableResolver is the main entry point when a table is sync is called.
Table resolver has 3 main arguments: - meta(ClientMeta): is the client returned by the plugin.Provider Configure call - parent(Resource): resource is the parent resource in case this table is called via parent table (i.e. relation) - res(chan any): is a channel to pass results fetched by the TableResolver
type TableValidator ¶
type Tables ¶
type Tables []*Table
func (Tables) FilterDfsFunc ¶
func (Tables) FlattenTables ¶
func (Tables) GetTopLevel ¶
GetTopLevel returns a table by name. Only returns the table if it is in top-level list.
func (Tables) TableNames ¶
func (Tables) ToArrowSchemas ¶
func (Tables) ValidateColumnNames ¶
func (Tables) ValidateDuplicateColumns ¶
func (Tables) ValidateDuplicateTables ¶
func (Tables) ValidateTableNames ¶
type Text ¶
type TextArray ¶
type TextArray struct { Elements []Text Dimensions []ArrayDimension Status Status }
type TextArrayTransformer ¶
type TextTransformer ¶
type Timestamptz ¶
type Timestamptz struct { Time time.Time Status Status InfinityModifier InfinityModifier }
func (*Timestamptz) DecodeText ¶
func (dst *Timestamptz) DecodeText(src []byte) error
func (*Timestamptz) Equal ¶
func (dst *Timestamptz) Equal(src CQType) bool
func (Timestamptz) Get ¶
func (dst Timestamptz) Get() any
func (*Timestamptz) GetStatus ¶
func (dst *Timestamptz) GetStatus() Status
func (*Timestamptz) Set ¶
func (dst *Timestamptz) Set(src any) error
func (*Timestamptz) Size ¶
func (dst *Timestamptz) Size() int
func (*Timestamptz) String ¶
func (dst *Timestamptz) String() string
func (*Timestamptz) Type ¶
func (*Timestamptz) Type() ValueType
type TimestamptzTransformer ¶
type TimestamptzTransformer interface {
TransformTimestamptz(*Timestamptz) any
}
type UUIDArray ¶
type UUIDArray struct { Elements []UUID Dimensions []ArrayDimension Status Status }
type UUIDArrayTransformer ¶
type UUIDTransformer ¶
type ValidationError ¶
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) MaskedError ¶
func (e *ValidationError) MaskedError() string
this prints the error without the value
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
Source Files ¶
- array.go
- arrow.go
- bool.go
- bytea.go
- cidr.go
- cidr_array.go
- column.go
- convert.go
- doc.go
- errors.go
- float8.go
- inet.go
- inet_array.go
- int8.go
- int8_array.go
- json.go
- macaddr.go
- macaddr_array.go
- meta.go
- resolvers.go
- resource.go
- schemas.go
- table.go
- text.go
- text_array.go
- timestamptz.go
- transformer.go
- types.go
- uuid.go
- uuid_array.go
- validators.go