Skip to content

Commit

Permalink
Merge pull request #2703 from dolthub/fulghum/implicit-prefix-lengths
Browse files Browse the repository at this point in the history
Minor changes for implicit prefix lengths in Doltgres
  • Loading branch information
fulghum authored Oct 16, 2024
2 parents 754f4b7 + cbdedd4 commit 7dbc4bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sql/analyzer/validate_create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
return nil, transform.SameTree, err
}

sch, err = validateAddColumn(initialSch, sch, n.(*plan.AddColumn))
sch, err = ValidateAddColumn(sch, n.(*plan.AddColumn))
if err != nil {
return nil, transform.SameTree, err
}
Expand Down Expand Up @@ -395,7 +395,10 @@ func validateRenameColumn(initialSch, sch sql.Schema, rc *plan.RenameColumn) (sq
return renameInSchema(sch, rc.ColumnName, rc.NewColumnName, nameable.Name()), nil
}

func validateAddColumn(initialSch sql.Schema, schema sql.Schema, ac *plan.AddColumn) (sql.Schema, error) {
// ValidateAddColumn validates that the column specified in |ac| can be added to the specified
// |schema|. A new Schema is returned, with the added column, if the column can be added. Otherwise,
// an error is returned if there are any validation errors.
func ValidateAddColumn(schema sql.Schema, ac *plan.AddColumn) (sql.Schema, error) {
table := ac.Table
nameable := table.(sql.Nameable)

Expand Down Expand Up @@ -828,8 +831,6 @@ func validateAutoIncrementAdd(schema sql.Schema, keyColumns map[string]bool) err
return nil
}

const textIndexPrefix = 1000

func schToColMap(sch sql.Schema) map[string]*sql.Column {
colMap := make(map[string]*sql.Column, len(sch))
for _, col := range sch {
Expand Down
5 changes: 5 additions & 0 deletions sql/plan/alter_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func (p AlterIndex) WithChildren(children ...sql.Node) (sql.Node, error) {
}
}

func (p AlterIndex) WithColumns(columns []sql.IndexColumn) (sql.Node, error) {
p.Columns = columns
return &p, nil
}

func (p AlterIndex) WithTargetSchema(schema sql.Schema) (sql.Node, error) {
p.targetSchema = schema
return &p, nil
Expand Down
8 changes: 8 additions & 0 deletions sql/plan/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ func (c *CreateTable) WithDatabase(db sql.Database) (sql.Node, error) {
return &nc, nil
}

// WithIndexDefs returns a copy of this CreateTable instance, with the index definitions
// set to |idxDefs|.
func (c *CreateTable) WithIndexDefs(idxDefs sql.IndexDefs) (*CreateTable, error) {
nc := *c
nc.idxDefs = idxDefs
return &nc, nil
}

// Name implements the Nameable interface.
func (c *CreateTable) Name() string {
return c.name
Expand Down

0 comments on commit 7dbc4bd

Please sign in to comment.