{"modulePath":"github.com/cloudquery/plugin-sdk/v4","version":"v4.100.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package schema\n\n## Constants\n\n```go\nconst (\n\tMetadataUnique              = \"cq:extension:unique\"\n\tMetadataPrimaryKey          = \"cq:extension:primary_key\"\n\tMetadataPrimaryKeyComponent = \"cq:extension:primary_key_component\"\n\tMetadataConstraintName      = \"cq:extension:constraint_name\"\n\tMetadataIncremental         = \"cq:extension:incremental\"\n\tMetadataTypeSchema          = \"cq:extension:type_schema\"\n\n\tMetadataTrue                   = \"true\"\n\tMetadataFalse                  = \"false\"\n\tMetadataTableName              = \"cq:table_name\"\n\tMetadataTableDescription       = \"cq:table_description\"\n\tMetadataTableTitle             = \"cq:table_title\"\n\tMetadataTableDependsOn         = \"cq:table_depends_on\"\n\tMetadataTableIsPaid            = \"cq:table_paid\"\n\tMetadataTablePermissionsNeeded = \"cq:table_permissions_needed\"\n\tMetadataTableSensitiveColumns  = \"cq:table_sensitive_columns\"\n)\n```\n\n## Variables\n\n```go\nvar CqClientIDColumn = Column{\n\tName:        \"_cq_client_id\",\n\tType:        arrow.BinaryTypes.String,\n\tDescription: \"Internal CQ ID of the multiplexed client\",\n\tNotNull:     true,\n}\n```\n\n```go\nvar CqIDColumn = Column{\n\tName:        \"_cq_id\",\n\tType:        types.ExtensionTypes.UUID,\n\tDescription: \"Internal CQ ID of the row\",\n\tNotNull:     true,\n\tUnique:      true,\n}\n```\nThese columns are managed and populated by the source plugins\n\n```go\nvar CqParentIDColumn = Column{\n\tName:          \"_cq_parent_id\",\n\tType:          types.ExtensionTypes.UUID,\n\tDescription:   \"Internal CQ ID of the parent row\",\n\tResolver:      parentCqUUIDResolver(),\n\tIgnoreInTests: true,\n}\n```\n\n```go\nvar CqSourceNameColumn = Column{\n\tName:        \"_cq_source_name\",\n\tType:        arrow.BinaryTypes.String,\n\tDescription: \"Internal CQ row that references the source plugin name data was retrieved\",\n}\n```\n\n```go\nvar CqSyncTimeColumn = Column{\n\tName:        \"_cq_sync_time\",\n\tType:        arrow.FixedWidthTypes.Timestamp_us,\n\tDescription: \"Internal CQ row of when sync was started (this will be the same for all rows in a single fetch)\",\n}\n```\nThese columns are managed and populated by the destination plugin.\n\n```go\nvar ErrUnableToCompare = errors.New(\"unable to compare\")\n```\n\n## Functions\n\n```go\nfunc AddCqClientID(t *Table)\n```\nAddCqClientID adds the cq\\_client\\_id column to the table, which is used to identify the multiplexed client that fetched the resource\n\n```go\nfunc AddCqIDs(table *Table)\n```\nAddCqIDs adds the cq\\_id and cq\\_parent\\_id columns to the table and all its relations set cq\\_id as primary key if no other primary keys\n\n```go\nfunc AddInternalColumnsToRecord(record arrow.RecordBatch, cqClientIDValue string) (arrow.RecordBatch, error)\n```\n\n```go\nfunc CqIDAsPK(t *Table)\n```\nCqIDAsPK sets the cq\\_id column as primary key if it exists and removes the primary key from all other columns\n\n```go\nfunc FindEmptyColumns(table *Table, records []arrow.RecordBatch) []string\n```\n\n```go\nfunc FindNotMatchingSensitiveColumns(table *Table) (nonMatchingColumns []string, nonMatchingJSONColumns []string)\n```\n\n```go\nfunc GetChangesSummary(tablesChanges map[string][]TableColumnChange) string\n```\n\n```go\nfunc GetColumnChangeSummary(change TableColumnChange) string\n```\n\n```go\nfunc ReplaceFieldInRecord(src arrow.RecordBatch, fieldName string, field arrow.Array) (record arrow.RecordBatch, err error)\n```\n\n```go\nfunc StringArrayFromValue(value string, nRows int) arrow.Array\n```\n\n```go\nfunc SyntheticRecords(oldField, newField arrow.Field, pairs []SyntheticPair) (oldRecord, newRecord arrow.RecordBatch, err error)\n```\nSyntheticRecords builds one-column records for the old and the new field, with one row per pair.\n\n```go\nfunc TimestampArrayFromTime(t time.Time, unit arrow.TimeUnit, timeZone string, nRows int) (arrow.Array, error)\n```\n\n```go\nfunc ValidColumnName(name string) bool\n```\n\n## Types\n\n```go\ntype ClientMeta interface {\n\tID() string\n}\n```\n\n```go\ntype Column struct {\n\t// Name of column\n\tName string `json:\"name\"`\n\t// Value Type of column i.e String, UUID etc'\n\tType arrow.DataType `json:\"type\"`\n\t// Description about column, this description is added as a comment in the database\n\tDescription string `json:\"description\"`\n\t// Column Resolver allows to set your own data for a column; this can be an API call, setting multiple embedded values, etc\n\tResolver ColumnResolver `json:\"-\"`\n\n\t// IgnoreInTests is used to skip verifying the column is non-nil in integration tests.\n\t// By default, integration tests perform a fetch for all resources in cloudquery's test account, and\n\t// verify all columns are non-nil.\n\t// If IgnoreInTests is true, verification is skipped for this column.\n\t// Used when it is hard to create a reproducible environment with this column being non-nil (e.g. various error columns).\n\tIgnoreInTests bool `json:\"-\"`\n\n\t// PrimaryKey requires the destinations supporting this to include this column into the primary key\n\tPrimaryKey bool `json:\"primary_key\"`\n\t// NotNull requires the destinations supporting this to mark this column as non-nullable\n\tNotNull bool `json:\"not_null\"`\n\t// IncrementalKey is a flag that indicates if the column is used as part of an incremental key.\n\t// It is mainly used for documentation purposes, but may also be used as part of ensuring that\n\t// migrations are done correctly.\n\tIncrementalKey bool `json:\"incremental_key\"`\n\t// Unique requires the destinations supporting this to mark this column as unique\n\tUnique bool `json:\"unique\"`\n\n\t// PrimaryKeyComponent is a flag that indicates if the column is used as part of the input to calculate the value of `_cq_id`.\n\tPrimaryKeyComponent bool `json:\"primary_key_component\"`\n\n\t// If the column type is JSON, this field will have a JSON string that represents the schema of the JSON object.\n\tTypeSchema string `json:\"type_schema,omitempty\"`\n\n\t// Some PK columns can be nullable if there are a part of a composite PK, so we want to skip validation for them.\n\tSkipPKValidation bool `json:\"skip_pk_validation\"`\n}\n```\nColumn definition for Table\n\n```go\nfunc NewColumnFromArrowField(f arrow.Field) Column\n```\nNewColumnFromArrowField creates a new Column from an arrow.Field arrow.Field is a low-level representation of a CloudQuery column that can be sent over the wire in a cross-language way.\n\n```go\nfunc (c Column) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (c Column) String() string\n```\n\n```go\nfunc (c Column) ToArrowField() arrow.Field\n```\n\n```go\ntype ColumnList []Column\n```\n\n```go\nfunc (c ColumnList) Get(name string) *Column\n```\n\n```go\nfunc (c ColumnList) Index(col string) int\n```\n\n```go\nfunc (c ColumnList) Names() []string\n```\n\n```go\nfunc (c ColumnList) String() string\n```\n\n```go\ntype ColumnResolver func(ctx context.Context, meta ClientMeta, resource *Resource, c Column) error\n```\nColumnResolver 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.\n\n```go\nfunc ParentColumnResolver(name string) ColumnResolver\n```\nParentColumnResolver resolves a column from the parent's table data, if name isn't set the column will be set to null\n\n```go\nfunc PathResolver(path string) ColumnResolver\n```\nPathResolver resolves a field in the Resource.Item\n\nExamples: PathResolver(\"Field\") PathResolver(\"InnerStruct.Field\") PathResolver(\"InnerStruct.InnerInnerStruct.Field\")\n\n```go\ntype ErrorClassifier func(ctx context.Context, err error, event ErrorEvent) bool\n```\nErrorClassifier reports whether a resolver error should be suppressed rather than raised. Suppressed errors are logged at debug level and are not counted in error metrics or emitted as a SyncError message. A nil ErrorClassifier raises every error. It is not consulted for primary key calculation or validation errors. The classifier may be invoked concurrently; implementations must be safe for concurrent use.\n\n```go\nfunc (c ErrorClassifier) Suppress(ctx context.Context, err error, event ErrorEvent) bool\n```\nSuppress is a nil-safe call: a nil ErrorClassifier returns false.\n\n```go\ntype ErrorEvent struct {\n\tTable  *Table\n\tClient ClientMeta\n\tPhase  ErrorPhase\n\t// Column is set only when Phase == ErrorPhaseColumnResolver.\n\tColumn *Column\n}\n```\nErrorEvent describes the context in which a resolver error occurred.\n\n```go\ntype ErrorPhase int\n```\nErrorPhase identifies the resolver stage that produced an error.\n\n```go\nconst (\n\tErrorPhaseTableResolver ErrorPhase = iota\n\tErrorPhasePreResourceChunkResolver\n\tErrorPhasePreResourceResolver\n\tErrorPhaseColumnResolver\n\tErrorPhasePostResourceResolver\n)\n```\n\n```go\nfunc (p ErrorPhase) String() string\n```\n\n```go\ntype GenTestDataOptions struct {\n\t// SourceName is the name of the source to set in the source_name column.\n\tSourceName string\n\t// SyncTime is the time to set in the sync_time column.\n\tSyncTime time.Time\n\t// MaxRows is the number of rows to generate.\n\tMaxRows int\n\t// StableTime is the time to use for all rows other than sync time. If set to time.Time{}, a new time will be generated\n\tStableTime time.Time\n\t// TimePrecision is the precision to use for time columns.\n\tTimePrecision time.Duration\n\t// NullRows indicates whether to generate rows with all null values.\n\tNullRows bool\n\t// UseHomogeneousType indicates whether to use a single type for JSON arrays.\n\tUseHomogeneousType bool\n}\n```\nGenTestDataOptions are options for generating test data\n\n```go\ntype Multiplexer func(meta ClientMeta) []ClientMeta\n```\n\n```go\ntype PKComponentError struct {\n\tMissingPKComponents []string\n}\n```\n\n```go\nfunc (e *PKComponentError) Error() string\n```\n\n```go\ntype PKError struct {\n\tMissingPKs []string\n}\n```\n\n```go\nfunc (e *PKError) Error() string\n```\n\n```go\ntype PatternMatchError struct {\n\tKey     string // \"tables\" or \"skip_tables\"\n\tPattern string // the glob pattern that had no matches\n}\n```\nPatternMatchError is returned by Tables.FilterDfs when a tables or skip\\_tables pattern does not match any known table.\n\n```go\nfunc (e *PatternMatchError) Error() string\n```\n\n```go\ntype Resource struct {\n\t// Original resource item that wa from prior resolve\n\tItem any\n\t// Set if this is an embedded table\n\tParent *Resource\n\t// internal fields\n\tTable *Table\n\t// contains filtered or unexported fields\n}\n```\nResource 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\n\n```go\nfunc NewResourceData(t *Table, parent *Resource, item any) *Resource\n```\n\n```go\nfunc (r *Resource) CalculateCQID(deterministicCQID bool) error\n```\n\n```go\nfunc (r *Resource) Get(columnName string) scalar.Scalar\n```\n\n```go\nfunc (r *Resource) GetItem() any\n```\n\n```go\nfunc (r *Resource) GetValues() scalar.Vector\n```\n\n```go\nfunc (r *Resource) Set(columnName string, value any) error\n```\nSet 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\n\n```go\nfunc (r *Resource) SetItem(item any)\n```\nOverride original item (this is useful for apis that follow list/details pattern)\n\n```go\nfunc (r *Resource) StoreCQClientID(clientID string) error\n```\n\n```go\nfunc (r *Resource) Validate() error\n```\nValidates that all primary keys have values.\n\n```go\ntype Resources []*Resource\n```\n\n```go\nfunc (rr Resources) ColumnNames() []string\n```\n\n```go\nfunc (rr Resources) TableName() string\n```\n\n```go\ntype RowResolver func(ctx context.Context, meta ClientMeta, resource *Resource) error\n```\n\n```go\ntype RowsChunkResolver struct {\n\tChunkSize    int\n\tRowsResolver func(ctx context.Context, meta ClientMeta, resourcesChunk []*Resource) error\n}\n```\nEXPERIMENTAL: RowsChunkResolver API might change in future versions of the SDK\n\n```go\ntype Schemas []*arrow.Schema\n```\n\n```go\nfunc (s Schemas) Len() int\n```\n\n```go\nfunc (s Schemas) SchemaByName(name string) *arrow.Schema\n```\n\n```go\ntype SyntheticCase string\n```\n\n```go\nconst (\n\tSyntheticCasePopulated       SyntheticCase = \"populated\"\n\tSyntheticCaseNull            SyntheticCase = \"null\"\n\tSyntheticCaseEmptyCollection SyntheticCase = \"empty collection\"\n\tSyntheticCaseNested          SyntheticCase = \"nested\"\n\tSyntheticCaseEscaping        SyntheticCase = \"escaping\"\n)\n```\n\n```go\ntype SyntheticPair struct {\n\tCase  SyntheticCase\n\tValue string\n}\n```\nSyntheticPair is a value that means the same under the old and the new field. Value is its Arrow JSON form, which both fields accept and read back as equal values.\n\n```go\nfunc SyntheticPairs(oldField, newField arrow.Field) ([]SyntheticPair, error)\n```\nSyntheticPairs returns equivalent values for each case both fields support. It returns ErrUnableToCompare when no populated value means the same under both fields.\n\n```go\ntype Table struct {\n\t// Name of table\n\tName string `json:\"name\"`\n\t// Title to be used in documentation (optional: will be generated from name if not set)\n\tTitle string `json:\"title\"`\n\t// table description\n\tDescription string `json:\"description\"`\n\t// List of permissions needed to access this table, if any. For example [\"Microsoft.Network/dnsZones/read\"] or [\"storage.buckets.list\"]\n\tPermissionsNeeded []string `json:\"permissions_needed\"`\n\t// List of columns that may contain sensitive or secret data\n\tSensitiveColumns []string `json:\"sensitive_columns\"`\n\t// Columns are the set of fields that are part of this table\n\tColumns ColumnList `json:\"columns\"`\n\t// Relations are a set of related tables defines\n\tRelations Tables `json:\"relations\"`\n\t// Transform\n\tTransform Transform `json:\"-\"`\n\t// Resolver is the main entry point to fetching table data and\n\tResolver TableResolver `json:\"-\"`\n\t// Multiplex returns re-purposed meta clients. The sdk will execute the table with each of them\n\tMultiplex Multiplexer `json:\"-\"`\n\t// PostResourceResolver is called after all columns have been resolved, but before the Resource is sent to be inserted. The ordering of resolvers is:\n\t//  (Table) Resolver → PreResourceResolver → ColumnResolvers → PostResourceResolver\n\tPostResourceResolver RowResolver `json:\"-\"`\n\t// PreResourceResolver is called before all columns are resolved but after Resource is created. The ordering of resolvers is:\n\t//  (Table) Resolver → PreResourceResolver → ColumnResolvers → PostResourceResolver\n\tPreResourceResolver RowResolver `json:\"-\"`\n\n\tPreResourceChunkResolver *RowsChunkResolver `json:\"-\"`\n\n\t// IsIncremental is a flag that indicates if the table is incremental or not. This flag mainly affects how the table is\n\t// documented.\n\tIsIncremental bool `json:\"is_incremental\"`\n\n\t// IgnoreInTests is used to exclude a table from integration tests.\n\t// By default, integration tests fetch all resources from cloudquery's test account, and verify all tables\n\t// have at least one row.\n\t// When IgnoreInTests is true, integration tests won't fetch from this table.\n\t// Used when it is hard to create a reproducible environment with a row in this table.\n\tIgnoreInTests bool `json:\"-\"`\n\n\t// Parent is the parent table in case this table is called via parent table (i.e. relation)\n\tParent *Table `json:\"-\"`\n\n\tPkConstraintName string `json:\"pk_constraint_name\"`\n\n\t// IsPaid indicates whether this table is a paid (premium) table.\n\t// This relates to the CloudQuery plugin itself, and should not be confused\n\t// with whether the table makes use of a paid API or not.\n\tIsPaid bool `json:\"is_paid\"`\n\n\t// IgnorePKComponentsMismatchValidation is a flag that indicates if the table should skip validating usage of both primary key components and primary keys\n\tIgnorePKComponentsMismatchValidation bool `json:\"ignore_pk_components_mismatch_validation\"`\n}\n```\n\n```go\nfunc NewTableFromArrowSchema(sc *arrow.Schema) (*Table, error)\n```\nNewTableFromArrowSchema creates a CloudQuery Table abstraction from an Arrow schema. The Arrow schema is a low level representation of a table that can be sent over the wire in a cross-language way.\n\n```go\nfunc TestTable(name string, opts TestSourceOptions) *Table\n```\n\n```go\nfunc (t *Table) Column(name string) *Column\n```\n\n```go\nfunc (t *Table) Copy(parent *Table) *Table\n```\n\n```go\nfunc (t *Table) GetChanges(old *Table) []TableColumnChange\n```\nGetChanges returns changes between two tables when t is the new one and old is the old one.\n\n```go\nfunc (t *Table) IncrementalKeys() []string\n```\n\n```go\nfunc (t *Table) OverwriteOrAddColumn(column *Column)\n```\nOverwriteOrAddColumn overwrites or adds columns. If the column with the same name exists, overwrites it. Otherwise, adds the column to the beginning of the table.\n\n```go\nfunc (t *Table) PrimaryKeyComponents() []string\n```\n\n```go\nfunc (t *Table) PrimaryKeys() []string\n```\n\n```go\nfunc (t *Table) PrimaryKeysIndexes() []int\n```\n\n```go\nfunc (t *Table) TableNames() []string\n```\n\n```go\nfunc (t *Table) ToArrowSchema() *arrow.Schema\n```\n\n```go\nfunc (t *Table) ValidateDuplicateColumns() error\n```\n\n```go\ntype TableColumnChange struct {\n\tType       TableColumnChangeType\n\tColumnName string\n\tCurrent    Column\n\tPrevious   Column\n}\n```\n\n```go\nfunc (t TableColumnChange) String() string\n```\n\n```go\ntype TableColumnChangeType int\n```\n\n```go\nconst (\n\tTableColumnChangeTypeUnknown TableColumnChangeType = iota\n\tTableColumnChangeTypeAdd\n\tTableColumnChangeTypeUpdate\n\tTableColumnChangeTypeRemove\n\t// These are special cases to help users migrate\n\t// As we remove unique constraints on _cq_id columns this will give destination plugins the ability to auto migrate\n\tTableColumnChangeTypeRemoveUniqueConstraint\n\t// Moving from composite pks to singular PK on _cq_id this will give destination plugins the ability to auto migrate\n\tTableColumnChangeTypeMoveToCQOnly\n)\n```\n\n```go\nfunc (t TableColumnChangeType) String() string\n```\n\n```go\ntype TableResolver func(ctx context.Context, meta ClientMeta, parent *Resource, res chan\u003c- any) error\n```\nTableResolver is the main entry point when a table is sync is called.\n\nTable 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\n\n```go\ntype Tables []*Table\n```\n\n```go\nfunc NewTablesFromArrowSchemas(schemas []*arrow.Schema) (Tables, error)\n```\n\n```go\nfunc (tt Tables) FilterDfs(tables, skipTables []string, skipDependentTables bool) (Tables, error)\n```\n\n```go\nfunc (tt Tables) FilterDfsFunc(include, exclude func(*Table) bool, skipDependentTables bool) Tables\n```\n\n```go\nfunc (tt Tables) FlattenTables() Tables\n```\n\n```go\nfunc (tt Tables) Get(name string) *Table\n```\nGet returns a table by name. Returns top-level tables and relations.\n\n```go\nfunc (tt Tables) GetPaidTables() Tables\n```\n\n```go\nfunc (tt Tables) GetTopLevel(name string) *Table\n```\nGetTopLevel returns a table by name. Only returns the table if it is in top-level list.\n\n```go\nfunc (tt Tables) HasPaidTables() bool\n```\n\n```go\nfunc (tt Tables) TableNames() []string\n```\n\n```go\nfunc (tt Tables) ToArrowSchemas() Schemas\n```\n\n```go\nfunc (tt Tables) UnflattenTables() (Tables, error)\n```\nUnflattenTables returns a new Tables copy with the relations unflattened. This is the opposite operation of FlattenTables.\n\n```go\nfunc (tt Tables) ValidateDuplicateColumns() error\n```\n\n```go\nfunc (tt Tables) ValidateDuplicateTables() error\n```\n\n```go\ntype TestDataGenerator struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewTestDataGenerator(randomSeed uint64) *TestDataGenerator\n```\n\n```go\nfunc (tg *TestDataGenerator) Generate(table *Table, opts GenTestDataOptions) arrow.RecordBatch\n```\nGenerate will produce a single arrow.RecordBatch with the given schema and options.\n\n```go\nfunc (tg *TestDataGenerator) Reset()\n```\n\n```go\ntype TestSourceOptions struct {\n\tSkipDates      bool\n\tSkipDurations  bool\n\tSkipIntervals  bool\n\tSkipLargeTypes bool // e.g. large binary, large string\n\tSkipLists      bool // lists of all primitive types. Lists that were supported by CQTypes are always included.\n\tSkipMaps       bool\n\tSkipStructs    bool\n\tSkipTimes      bool // time of day types\n\tSkipTimestamps bool // timestamp types. Microsecond timestamp is always be included, regardless of this setting.\n\tTimePrecision  time.Duration\n\tSkipDecimals   bool\n}\n```\nTestSourceOptions controls which types are included by TestSourceColumns.\n\n```go\ntype Transform func(table *Table) error\n```\n\n```go\ntype ValidationError struct {\n\tErr   error\n\tMsg   string\n\tType  arrow.DataType\n\tValue any\n}\n```\n\n```go\nfunc (e *ValidationError) Error() string\n```\n\n```go\nfunc (e *ValidationError) MaskedError() string\n```\nthis prints the error without the value\n\n```go\nfunc (e *ValidationError) Unwrap() error\n```\n\n","path":"github.com/cloudquery/plugin-sdk/v4/schema","name":"schema","synopsis":"","isRedistributable":true}
