Documentation ¶
Index ¶
- Constants
- Variables
- func AutoGenerateTag(existingTags *set.Uint64Set, tableName string, ...) uint64
- func ColCollsAreEqual(cc1, cc2 *ColCollection) bool
- func ColConstraintsAreEqual(a, b []ColConstraint) bool
- func ErrTagPrevUsed(tag uint64, newColName, tableName string) error
- func ExtractAllColNames(sch Schema) (map[uint64]string, error)
- func IndexOfConstraint(constraints []ColConstraint, constraintType string) int
- func NomsKindsFromSchema(sch Schema) []types.NomsKind
- func SchemasAreEqual(sch1, sch2 Schema) (bool, error)
- func ValidateForInsert(allCols *ColCollection) error
- func VerifyInSchema(inSch, outSch Schema) (bool, error)
- type ColCollection
- func ColCollUnion(colColls ...*ColCollection) (*ColCollection, error)
- func ColCollectionSetDifference(leftCC, rightCC *ColCollection) (d *ColCollection)
- func FilterColCollection(cc *ColCollection, cb func(col Column) (bool, error)) (*ColCollection, error)
- func MapColCollection(cc *ColCollection, cb func(col Column) (Column, error)) (*ColCollection, error)
- func NewColCollection(cols ...Column) (*ColCollection, error)
- func (cc *ColCollection) Append(cols ...Column) (*ColCollection, error)
- func (cc *ColCollection) AppendColl(colColl *ColCollection) (*ColCollection, error)
- func (cc *ColCollection) GetByIndex(idx int) Column
- func (cc *ColCollection) GetByName(name string) (Column, bool)
- func (cc *ColCollection) GetByNameCaseInsensitive(name string) (Column, bool)
- func (cc *ColCollection) GetByTag(tag uint64) (Column, bool)
- func (cc *ColCollection) GetColumnNames() []string
- func (cc *ColCollection) GetColumns() []Column
- func (cc *ColCollection) Iter(cb func(tag uint64, col Column) (stop bool, err error)) error
- func (cc *ColCollection) IterInSortedOrder(cb func(tag uint64, col Column) (stop bool))
- func (cc *ColCollection) Replace(old, new Column) (*ColCollection, error)
- func (cc *ColCollection) Size() int
- type ColConstraint
- type Column
- func ColFromName(sch Schema, name string) (Column, bool)
- func ColFromTag(sch Schema, tag uint64) (Column, bool)
- func NewColumn(name string, tag uint64, kind types.NomsKind, partOfPK bool, ...) Column
- func NewColumnWithTypeInfo(name string, tag uint64, typeInfo typeinfo.TypeInfo, partOfPK bool, ...) (Column, error)
- type Index
- type IndexCollection
- type IndexProperties
- type NotNullConstraint
- type Schema
- type SuperSchema
- func (ss *SuperSchema) AddColumn(col Column) (err error)
- func (ss *SuperSchema) AddSchemas(schemas ...Schema) error
- func (ss *SuperSchema) AllColumnNames(tag uint64) []string
- func (ss *SuperSchema) AllTags() []uint64
- func (ss *SuperSchema) Equals(oss *SuperSchema) bool
- func (ss *SuperSchema) GenerateColCollection() (*ColCollection, error)
- func (ss *SuperSchema) GenerateSchema() (Schema, error)
- func (ss *SuperSchema) GetByTag(tag uint64) (Column, bool)
- func (ss *SuperSchema) Iter(cb func(tag uint64, col Column) (stop bool, err error)) error
- func (ss *SuperSchema) LatestColumnName(tag uint64) string
- func (ss *SuperSchema) NameMapForSchema(sch Schema) (map[string]string, error)
- func (ss *SuperSchema) RebaseTag(tagMapping map[uint64]uint64) (*SuperSchema, error)
- func (ss *SuperSchema) Size() int
Constants ¶
const InvalidTag uint64 = math.MaxUint64
InvalidTag is used as an invalid tag
const (
NotNullConstraintType = "not_null"
)
const ( // ReservedTagMin is the start of a range of tags which the user should not be able to use in their schemas. ReservedTagMin uint64 = 1 << 50 )
Variables ¶
var ( // KindToLwrStr maps a noms kind to the kinds lowercased name KindToLwrStr = make(map[types.NomsKind]string) // LwrStrToKind maps a lowercase string to the noms kind it is referring to LwrStrToKind = make(map[string]types.NomsKind) )
var EmptyColColl = &ColCollection{ []Column{}, []uint64{}, []uint64{}, map[uint64]Column{}, map[string]Column{}, map[string]Column{}, }
var EmptySchema = &schemaImpl{ pkCols: EmptyColColl, nonPKCols: EmptyColColl, allCols: EmptyColColl, indexCollection: NewIndexCollection(nil), }
EmptySchema is an instance of a schema with no columns.
var ErrColNameCollision = errors.New("two different columns with the same name exist")
ErrColNameCollision is an error that is returned when two columns within a ColCollection have the same name but a different type or tag
var ErrColNotFound = errors.New("column not found")
ErrColNotFound is an error that is returned when attempting an operation on a column that does not exist
var ErrColTagCollision = errors.New("two different columns with the same tag")
ErrColTagCollision is an error that is returned when two columns within a ColCollection have the same tag but a different name or type
var ErrNoPrimaryKeyColumns = errors.New("no primary key columns")
ErrNoPrimaryKeyColumns is an error that is returned when wo
var ( // InvalidCol is a Column instance that is returned when there is nothing to return and can be tested against. InvalidCol = Column{ "invalid", InvalidTag, types.NullKind, false, typeinfo.UnknownType, "", "", nil, } )
Functions ¶
func AutoGenerateTag ¶
func AutoGenerateTag(existingTags *set.Uint64Set, tableName string, existingColKinds []types.NomsKind, newColName string, newColKind types.NomsKind) uint64
AutoGenerateTag generates a random tag that doesn't exist in the provided SuperSchema. It uses a deterministic random number generator that is seeded with the NomsKinds of any existing columns in the schema and the NomsKind of the column being added to the schema. Deterministic tag generation means that branches and repositories that perform the same sequence of mutations to a database will get equivalent databases as a result. DETERMINISTIC MUTATION IS A CRITICAL INVARIANT TO MAINTAINING COMPATIBILITY BETWEEN REPOSITORIES. DO NOT ALTER THIS METHOD.
func ColCollsAreEqual ¶
func ColCollsAreEqual(cc1, cc2 *ColCollection) bool
ColCollsAreEqual determines whether two ColCollections are equal.
func ColConstraintsAreEqual ¶
func ColConstraintsAreEqual(a, b []ColConstraint) bool
ColConstraintsAreEqual validates two ColConstraint slices are identical.
func ErrTagPrevUsed ¶
func ExtractAllColNames ¶
ExtractAllColNames returns a map of tag to column name, with one map entry for every column in the schema.
func IndexOfConstraint ¶
func IndexOfConstraint(constraints []ColConstraint, constraintType string) int
IndexOfConstraint returns the index in the supplied slice of the first constraint of matching type. If none are found then -1 is returned
func NomsKindsFromSchema ¶
func SchemasAreEqual ¶
TODO: this function never returns an error SchemasAreEqual tests equality of two schemas.
func ValidateForInsert ¶
func ValidateForInsert(allCols *ColCollection) error
ValidateForInsert returns an error if the given schema cannot be written to the dolt database.
func VerifyInSchema ¶
TODO: this function never returns an error VerifyInSchema tests that the incoming schema matches the schema from the original table based on the presence of the column name in the original schema.
Types ¶
type ColCollection ¶
type ColCollection struct { // Tags is a list of all the tags in the ColCollection in their original order. Tags []uint64 // SortedTags is a list of all the tags in the ColCollection in sorted order. SortedTags []uint64 // TagToCol is a map of tag to column TagToCol map[uint64]Column // NameToCol is a map from name to column NameToCol map[string]Column // LowerNameToCol is a map from lower-cased name to column LowerNameToCol map[string]Column // contains filtered or unexported fields }
ColCollection is a collection of columns. As a stand-alone collection, all columns in the collection must have unique tags. To be instantiated as a schema for writing to the database, names must also be unique. See schema.ValidateForInsert for details.
func ColCollUnion ¶
func ColCollUnion(colColls ...*ColCollection) (*ColCollection, error)
func ColCollectionSetDifference ¶
func ColCollectionSetDifference(leftCC, rightCC *ColCollection) (d *ColCollection)
ColCollectionSetDifference returns the set difference leftCC - rightCC.
func FilterColCollection ¶
func FilterColCollection(cc *ColCollection, cb func(col Column) (bool, error)) (*ColCollection, error)
FilterColCollection applies a boolean function to column in a ColCollection, it creates a new ColCollection from the set of columns for which the function returned true.
func MapColCollection ¶
func MapColCollection(cc *ColCollection, cb func(col Column) (Column, error)) (*ColCollection, error)
MapColCollection applies a function to each column in a ColCollection and creates a new ColCollection from the results.
func NewColCollection ¶
func NewColCollection(cols ...Column) (*ColCollection, error)
NewColCollection creates a new collection from a list of columns. All columns must have unique tags or this method returns an error. If any columns have the same name, by-name lookups from this collection will not function correctly, and this column collection cannot be used to create a schema. If any columns have the same case- insensitive name, case-insensitive lookups will be unable to return the correct column in all cases.
func (*ColCollection) Append ¶
func (cc *ColCollection) Append(cols ...Column) (*ColCollection, error)
Append returns a new collection with the additional columns appended
func (*ColCollection) AppendColl ¶
func (cc *ColCollection) AppendColl(colColl *ColCollection) (*ColCollection, error)
AppendColl returns a new collection with the additional ColCollection's columns appended
func (*ColCollection) GetByIndex ¶
func (cc *ColCollection) GetByIndex(idx int) Column
GetByIndex returns a column with a given index
func (*ColCollection) GetByName ¶
func (cc *ColCollection) GetByName(name string) (Column, bool)
GetByName takes the name of a column and returns the column and true if found. Otherwise InvalidCol and false are returned.
func (*ColCollection) GetByNameCaseInsensitive ¶
func (cc *ColCollection) GetByNameCaseInsensitive(name string) (Column, bool)
GetByNameCaseInensitive takes the name of a column and returns the column and true if there is a column with that name ignoring case. Otherwise InvalidCol and false are returned. If multiple columns have the same case-insensitive name, the first declared one is returned.
func (*ColCollection) GetByTag ¶
func (cc *ColCollection) GetByTag(tag uint64) (Column, bool)
GetByTag takes a tag and returns the corresponding column and true if found, otherwise InvalidCol and false are returned
func (*ColCollection) GetColumnNames ¶
func (cc *ColCollection) GetColumnNames() []string
GetColumnNames returns a list of names of the columns.
func (*ColCollection) GetColumns ¶
func (cc *ColCollection) GetColumns() []Column
GetColumns returns the underlying list of columns. The list returned is a copy.
func (*ColCollection) IterInSortedOrder ¶
func (cc *ColCollection) IterInSortedOrder(cb func(tag uint64, col Column) (stop bool))
IterInSortOrder iterates over all the columns from lowest tag to highest tag.
func (*ColCollection) Replace ¶
func (cc *ColCollection) Replace(old, new Column) (*ColCollection, error)
Replace will replace one column of the schema with another.
func (*ColCollection) Size ¶
func (cc *ColCollection) Size() int
Size returns the number of columns in the collection.
type ColConstraint ¶
type ColConstraint interface { // SatisfiesConstraint takes in a value and returns true if the value satisfies the constraint SatisfiesConstraint(value types.Value) bool // GetConstraintType returns a string representation of the type of constraint. This is used for serialization and // deserialization of constraints (see ColConstraintFromTypeAndParams). GetConstraintType() string // GetConstraintParams returns a map[string]string containing the constraints parameters. This is used for // serialization and deserialization of constraints, and a deserialized constraint must be able to reproduce the same // behavior based on the parameters in this map (See ColConstraintFromTypeAndParams). GetConstraintParams() map[string]string // Stringer results are used to inform users of the constraint's properties. fmt.Stringer }
ColConstraint is an interface used for evaluating whether a columns value is valid
func ColConstraintFromTypeAndParams ¶
func ColConstraintFromTypeAndParams(colCnstType string, params map[string]string) ColConstraint
ColConstraintFromTypeAndParams takes in a string representing the type of the constraint and a map of parameters that can be used to determine the behavior of the constraint. An example might be a constraint which validated a value is in a given range. For this the constraint type might by "in_range_constraint", and the parameters might be {"min": -10, "max": 10}
type Column ¶
type Column struct { // Name is the name of the column Name string // Tag should be unique per versioned schema and allows Tag uint64 // Kind is the types.NomsKind that values of this column will be Kind types.NomsKind // IsPartOfPK says whether this column is part of the primary key IsPartOfPK bool // TypeInfo states the type of this column. TypeInfo typeinfo.TypeInfo // Default is the default value of this column. This is the string representation of a sql.Expression. Default string // Comment is the comment for this column. Comment string // Constraints are rules that can be checked on each column to say if the columns value is valid Constraints []ColConstraint }
Column is a structure containing information about a column in a row in a table.
func ColFromName ¶
ColFromName returns a schema.Column from a schema from it's name
func ColFromTag ¶
ColFromTag returns a schema.Column from a schema and a tag
func NewColumn ¶
func NewColumn(name string, tag uint64, kind types.NomsKind, partOfPK bool, constraints ...ColConstraint) Column
NewColumn creates a Column instance with the default type info for the NomsKind
func NewColumnWithTypeInfo ¶
func NewColumnWithTypeInfo(name string, tag uint64, typeInfo typeinfo.TypeInfo, partOfPK bool, defaultVal, comment string, constraints ...ColConstraint) (Column, error)
NewColumnWithTypeInfo creates a Column instance with the given type info.
func (Column) IsNullable ¶
IsNullable returns whether the column can be set to a null value.
func (Column) KindString ¶
KindString returns the string representation of the NomsKind stored in the column.
type Index ¶
type Index interface { // AllTags returns the tags of the columns in the entire index, including the primary keys. // If we imagined a dolt index as being a standard dolt table, then the tags would represent the schema columns. AllTags() []uint64 // ColumnNames returns the names of the columns in the index. ColumnNames() []string // Comment returns the comment that was provided upon index creation. Comment() string // Count returns the number of indexed columns in this index. Count() int // Equals returns whether this Index is equivalent to another. This does not check for column names, thus those may // be renamed and the index equivalence will be preserved. It also does not depend on the table's primary keys. Equals(other Index) bool // GetColumn returns the column for the given tag and whether the column was found or not. GetColumn(tag uint64) (Column, bool) // IndexedColumnTags returns the tags of the columns in the index. IndexedColumnTags() []uint64 // IsHidden returns whether the index is hidden and managed internally, such as for a foreign key. Such indexes do // not cause column nor tag collisions with other indexes. IsUnique() bool // Name returns the name of the index. Name() string // PrimaryKeyTags returns the primary keys of the indexed table, in the order that they're stored for that table. PrimaryKeyTags() []uint64 // Schema returns the schema for the internal index map. Can be used for table operations. Schema() Schema }
type IndexCollection ¶
type IndexCollection interface { // AddIndex adds the given index, overwriting any current indexes with the same name or columns. // It does not perform any kind of checking, and is intended for schema modifications. AddIndex(indexes ...Index) // AddIndexByColNames adds an index with the given name and columns (in index order). AddIndexByColNames(indexName string, cols []string, props IndexProperties) (Index, error) // AddIndexByColTags adds an index with the given name and column tags (in index order). AddIndexByColTags(indexName string, tags []uint64, props IndexProperties) (Index, error) // todo: this method is trash, clean up this interface UnsafeAddIndexByColTags(indexName string, tags []uint64, props IndexProperties) (Index, error) // AllIndexes returns a slice containing all of the indexes in this collection. AllIndexes() []Index // Contains returns whether the given index name already exists for this table. Contains(indexName string) bool // Count returns the number of indexes in this collection. Count() int // Equals returns whether this index collection is equivalent to another. Indexes are compared by everything except // for their name, the names of all columns, and anything relating to the parent table's primary keys. Equals(other IndexCollection) bool // GetByName returns the index with the given name, or nil if it does not exist. GetByName(indexName string) Index // GetByName returns the index with a matching case-insensitive name, the bool return value indicates if a match was found. GetByNameCaseInsensitive(indexName string) (Index, bool) // GetIndexByTags returns whether the collection contains an index that has this exact collection and ordering of columns. // Any hidden indexes are ignored. GetIndexByTags(tags ...uint64) (Index, bool) // IndexesWithColumn returns all indexes that index the given column. IndexesWithColumn(columnName string) []Index // IndexesWithTag returns all indexes that index the given tag. IndexesWithTag(tag uint64) []Index // Iter iterated over the indexes in the collection, calling the cb function on each. Iter(cb func(index Index) (stop bool, err error)) error // Merge adds the given index if it does not already exist. Indexed columns are referenced by column name, // rather than by tag number, which allows an index from a different table to be added as long as they have matching // column names. If an index with the same name or column structure already exists, or the index contains different // columns, then it is skipped. Merge(indexes ...Index) // RemoveIndex removes an index from the table metadata. RemoveIndex(indexName string) (Index, error) // RenameIndex renames an index in the table metadata. RenameIndex(oldName, newName string) (Index, error) }
func NewIndexCollection ¶
func NewIndexCollection(cols *ColCollection) IndexCollection
type IndexProperties ¶
type NotNullConstraint ¶
type NotNullConstraint struct{}
NotNullConstraint validates that a value is not null. It does not restrict 0 length strings, or 0 valued ints, or anything other than non nil values
func (NotNullConstraint) GetConstraintParams ¶
func (nnc NotNullConstraint) GetConstraintParams() map[string]string
GetConstraintParams returns nil as this constraint does not require any parameters.
func (NotNullConstraint) GetConstraintType ¶
func (nnc NotNullConstraint) GetConstraintType() string
GetConstraintType returns "not_null"
func (NotNullConstraint) SatisfiesConstraint ¶
func (nnc NotNullConstraint) SatisfiesConstraint(value types.Value) bool
SatisfiesConstraint returns true if value is not nil and not types.NullValue
func (NotNullConstraint) String ¶
func (nnc NotNullConstraint) String() string
String returns a useful description of the constraint
type Schema ¶
type Schema interface { // GetPKCols gets the collection of columns which make the primary key. GetPKCols() *ColCollection // GetNonPKCols gets the collection of columns which are not part of the primary key. GetNonPKCols() *ColCollection // GetAllCols gets the collection of all columns (pk and non-pk) GetAllCols() *ColCollection // Indexes returns a collection of all indexes on the table that this schema belongs to. Indexes() IndexCollection }
Schema is an interface for retrieving the columns that make up a schema
func SchemaFromCols ¶
func SchemaFromCols(allCols *ColCollection) Schema
SchemaFromCols creates a Schema from a collection of columns
func SchemaFromPKAndNonPKCols ¶
func SchemaFromPKAndNonPKCols(pkCols, nonPKCols *ColCollection) (Schema, error)
SchemaFromPKAndNonPKCols creates a Schema from a collection of the key columns, and the non-key columns.
func UnkeyedSchemaFromCols ¶
func UnkeyedSchemaFromCols(allCols *ColCollection) Schema
UnkeyedSchemaFromCols creates a schema without any primary keys to be used for displaying to users, tests, etc. Such unkeyed schemas are not suitable to be inserted into storage.
type SuperSchema ¶
type SuperSchema struct {
// contains filtered or unexported fields
}
SuperSchema is the union of all Schemas over the history of a table the tagNames map tracks all names corresponding to a column tag
func NewSuperSchema ¶
func NewSuperSchema(schemas ...Schema) (*SuperSchema, error)
NewSuperSchema creates a SuperSchema from the columns of schemas.
func SuperSchemaUnion ¶
func SuperSchemaUnion(superSchemas ...*SuperSchema) (*SuperSchema, error)
SuperSchemaUnion combines multiple SuperSchemas.
func UnmarshalSuperSchema ¶
func UnmarshalSuperSchema(allCols *ColCollection, tagNames map[uint64][]string) *SuperSchema
UnmarshalSuperSchema creates a SuperSchema, it is only used by the encoding package.
func (*SuperSchema) AddColumn ¶
func (ss *SuperSchema) AddColumn(col Column) (err error)
AddColumn adds a column and its name to the SuperSchema
func (*SuperSchema) AddSchemas ¶
func (ss *SuperSchema) AddSchemas(schemas ...Schema) error
AddSchemas adds all names and columns of each schema to the SuperSchema
func (*SuperSchema) AllColumnNames ¶
func (ss *SuperSchema) AllColumnNames(tag uint64) []string
AllColumnNames returns all names of the column corresponding to tag
func (*SuperSchema) AllTags ¶
func (ss *SuperSchema) AllTags() []uint64
AllTags returns a slice of all tags contained in the SuperSchema
func (*SuperSchema) Equals ¶
func (ss *SuperSchema) Equals(oss *SuperSchema) bool
Equals returns true iff the SuperSchemas have the same ColCollections and tagNames maps
func (*SuperSchema) GenerateColCollection ¶
func (ss *SuperSchema) GenerateColCollection() (*ColCollection, error)
GenerateColCollection creates a ColCollection from all the columns in the SuperSchema. Each column is assigned its latest name from its name history.
func (*SuperSchema) GenerateSchema ¶
func (ss *SuperSchema) GenerateSchema() (Schema, error)
GenerateSchema creates a Schema from all the columns in the SuperSchema. Each column is assigned its latest name from its name history.
func (*SuperSchema) GetByTag ¶
func (ss *SuperSchema) GetByTag(tag uint64) (Column, bool)
GetByTag returns the corresponding column and true if found, returns InvalidCol and false otherwise
func (*SuperSchema) Iter ¶
Iter processes each column in the SuperSchema with the specified function
func (*SuperSchema) LatestColumnName ¶
func (ss *SuperSchema) LatestColumnName(tag uint64) string
LatestColumnName returns the latest name of the column corresponding to tag
func (*SuperSchema) NameMapForSchema ¶
func (ss *SuperSchema) NameMapForSchema(sch Schema) (map[string]string, error)
NameMapForSchema creates a field name mapping needed to construct a rowconv.RowConverter sch columns are mapped by tag to the corresponding SuperSchema columns
func (*SuperSchema) RebaseTag ¶
func (ss *SuperSchema) RebaseTag(tagMapping map[uint64]uint64) (*SuperSchema, error)
RebaseTag changes the tag of a column from oldTag to newTag.
func (*SuperSchema) Size ¶
func (ss *SuperSchema) Size() int
Size returns the number of columns in the SuperSchema