mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-20 11:29:13 -05:00
update logic for working set changes in dolt_column_diff
This commit is contained in:
@@ -180,11 +180,15 @@ func (dt *ColumnDiffTable) LookupPartitions(ctx *sql.Context, lookup sql.IndexLo
|
||||
}
|
||||
|
||||
type doltColDiffWorkingSetRowItr struct {
|
||||
ddb *doltdb.DoltDB
|
||||
stagedIndex int
|
||||
unstagedIndex int
|
||||
colIndex int
|
||||
changeSet string
|
||||
stagedTableDeltas []diff.TableDelta
|
||||
unstagedTableDeltas []diff.TableDelta
|
||||
currentTableDelta *diff.TableDelta
|
||||
tableName string
|
||||
colNames []string
|
||||
diffTypes []string
|
||||
}
|
||||
@@ -203,6 +207,7 @@ func (dt *ColumnDiffTable) newWorkingSetRowItr(ctx *sql.Context) (sql.RowIter, e
|
||||
|
||||
var ri sql.RowIter
|
||||
ri = &doltColDiffWorkingSetRowItr{
|
||||
ddb: dt.ddb,
|
||||
stagedTableDeltas: staged,
|
||||
unstagedTableDeltas: unstaged,
|
||||
}
|
||||
@@ -216,13 +221,14 @@ func (dt *ColumnDiffTable) newWorkingSetRowItr(ctx *sql.Context) (sql.RowIter, e
|
||||
|
||||
// incrementColIndex increments the column index and table changes index. When the end of the column names array is
|
||||
// reached, moves to the next table changes delta.
|
||||
func (d *doltColDiffWorkingSetRowItr) incrementColIndex(staged bool) {
|
||||
func (d *doltColDiffWorkingSetRowItr) incrementColIndex() {
|
||||
d.colIndex++
|
||||
|
||||
// move to next table once all modified columns are iterated through
|
||||
if d.colIndex >= len(d.colNames) {
|
||||
d.colIndex = 0
|
||||
if staged {
|
||||
d.currentTableDelta = nil
|
||||
if d.changeSet == "STAGED" {
|
||||
d.stagedIndex++
|
||||
} else {
|
||||
d.unstagedIndex++
|
||||
@@ -231,39 +237,43 @@ func (d *doltColDiffWorkingSetRowItr) incrementColIndex(staged bool) {
|
||||
}
|
||||
|
||||
func (d *doltColDiffWorkingSetRowItr) Next(ctx *sql.Context) (sql.Row, error) {
|
||||
var changeSet string
|
||||
var tableDelta diff.TableDelta
|
||||
// staged keeps track of whether we are looking at staged changes or working set changes
|
||||
staged := false
|
||||
if d.stagedIndex < len(d.stagedTableDeltas) {
|
||||
changeSet = "STAGED"
|
||||
tableDelta = d.stagedTableDeltas[d.stagedIndex]
|
||||
staged = true
|
||||
// only need to load new changes when we're finished iterating through the previous tableDelta
|
||||
if d.colIndex == 0 {
|
||||
d.loadColumnChanges(tableDelta)
|
||||
}
|
||||
} else if d.unstagedIndex < len(d.unstagedTableDeltas) {
|
||||
changeSet = "WORKING"
|
||||
tableDelta = d.unstagedTableDeltas[d.unstagedIndex]
|
||||
// only need to load new changes when we're finished iterating through the previous tableDelta
|
||||
if d.colIndex == 0 {
|
||||
d.loadColumnChanges(tableDelta)
|
||||
}
|
||||
} else {
|
||||
return nil, io.EOF
|
||||
}
|
||||
defer d.incrementColIndex()
|
||||
|
||||
defer d.incrementColIndex(staged)
|
||||
// only need to load new changes when we're finished iterating through the previous tableDelta
|
||||
for d.currentTableDelta == nil {
|
||||
if d.stagedIndex < len(d.stagedTableDeltas) {
|
||||
d.changeSet = "STAGED"
|
||||
d.currentTableDelta = &d.stagedTableDeltas[d.stagedIndex]
|
||||
} else if d.unstagedIndex < len(d.unstagedTableDeltas) {
|
||||
d.changeSet = "WORKING"
|
||||
d.currentTableDelta = &d.unstagedTableDeltas[d.unstagedIndex]
|
||||
} else {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
change, err := tableDelta.GetSummary(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
change, err := processTableColDelta(ctx, d.ddb, *d.currentTableDelta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// ignore changes with no modified columns
|
||||
if len(change.colNames) != 0 {
|
||||
d.colNames = change.colNames
|
||||
d.diffTypes = change.diffTypes
|
||||
d.tableName = change.tableName
|
||||
} else {
|
||||
if d.changeSet == "STAGED" {
|
||||
d.stagedIndex++
|
||||
} else {
|
||||
d.unstagedIndex++
|
||||
}
|
||||
d.currentTableDelta = nil
|
||||
}
|
||||
}
|
||||
|
||||
sqlRow := sql.NewRow(
|
||||
changeSet,
|
||||
change.TableName,
|
||||
d.changeSet,
|
||||
d.tableName,
|
||||
d.colNames[d.colIndex],
|
||||
nil, // committer
|
||||
nil, // email
|
||||
@@ -275,23 +285,6 @@ func (d *doltColDiffWorkingSetRowItr) Next(ctx *sql.Context) (sql.Row, error) {
|
||||
return sqlRow, nil
|
||||
}
|
||||
|
||||
// loadColumnChanges loads the list of column names for columns that have changed and the corresponding diff_type for
|
||||
// those column changes
|
||||
func (d *doltColDiffWorkingSetRowItr) loadColumnChanges(tableDelta diff.TableDelta) {
|
||||
var toCols, fromCols *schema.ColCollection
|
||||
if tableDelta.ToSch != nil {
|
||||
toCols = tableDelta.ToSch.GetAllCols()
|
||||
}
|
||||
if tableDelta.FromSch != nil {
|
||||
fromCols = tableDelta.FromSch.GetAllCols()
|
||||
}
|
||||
_, _, _, colNames, diffTypes := calculateColSchemaDiff(toCols, fromCols)
|
||||
// TODO (steph): if a row has been modified, all columns will be marked as modified instead of just the columns which contain the changes
|
||||
|
||||
d.colNames = colNames
|
||||
d.diffTypes = diffTypes
|
||||
}
|
||||
|
||||
func (d *doltColDiffWorkingSetRowItr) Close(c *sql.Context) error {
|
||||
return nil
|
||||
}
|
||||
@@ -498,8 +491,6 @@ func processTableColDelta(ctx *sql.Context, ddb *doltdb.DoltDB, delta diff.Table
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Renaming a table does not affect columns necessarily, if table data was changed it will be checked below
|
||||
|
||||
// Creating a table is always a schema change, and also a data change if data was inserted
|
||||
if delta.IsAdd() {
|
||||
diffTypes := make([]string, delta.ToSch.GetAllCols().Size())
|
||||
@@ -514,17 +505,11 @@ func processTableColDelta(ctx *sql.Context, ddb *doltdb.DoltDB, delta diff.Table
|
||||
}, nil
|
||||
}
|
||||
|
||||
// calculate which columns have been modified
|
||||
diffTableSchema, j, err := GetDiffTableSchemaAndJoiner(delta.ToTable.Format(), delta.FromSch, delta.ToSch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// NOTE: Renaming a table does not affect columns necessarily, if table data was changed it will be checked below
|
||||
|
||||
// accurate commit time returned elsewhere
|
||||
now := time.Now()
|
||||
dp := NewDiffPartition(delta.ToTable, delta.FromTable, delta.ToName, delta.FromName, (*dtypes.Timestamp)(&now), (*dtypes.Timestamp)(&now), delta.ToSch, delta.FromSch)
|
||||
ri := NewDiffPartitionRowIter(*dp, ddb, j)
|
||||
colNames, diffTypes, err := calculateColDelta(ctx, ri, delta.ToSch.GetAllCols(), delta.FromSch.GetAllCols(), diffTableSchema.GetAllCols())
|
||||
// calculate which columns have been modified
|
||||
colSchemaDiff := calculateColSchemaDiff(delta.ToSch.GetAllCols(), delta.FromSch.GetAllCols())
|
||||
colNames, diffTypes, err := calculateColDelta(ctx, ddb, &delta, colSchemaDiff)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -538,25 +523,34 @@ func processTableColDelta(ctx *sql.Context, ddb *doltdb.DoltDB, delta diff.Table
|
||||
|
||||
// calculateColDelta iterates through the rows of the given table delta and compares each cell in the to_ and from_
|
||||
// cells to compile a list of modified columns
|
||||
func calculateColDelta(ctx *sql.Context, iter sql.RowIter, toCols, fromCols, diffTableCols *schema.ColCollection) ([]string, []string, error) {
|
||||
colNamesSet := make(map[string]struct{})
|
||||
func calculateColDelta(ctx *sql.Context, ddb *doltdb.DoltDB, delta *diff.TableDelta, colSchemaDiff *ColSchemaDiff) ([]string, []string, error) {
|
||||
// initialize row iterator
|
||||
diffTableSchema, j, err := GetDiffTableSchemaAndJoiner(delta.ToTable.Format(), delta.FromSch, delta.ToSch)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
diffTableCols := diffTableSchema.GetAllCols()
|
||||
|
||||
now := time.Now() // accurate commit time returned elsewhere
|
||||
dp := NewDiffPartition(delta.ToTable, delta.FromTable, delta.ToName, delta.FromName, (*dtypes.Timestamp)(&now), (*dtypes.Timestamp)(&now), delta.ToSch, delta.FromSch)
|
||||
ri := NewDiffPartitionRowIter(*dp, ddb, j)
|
||||
|
||||
var resultColNames []string
|
||||
var resultDiffTypes []string
|
||||
modifiedCols, addedCols, droppedCols, _, _ := calculateColSchemaDiff(toCols, fromCols)
|
||||
|
||||
// add all added/dropped columns to result
|
||||
for _, col := range addedCols {
|
||||
for _, col := range colSchemaDiff.addedCols {
|
||||
resultColNames = append(resultColNames, col)
|
||||
resultDiffTypes = append(resultDiffTypes, diffTypeAdded)
|
||||
}
|
||||
for _, col := range droppedCols {
|
||||
for _, col := range colSchemaDiff.droppedCols {
|
||||
resultColNames = append(resultColNames, col)
|
||||
resultDiffTypes = append(resultDiffTypes, diffTypeRemoved)
|
||||
}
|
||||
|
||||
colNamesSet := make(map[string]struct{})
|
||||
// check each row for diffs in modified columns
|
||||
for {
|
||||
r, err := iter.Next(ctx)
|
||||
r, err := ri.Next(ctx)
|
||||
if err == io.EOF {
|
||||
for col := range colNamesSet {
|
||||
// append modified columns to result
|
||||
@@ -569,7 +563,7 @@ func calculateColDelta(ctx *sql.Context, iter sql.RowIter, toCols, fromCols, dif
|
||||
}
|
||||
|
||||
// only need to check modified columns
|
||||
for _, col := range modifiedCols {
|
||||
for _, col := range colSchemaDiff.modifiedCols {
|
||||
toColTag := diffTableCols.NameToCol["to_"+col].Tag
|
||||
fromColTag := diffTableCols.NameToCol["from_"+col].Tag
|
||||
toIdx := diffTableCols.TagToIdx[toColTag]
|
||||
@@ -581,7 +575,7 @@ func calculateColDelta(ctx *sql.Context, iter sql.RowIter, toCols, fromCols, dif
|
||||
}
|
||||
|
||||
// can stop checking rows when we already have all modified columns in the result set
|
||||
if len(colNamesSet) == len(modifiedCols) {
|
||||
if len(colNamesSet) == len(colSchemaDiff.modifiedCols) {
|
||||
for col := range colNamesSet {
|
||||
// append modified columns to result
|
||||
resultColNames = append(resultColNames, col)
|
||||
@@ -592,10 +586,20 @@ func calculateColDelta(ctx *sql.Context, iter sql.RowIter, toCols, fromCols, dif
|
||||
}
|
||||
}
|
||||
|
||||
// calculateColSchemaDiff calculates which columns were modified, added, or dropped between to and from schemas and
|
||||
// returns a list of column names for each type of change, the total list of column names, and a corresponding list of
|
||||
// ColSchemaDiff is a collection of column names that hold the results of doing a schema diff between to/from schemas,
|
||||
// i.e. a list of column names for each type of change, the total list of column names, and a corresponding list of
|
||||
// diff_types for each column
|
||||
func calculateColSchemaDiff(toCols *schema.ColCollection, fromCols *schema.ColCollection) ([]string, []string, []string, []string, []string) {
|
||||
type ColSchemaDiff struct {
|
||||
modifiedCols []string
|
||||
addedCols []string
|
||||
droppedCols []string
|
||||
allCols []string
|
||||
diffTypes []string
|
||||
}
|
||||
|
||||
// calculateColSchemaDiff calculates which columns were modified, added, or dropped between to and from schemas and
|
||||
// returns a ColSchemaDiff to hold the results of the diff
|
||||
func calculateColSchemaDiff(toCols *schema.ColCollection, fromCols *schema.ColCollection) *ColSchemaDiff {
|
||||
// put to/from columns into a set
|
||||
toColTags := make(map[uint64]struct{})
|
||||
fromColTags := make(map[uint64]struct{})
|
||||
@@ -642,5 +646,11 @@ func calculateColSchemaDiff(toCols *schema.ColCollection, fromCols *schema.ColCo
|
||||
}
|
||||
}
|
||||
|
||||
return modifiedCols, addedCols, droppedCols, allCols, diffTypes
|
||||
return &ColSchemaDiff{
|
||||
modifiedCols: modifiedCols,
|
||||
addedCols: addedCols,
|
||||
droppedCols: droppedCols,
|
||||
allCols: allCols,
|
||||
diffTypes: diffTypes,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3703,27 +3703,79 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
|
||||
var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
{
|
||||
Name: "working set changes",
|
||||
Name: "table changes - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table regularTable (a int primary key, b int);",
|
||||
"create table modifiedTable (a int primary key, b int);",
|
||||
"insert into modifiedTable values (1, 2), (2, 3);",
|
||||
"create table droppedTable (a int primary key, b int);",
|
||||
"insert into droppedTable values (1, 2), (2, 3);",
|
||||
"create table renamedTable (a int primary key, b int);",
|
||||
"call dolt_add('.')",
|
||||
"call dolt_commit('-am', 'creating tables');",
|
||||
|
||||
"update modifiedTable set b = 5 where a = 1;",
|
||||
"drop table droppedTable;",
|
||||
"rename table renamedTable to newRenamedTable;",
|
||||
"create table addedTable (a int primary key, b int);",
|
||||
"call dolt_add('.')",
|
||||
"call dolt_commit('-am', 'make table changes');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'modifiedTable';",
|
||||
Expected: []sql.Row{
|
||||
{"modifiedTable", "a", "added"},
|
||||
{"modifiedTable", "b", "added"},
|
||||
{"modifiedTable", "b", "modified"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'droppedTable';",
|
||||
Expected: []sql.Row{
|
||||
{"droppedTable", "a", "added"},
|
||||
{"droppedTable", "b", "added"},
|
||||
{"droppedTable", "a", "removed"},
|
||||
{"droppedTable", "b", "removed"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'renamedTable' OR table_name = 'newRenamedTable';",
|
||||
Expected: []sql.Row{
|
||||
{"renamedTable", "a", "added"},
|
||||
{"renamedTable", "b", "added"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'addedTable';",
|
||||
Expected: []sql.Row{
|
||||
{"addedTable", "a", "added"},
|
||||
{"addedTable", "b", "added"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "table changes - working set",
|
||||
SetUpScript: []string{
|
||||
"create table modifiedTable (a int primary key, b int);",
|
||||
"insert into modifiedTable values (1, 2), (2, 3);",
|
||||
"create table droppedTable (a int primary key, b int);",
|
||||
"insert into droppedTable values (1, 2), (2, 3);",
|
||||
"create table renamedTable (a int primary key, b int);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"insert into regularTable values (1, 2), (2, 3);",
|
||||
"update modifiedTable set b = 5 where a = 1;",
|
||||
"drop table droppedTable;",
|
||||
"rename table renamedTable to newRenamedTable;",
|
||||
"create table addedTable (a int primary key, b int);",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT commit_hash, table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'regularTable' ORDER BY commit_hash, table_name, column_name;",
|
||||
Query: "SELECT commit_hash, table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'modifiedTable' ORDER BY commit_hash, table_name, column_name;",
|
||||
Expected: []sql.Row{
|
||||
{"STAGED", "regularTable", "a", "added"},
|
||||
{"STAGED", "regularTable", "b", "added"},
|
||||
{"WORKING", "regularTable", "a", "modified"},
|
||||
{"WORKING", "regularTable", "b", "modified"},
|
||||
{"STAGED", "modifiedTable", "a", "added"},
|
||||
{"STAGED", "modifiedTable", "b", "added"},
|
||||
{"WORKING", "modifiedTable", "b", "modified"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3740,8 +3792,6 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
Expected: []sql.Row{
|
||||
{"STAGED", "renamedTable", "a", "added"},
|
||||
{"STAGED", "renamedTable", "b", "added"},
|
||||
{"WORKING", "newRenamedTable", "a", "modified"},
|
||||
{"WORKING", "newRenamedTable", "b", "modified"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3754,7 +3804,7 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "add column",
|
||||
Name: "add column - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"call dolt_add('.')",
|
||||
@@ -3764,7 +3814,6 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
|
||||
"alter table t add column d int;",
|
||||
"set @Commit2 = '';",
|
||||
"update t set d = 6 where pk = 1;",
|
||||
"call dolt_add('.')",
|
||||
"call dolt_commit_hash_out(@Commit2, '-m', 'updating d in t');",
|
||||
},
|
||||
@@ -3780,7 +3829,27 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "modify column",
|
||||
Name: "add column - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"insert into t values (1, 2), (3, 4);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"alter table t add column d int;",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "select count(*) from dolt_column_diff where commit_hash = 'STAGED';",
|
||||
Expected: []sql.Row{{2}},
|
||||
},
|
||||
{
|
||||
Query: "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = 'WORKING';",
|
||||
Expected: []sql.Row{{"t", "d", "added"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "modify column - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"call dolt_add('.')",
|
||||
@@ -3805,7 +3874,27 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "drop column",
|
||||
Name: "modify column - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"insert into t values (1, 2), (3, 4);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"update t set c = 5 where pk = 3;",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "select count(*) from dolt_column_diff where commit_hash = 'STAGED';",
|
||||
Expected: []sql.Row{{2}},
|
||||
},
|
||||
{
|
||||
Query: "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = 'WORKING';",
|
||||
Expected: []sql.Row{{"t", "c", "modified"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "drop column - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"call dolt_add('.')",
|
||||
@@ -3830,7 +3919,27 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "drop column and recreate with same type",
|
||||
Name: "drop column - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"insert into t values (1, 2), (3, 4);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"alter table t drop column c;",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "select count(*) from dolt_column_diff where commit_hash = 'STAGED';",
|
||||
Expected: []sql.Row{{2}},
|
||||
},
|
||||
{
|
||||
Query: "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = 'WORKING';",
|
||||
Expected: []sql.Row{{"t", "c", "removed"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "drop column and recreate with same type - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"call dolt_add('.')",
|
||||
@@ -3875,7 +3984,39 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "drop column, then rename column with same type to same name",
|
||||
Name: "drop column and recreate with same type - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"insert into t values (1, 2), (3, 4);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"alter table t drop column c;",
|
||||
"alter table t add column c int;",
|
||||
"insert into t values (100, 101);",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
|
||||
Expected: []sql.Row{{4}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "added"},
|
||||
{"t", "c", "added"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "modified"},
|
||||
{"t", "c", "modified"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "drop column, then rename column with same type to same name - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c1 int, c2 int);",
|
||||
"call dolt_add('.')",
|
||||
@@ -3921,7 +4062,41 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "column drop and recreate with different type that can be coerced (int -> string)",
|
||||
Name: "drop column, then rename column with same type to same name - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c1 int, c2 int);",
|
||||
"insert into t values (1, 2, 3), (4, 5, 6);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"alter table t drop column c1;",
|
||||
"alter table t rename column c2 to c1;",
|
||||
"insert into t values (100, 101);",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
|
||||
Expected: []sql.Row{{6}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "added"},
|
||||
{"t", "c1", "added"},
|
||||
{"t", "c2", "added"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "modified"},
|
||||
{"t", "c1", "removed"},
|
||||
{"t", "c1", "modified"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "column drop and recreate with different type that can be coerced (int -> string) - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"call dolt_add('.')",
|
||||
@@ -3966,7 +4141,40 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "column drop and recreate with different type that can NOT be coerced (string -> int)",
|
||||
Name: "column drop and recreate with different type that can be coerced (int -> string) - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c int);",
|
||||
"insert into t values (1, 2), (3, 4);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"alter table t drop column c;",
|
||||
"alter table t add column c varchar(20);",
|
||||
"insert into t values (100, '101');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
|
||||
Expected: []sql.Row{{5}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "added"},
|
||||
{"t", "c", "added"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "modified"},
|
||||
{"t", "c", "removed"},
|
||||
{"t", "c", "added"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "column drop and recreate with different type that can NOT be coerced (string -> int) - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c varchar(20));",
|
||||
"call dolt_add('.')",
|
||||
@@ -4011,7 +4219,40 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "multiple column renames",
|
||||
Name: "column drop and recreate with different type that can NOT be coerced (string -> int) - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c varchar(20));",
|
||||
"insert into t values (1, 'two'), (3, 'four');",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"alter table t drop column c;",
|
||||
"alter table t add column c int;",
|
||||
"insert into t values (100, 101);",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
|
||||
Expected: []sql.Row{{5}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "added"},
|
||||
{"t", "c", "added"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "modified"},
|
||||
{"t", "c", "removed"},
|
||||
{"t", "c", "added"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "multiple column renames - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c1 int);",
|
||||
"call dolt_add('.')",
|
||||
@@ -4068,7 +4309,43 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "primary key change",
|
||||
Name: "multiple column renames - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c1 int);",
|
||||
"insert into t values (1, 2);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"alter table t rename column c1 to c2;",
|
||||
"insert into t values (3, 4);",
|
||||
|
||||
"alter table t drop column c2;",
|
||||
"alter table t add column c2 int;",
|
||||
"insert into t values (100, '101');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
|
||||
Expected: []sql.Row{{5}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "added"},
|
||||
{"t", "c1", "added"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "modified"},
|
||||
{"t", "c1", "removed"},
|
||||
{"t", "c2", "added"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "primary key change - commit history",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c1 int);",
|
||||
"call dolt_add('.')",
|
||||
@@ -4124,6 +4401,38 @@ var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "primary key change - working set",
|
||||
SetUpScript: []string{
|
||||
"create table t (pk int primary key, c1 int);",
|
||||
"insert into t values (1, 2), (3, 4);",
|
||||
"call dolt_add('.')",
|
||||
|
||||
"alter table t drop primary key;",
|
||||
"alter table t add primary key (c1);",
|
||||
"insert into t values (7, 8);",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
|
||||
Expected: []sql.Row{{4}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "added"},
|
||||
{"t", "c1", "added"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
|
||||
Expected: []sql.Row{
|
||||
{"t", "pk", "modified"},
|
||||
{"t", "c1", "modified"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var CommitDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
|
||||
Reference in New Issue
Block a user