mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-21 11:29:51 -05:00
removed more redundant format assertions
This commit is contained in:
@@ -35,7 +35,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess/mutexmap"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/globalstate"
|
||||
"github.com/dolthub/dolt/go/store/prolly/tree"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
type LockMode int64
|
||||
@@ -374,41 +373,36 @@ func (a *AutoIncrementTracker) deepSet(ctx *sql.Context, tableName string, table
|
||||
}
|
||||
|
||||
func getMaxIndexValue(ctx *sql.Context, indexData durable.Index) (uint64, error) {
|
||||
if types.IsFormat_DOLT(indexData.Format()) {
|
||||
idx, err := durable.ProllyMapFromIndex(indexData)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
iter, err := idx.IterAllReverse(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
kd, _ := idx.Descriptors()
|
||||
k, _, err := iter.Next(ctx)
|
||||
if err == io.EOF {
|
||||
return 0, nil
|
||||
} else if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// TODO: is the auto-inc column always the first column in the index?
|
||||
field, err := tree.GetField(ctx, kd, 0, k, idx.NodeStore())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
maxVal, err := CoerceAutoIncrementValue(ctx, field)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return maxVal, nil
|
||||
idx, err := durable.ProllyMapFromIndex(indexData)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// For an LD format table, this operation won't succeed
|
||||
return math.MaxUint64, nil
|
||||
iter, err := idx.IterAllReverse(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
kd, _ := idx.Descriptors()
|
||||
k, _, err := iter.Next(ctx)
|
||||
if err == io.EOF {
|
||||
return 0, nil
|
||||
} else if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// TODO: is the auto-inc column always the first column in the index?
|
||||
field, err := tree.GetField(ctx, kd, 0, k, idx.NodeStore())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
maxVal, err := CoerceAutoIncrementValue(ctx, field)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return maxVal, nil
|
||||
}
|
||||
|
||||
// AddNewTable initializes a new table with an auto increment column to the tracker, as necessary
|
||||
|
||||
@@ -574,9 +574,9 @@ func (pm *PreviewMergeConflictsTableFunction) evaluateArguments() (interface{},
|
||||
return leftBranchVal, rightBranchVal, tableName, nil
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// --------------------------------------------------
|
||||
// previewMergeConflictsTableFunctionRowIter
|
||||
//--------------------------------------------------
|
||||
// --------------------------------------------------
|
||||
|
||||
var _ sql.RowIter = &previewMergeConflictsTableFunctionRowIter{}
|
||||
|
||||
|
||||
@@ -32,13 +32,10 @@ func NewConflictsTable(ctx *sql.Context, tblName doltdb.TableName, srcTable sql.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if types.IsFormat_DOLT(tbl.Format()) {
|
||||
upd, ok := srcTable.(sql.UpdatableTable)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%s can not have conflicts because it is not updateable", tblName)
|
||||
}
|
||||
return newProllyConflictsTable(ctx, tbl, upd, tblName, root, rs)
|
||||
types.AssertFormat_DOLT(tbl.Format())
|
||||
upd, ok := srcTable.(sql.UpdatableTable)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%s can not have conflicts because it is not updateable", tblName)
|
||||
}
|
||||
|
||||
panic("Unsupported storage format for conflicts table: " + tbl.Format().VersionString())
|
||||
return newProllyConflictsTable(ctx, tbl, upd, tblName, root, rs)
|
||||
}
|
||||
|
||||
@@ -490,25 +490,16 @@ func TestInsertIgnoreInto(t *testing.T) {
|
||||
|
||||
// TODO: merge this into the above test when we remove old format
|
||||
func TestInsertDuplicateKeyKeyless(t *testing.T) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip()
|
||||
}
|
||||
enginetest.TestInsertDuplicateKeyKeyless(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
// TODO: merge this into the above test when we remove old format
|
||||
func TestInsertDuplicateKeyKeylessPrepared(t *testing.T) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip()
|
||||
}
|
||||
enginetest.TestInsertDuplicateKeyKeylessPrepared(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
// TODO: merge this into the above test when we remove old format
|
||||
func TestIgnoreIntoWithDuplicateUniqueKeyKeyless(t *testing.T) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip()
|
||||
}
|
||||
h := newDoltHarness(t)
|
||||
defer h.Close()
|
||||
enginetest.TestIgnoreIntoWithDuplicateUniqueKeyKeyless(t, h)
|
||||
@@ -516,9 +507,6 @@ func TestIgnoreIntoWithDuplicateUniqueKeyKeyless(t *testing.T) {
|
||||
|
||||
// TODO: merge this into the above test when we remove old format
|
||||
func TestIgnoreIntoWithDuplicateUniqueKeyKeylessPrepared(t *testing.T) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip()
|
||||
}
|
||||
enginetest.TestIgnoreIntoWithDuplicateUniqueKeyKeylessPrepared(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
@@ -601,17 +589,14 @@ func TestSpatialScriptsPrepared(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSpatialIndexScripts(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
enginetest.TestSpatialIndexScripts(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestSpatialIndexScriptsPrepared(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
enginetest.TestSpatialIndexScriptsPrepared(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestSpatialIndexPlans(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
enginetest.TestSpatialIndexPlans(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
@@ -862,7 +847,6 @@ func TestCreateDatabase(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlobs(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
h := newDoltHarness(t)
|
||||
defer h.Close()
|
||||
enginetest.TestBlobs(t, h)
|
||||
@@ -893,14 +877,11 @@ func TestVectorType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexPrefix(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
harness := newDoltHarness(t)
|
||||
RunIndexPrefixTest(t, harness)
|
||||
}
|
||||
|
||||
func TestBigBlobs(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
|
||||
h := newDoltHarness(t)
|
||||
RunBigBlobsTest(t, h)
|
||||
}
|
||||
@@ -908,7 +889,6 @@ func TestBigBlobs(t *testing.T) {
|
||||
func TestAdaptiveEncoding(t *testing.T) {
|
||||
defer func() { schema.UseAdaptiveEncoding = false }()
|
||||
schema.UseAdaptiveEncoding = true
|
||||
skipOldFormat(t)
|
||||
|
||||
RunTestAdaptiveEncoding(t, newDoltHarness(t), AdaptiveEncodingTestType_Blob, AdaptiveEncodingTestPurpose_Representation)
|
||||
RunTestAdaptiveEncoding(t, newDoltHarness(t), AdaptiveEncodingTestType_Blob, AdaptiveEncodingTestPurpose_Correctness)
|
||||
@@ -950,9 +930,6 @@ func TestForeignKeyBranchesPrepared(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFulltextIndexes(t *testing.T) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("FULLTEXT is not supported on the old format")
|
||||
}
|
||||
if runtime.GOOS == "windows" && os.Getenv("CI") != "" {
|
||||
t.Skip("For some reason, this is flaky only on Windows CI.")
|
||||
}
|
||||
@@ -1335,21 +1312,6 @@ func TestDoltPreviewMergeConflictsPrepared(t *testing.T) {
|
||||
RunDoltPreviewMergeConflictsPreparedTests(t, h)
|
||||
}
|
||||
|
||||
// these tests are temporary while there is a difference between the old format
|
||||
// and new format merge behaviors.
|
||||
func TestOldFormatMergeConflictsAndCVs(t *testing.T) {
|
||||
if types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip()
|
||||
}
|
||||
for _, script := range OldFormatMergeConflictsAndCVsScripts {
|
||||
func() {
|
||||
h := newDoltHarness(t)
|
||||
defer h.Close()
|
||||
enginetest.TestScript(t, h, script)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoltReset(t *testing.T) {
|
||||
h := newDoltEnginetestHarness(t)
|
||||
RunDoltResetTest(t, h)
|
||||
@@ -1933,21 +1895,18 @@ func TestPreparedStatements(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCharsetCollationEngine(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
h := newDoltHarness(t)
|
||||
defer h.Close()
|
||||
enginetest.TestCharsetCollationEngine(t, h)
|
||||
}
|
||||
|
||||
func TestCharsetCollationWire(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
harness := newDoltHarness(t)
|
||||
defer harness.Close()
|
||||
enginetest.TestCharsetCollationWire(t, harness, newSessionBuilder(harness))
|
||||
}
|
||||
|
||||
func TestDatabaseCollationWire(t *testing.T) {
|
||||
skipOldFormat(t)
|
||||
harness := newDoltHarness(t)
|
||||
defer harness.Close()
|
||||
enginetest.TestDatabaseCollationWire(t, harness, newSessionBuilder(harness))
|
||||
|
||||
@@ -43,7 +43,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/store/datas"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const skipPreparedFlag = "DOLT_SKIP_PREPARED_ENGINETESTS"
|
||||
@@ -950,21 +949,16 @@ func RunDoltConflictsTableNameTableTests(t *testing.T, h DoltEnginetestHarness)
|
||||
}()
|
||||
}
|
||||
|
||||
if types.IsFormat_DOLT(types.Format_Default) {
|
||||
for _, script := range Dolt1ConflictTableNameTableTests {
|
||||
func() {
|
||||
h := h.NewHarness(t)
|
||||
defer h.Close()
|
||||
enginetest.TestScript(t, h, script)
|
||||
}()
|
||||
}
|
||||
for _, script := range Dolt1ConflictTableNameTableTests {
|
||||
func() {
|
||||
h := h.NewHarness(t)
|
||||
defer h.Close()
|
||||
enginetest.TestScript(t, h, script)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func RunKeylessDoltMergeCVsAndConflictsTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip()
|
||||
}
|
||||
for _, script := range KeylessMergeCVsAndConflictsScripts {
|
||||
func() {
|
||||
h := h.NewHarness(t)
|
||||
@@ -1172,9 +1166,6 @@ func RunUnscopedDiffSystemTableTestsPrepared(t *testing.T, h DoltEnginetestHarne
|
||||
}
|
||||
|
||||
func RunColumnDiffSystemTableTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("correct behavior of dolt_column_diff only guaranteed on new format")
|
||||
}
|
||||
for _, test := range ColumnDiffSystemTableScriptTests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
enginetest.TestScript(t, h.NewHarness(t), test)
|
||||
@@ -1183,9 +1174,6 @@ func RunColumnDiffSystemTableTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
}
|
||||
|
||||
func RunColumnDiffSystemTableTestsPrepared(t *testing.T, h DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("correct behavior of dolt_column_diff only guaranteed on new format")
|
||||
}
|
||||
for _, test := range ColumnDiffSystemTableScriptTests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
enginetest.TestScriptPrepared(t, h.NewHarness(t), test)
|
||||
@@ -1391,10 +1379,6 @@ func RunCommitDiffSystemTableTestsPrepared(t *testing.T, harness DoltEnginetestH
|
||||
}
|
||||
|
||||
func RunDoltDiffSystemTableTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("only new format support system table indexing")
|
||||
}
|
||||
|
||||
for _, test := range DiffSystemTableScriptTests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
h = h.NewHarness(t)
|
||||
@@ -1404,23 +1388,17 @@ func RunDoltDiffSystemTableTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
})
|
||||
}
|
||||
|
||||
if types.IsFormat_DOLT(types.Format_Default) {
|
||||
for _, test := range Dolt1DiffSystemTableScripts {
|
||||
func() {
|
||||
h = h.NewHarness(t)
|
||||
defer h.Close()
|
||||
h.Setup(setup.MydbData)
|
||||
enginetest.TestScript(t, h, test)
|
||||
}()
|
||||
}
|
||||
for _, test := range Dolt1DiffSystemTableScripts {
|
||||
func() {
|
||||
h = h.NewHarness(t)
|
||||
defer h.Close()
|
||||
h.Setup(setup.MydbData)
|
||||
enginetest.TestScript(t, h, test)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func RunDoltDiffSystemTableTestsPrepared(t *testing.T, h DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("only new format support system table indexing")
|
||||
}
|
||||
|
||||
for _, test := range DiffSystemTableScriptTests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
h = h.NewHarness(t)
|
||||
@@ -1430,23 +1408,17 @@ func RunDoltDiffSystemTableTestsPrepared(t *testing.T, h DoltEnginetestHarness)
|
||||
})
|
||||
}
|
||||
|
||||
if types.IsFormat_DOLT(types.Format_Default) {
|
||||
for _, test := range Dolt1DiffSystemTableScripts {
|
||||
func() {
|
||||
h = h.NewHarness(t)
|
||||
defer h.Close()
|
||||
h.Setup(setup.MydbData)
|
||||
enginetest.TestScriptPrepared(t, h, test)
|
||||
}()
|
||||
}
|
||||
for _, test := range Dolt1DiffSystemTableScripts {
|
||||
func() {
|
||||
h = h.NewHarness(t)
|
||||
defer h.Close()
|
||||
h.Setup(setup.MydbData)
|
||||
enginetest.TestScriptPrepared(t, h, test)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func RunNonlocalTableTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("only new format support system table indexing")
|
||||
}
|
||||
|
||||
for _, test := range NonlocalScripts {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
h = h.NewHarness(t)
|
||||
@@ -1458,10 +1430,6 @@ func RunNonlocalTableTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
}
|
||||
|
||||
func RunNonlocalTableTestsPrepared(t *testing.T, h DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("only new format support system table indexing")
|
||||
}
|
||||
|
||||
for _, test := range NonlocalScripts {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
h = h.NewHarness(t)
|
||||
@@ -1517,10 +1485,6 @@ func RunQueryDiffTests(t *testing.T, harness DoltEnginetestHarness) {
|
||||
}
|
||||
|
||||
func RunSystemTableIndexesTests(t *testing.T, harness DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("only new format support system table indexing")
|
||||
}
|
||||
|
||||
for _, stt := range SystemTableIndexTests {
|
||||
harness = harness.NewHarness(t).WithParallelism(1)
|
||||
defer harness.Close()
|
||||
@@ -1570,10 +1534,6 @@ var biasedCosters = []memo.Coster{
|
||||
}
|
||||
|
||||
func RunSystemTableIndexesTestsPrepared(t *testing.T, harness DoltEnginetestHarness) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip("only new format support system table indexing")
|
||||
}
|
||||
|
||||
for _, stt := range SystemTableIndexTests {
|
||||
harness = harness.NewHarness(t).WithParallelism(2)
|
||||
defer harness.Close()
|
||||
@@ -1917,12 +1877,7 @@ func RunDoltVerifyConstraintsTests(t *testing.T, harness DoltEnginetestHarness)
|
||||
}
|
||||
|
||||
func RunDoltStorageFormatTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
var expectedFormatString string
|
||||
if types.IsFormat_DOLT(types.Format_Default) {
|
||||
expectedFormatString = "NEW ( __DOLT__ )"
|
||||
} else {
|
||||
expectedFormatString = fmt.Sprintf("OLD ( %s )", types.Format_Default.VersionString())
|
||||
}
|
||||
var expectedFormatString = "NEW ( __DOLT__ )"
|
||||
script := queries.ScriptTest{
|
||||
Name: "dolt storage format function works",
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
@@ -1937,7 +1892,6 @@ func RunDoltStorageFormatTests(t *testing.T, h DoltEnginetestHarness) {
|
||||
}
|
||||
|
||||
func RunThreeWayMergeWithSchemaChangeScripts(t *testing.T, h DoltEnginetestHarness) {
|
||||
skipOldFormat(t)
|
||||
runMergeScriptTestsInBothDirections(t, SchemaChangeTestsBasicCases, "basic cases", false)
|
||||
runMergeScriptTestsInBothDirections(t, SchemaChangeTestsForDataConflicts, "data conflicts", false)
|
||||
runMergeScriptTestsInBothDirections(t, SchemaChangeTestsCollations, "collation changes", false)
|
||||
@@ -1960,7 +1914,6 @@ func RunThreeWayMergeWithSchemaChangeScripts(t *testing.T, h DoltEnginetestHarne
|
||||
}
|
||||
|
||||
func RunThreeWayMergeWithSchemaChangeScriptsPrepared(t *testing.T, h DoltEnginetestHarness) {
|
||||
skipOldFormat(t)
|
||||
runMergeScriptTestsInBothDirections(t, SchemaChangeTestsBasicCases, "basic cases", false)
|
||||
runMergeScriptTestsInBothDirections(t, SchemaChangeTestsForDataConflicts, "data conflicts", false)
|
||||
runMergeScriptTestsInBothDirections(t, SchemaChangeTestsCollations, "collation changes", false)
|
||||
@@ -2030,12 +1983,6 @@ var newFormatSkippedScripts = []string{
|
||||
"Multiple indexes on the same columns in a different order",
|
||||
}
|
||||
|
||||
func skipOldFormat(t *testing.T) {
|
||||
if !types.IsFormat_DOLT(types.Format_Default) {
|
||||
t.Skip()
|
||||
}
|
||||
}
|
||||
|
||||
func skipPreparedTests(t *testing.T) {
|
||||
if skipPrepared {
|
||||
t.Skip("skip prepared")
|
||||
|
||||
@@ -4594,362 +4594,6 @@ var SchemaConflictScripts = []queries.ScriptTest{
|
||||
},
|
||||
}
|
||||
|
||||
// OldFormatMergeConflictsAndCVsScripts tests old format merge behavior
|
||||
// where violations are appended and merges are aborted if there are existing
|
||||
// violations and/or conflicts.
|
||||
var OldFormatMergeConflictsAndCVsScripts = []queries.ScriptTest{
|
||||
{
|
||||
Name: "merging branches into a constraint violated head. Any new violations are appended",
|
||||
SetUpScript: []string{
|
||||
"CREATE table parent (pk int PRIMARY KEY, col1 int);",
|
||||
"CREATE table child (pk int PRIMARY KEY, parent_fk int, FOREIGN KEY (parent_fk) REFERENCES parent(pk));",
|
||||
"CREATE table other (pk int);",
|
||||
"CALL DOLT_ADD('.')",
|
||||
"INSERT INTO parent VALUES (1, 1), (2, 2);",
|
||||
"CALL DOLT_COMMIT('-am', 'setup');",
|
||||
"CALL DOLT_BRANCH('branch1');",
|
||||
"CALL DOLT_BRANCH('branch2');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
// we need dolt_force_transaction_commit because we want to
|
||||
// transaction commit constraint violations that occur as a
|
||||
// result of a merge.
|
||||
Query: "set autocommit = off, dolt_force_transaction_commit = on",
|
||||
Expected: []sql.Row{{types.NewOkResult(0)}},
|
||||
},
|
||||
{
|
||||
Query: "DELETE FROM parent where pk = 1;",
|
||||
Expected: []sql.Row{{types.NewOkResult(1)}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-am', 'delete parent 1');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_CHECKOUT('branch1');",
|
||||
Expected: []sql.Row{{0, "Switched to branch 'branch1'"}},
|
||||
},
|
||||
{
|
||||
Query: "INSERT INTO CHILD VALUES (1, 1);",
|
||||
Expected: []sql.Row{{types.NewOkResult(1)}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-am', 'insert child of parent 1');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_CHECKOUT('main');",
|
||||
Expected: []sql.Row{{0, "Switched to branch 'main'"}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('branch1');",
|
||||
Expected: []sql.Row{{"", 0, 1, "conflicts found"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;",
|
||||
Expected: []sql.Row{{uint16(1), 1, 1}},
|
||||
},
|
||||
{
|
||||
Query: "COMMIT;",
|
||||
Expected: []sql.Row{},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-am', 'commit constraint violations');",
|
||||
ExpectedErrStr: "error: the table(s) child have constraint violations",
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-afm', 'commit constraint violations');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_BRANCH('branch3');",
|
||||
Expected: []sql.Row{{0}},
|
||||
},
|
||||
{
|
||||
Query: "DELETE FROM parent where pk = 2;",
|
||||
Expected: []sql.Row{{types.NewOkResult(1)}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-afm', 'remove parent 2');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_CHECKOUT('branch2');",
|
||||
Expected: []sql.Row{{0, "Switched to branch 'branch2'"}},
|
||||
},
|
||||
{
|
||||
Query: "INSERT INTO OTHER VALUES (1);",
|
||||
Expected: []sql.Row{{types.NewOkResult(1)}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-am', 'non-fk insert');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_CHECKOUT('main');",
|
||||
Expected: []sql.Row{{0, "Switched to branch 'main'"}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('branch2');",
|
||||
Expected: []sql.Row{{"", 0, 1, "conflicts found"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;",
|
||||
Expected: []sql.Row{{uint16(1), 1, 1}},
|
||||
},
|
||||
{
|
||||
Query: "COMMIT;",
|
||||
Expected: []sql.Row{},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-am', 'commit non-conflicting merge');",
|
||||
ExpectedErrStr: "error: the table(s) child have constraint violations",
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-afm', 'commit non-conflicting merge');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_CHECKOUT('branch3');",
|
||||
Expected: []sql.Row{{0, "Switched to branch 'branch3'"}},
|
||||
},
|
||||
{
|
||||
Query: "INSERT INTO CHILD VALUES (2, 2);",
|
||||
Expected: []sql.Row{{types.NewOkResult(1)}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-afm', 'add child of parent 2');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_CHECKOUT('main');",
|
||||
Expected: []sql.Row{{0, "Switched to branch 'main'"}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('branch3');",
|
||||
Expected: []sql.Row{{"", 0, 1, "conflicts found"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;",
|
||||
Expected: []sql.Row{{uint16(1), 1, 1}, {uint16(1), 2, 2}},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "conflicting merge aborts when conflicts and violations already exist",
|
||||
SetUpScript: []string{
|
||||
"CREATE table parent (pk int PRIMARY KEY, col1 int);",
|
||||
"CREATE table child (pk int PRIMARY KEY, parent_fk int, FOREIGN KEY (parent_fk) REFERENCES parent(pk));",
|
||||
"CALL DOLT_ADD('.')",
|
||||
"INSERT INTO parent VALUES (1, 1), (2, 1);",
|
||||
"CALL DOLT_COMMIT('-am', 'create table with data');",
|
||||
"CALL DOLT_BRANCH('other');",
|
||||
"CALL DOLT_BRANCH('other2');",
|
||||
"UPDATE parent SET col1 = 2 where pk = 1;",
|
||||
"DELETE FROM parent where pk = 2;",
|
||||
"CALL DOLT_COMMIT('-am', 'updating col1 to 2 and remove pk = 2');",
|
||||
"CALL DOLT_CHECKOUT('other');",
|
||||
"UPDATE parent SET col1 = 3 where pk = 1;",
|
||||
"INSERT into child VALUEs (1, 2);",
|
||||
"CALL DOLT_COMMIT('-am', 'updating col1 to 3 and adding child of pk 2');",
|
||||
"CALL DOLT_CHECKOUT('other2')",
|
||||
"UPDATE parent SET col1 = 4 where pk = 1",
|
||||
"CALL DOLT_COMMIT('-am', 'updating col1 to 4');",
|
||||
"CALL DOLT_CHECKOUT('main');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SET dolt_force_transaction_commit = 1",
|
||||
Expected: []sql.Row{{types.NewOkResult(0)}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('other');",
|
||||
Expected: []sql.Row{{"", 0, 1, "conflicts found"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from parent;",
|
||||
Expected: []sql.Row{{1, 2}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from child;",
|
||||
Expected: []sql.Row{{1, 2}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT base_col1, base_pk, our_col1, our_pk, their_col1, their_pk from dolt_conflicts_parent;",
|
||||
Expected: []sql.Row{{1, 1, 2, 1, 3, 1}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;",
|
||||
Expected: []sql.Row{{uint16(1), 1, 2}},
|
||||
},
|
||||
// commit so we can merge again
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-afm', 'committing merge conflicts');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('other2');",
|
||||
ExpectedErrStr: "existing unresolved conflicts would be overridden by new conflicts produced by merge. Please resolve them and try again",
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from parent;",
|
||||
Expected: []sql.Row{{1, 2}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from child;",
|
||||
Expected: []sql.Row{{1, 2}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT base_col1, base_pk, our_col1, our_pk, their_col1, their_pk from dolt_conflicts_parent;",
|
||||
Expected: []sql.Row{{1, 1, 2, 1, 3, 1}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;",
|
||||
Expected: []sql.Row{{uint16(1), 1, 2}},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "non-conflicting / non-violating merge succeeds when conflicts and violations already exist",
|
||||
SetUpScript: []string{
|
||||
"CREATE table parent (pk int PRIMARY KEY, col1 int);",
|
||||
"CREATE table child (pk int PRIMARY KEY, parent_fk int, FOREIGN KEY (parent_fk) REFERENCES parent(pk));",
|
||||
"CALL DOLT_ADD('.')",
|
||||
"INSERT INTO parent VALUES (1, 1), (2, 1);",
|
||||
"CALL DOLT_COMMIT('-am', 'create table with data');",
|
||||
"CALL DOLT_BRANCH('other');",
|
||||
"CALL DOLT_BRANCH('other2');",
|
||||
"UPDATE parent SET col1 = 2 where pk = 1;",
|
||||
"DELETE FROM parent where pk = 2;",
|
||||
"CALL DOLT_COMMIT('-am', 'updating col1 to 2 and remove pk = 2');",
|
||||
"CALL DOLT_CHECKOUT('other');",
|
||||
"UPDATE parent SET col1 = 3 where pk = 1;",
|
||||
"INSERT into child VALUES (1, 2);",
|
||||
"CALL DOLT_COMMIT('-am', 'updating col1 to 3 and adding child of pk 2');",
|
||||
"CALL DOLT_CHECKOUT('other2')",
|
||||
"INSERT INTO parent values (3, 1);",
|
||||
"CALL DOLT_COMMIT('-am', 'insert parent with pk 3');",
|
||||
"CALL DOLT_CHECKOUT('main');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SET dolt_force_transaction_commit = 1;",
|
||||
Expected: []sql.Row{{types.NewOkResult(0)}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('other');",
|
||||
Expected: []sql.Row{{"", 0, 1, "conflicts found"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from parent;",
|
||||
Expected: []sql.Row{{1, 2}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from child;",
|
||||
Expected: []sql.Row{{1, 2}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT base_col1, base_pk, our_col1, our_pk, their_col1, their_pk from dolt_conflicts_parent;",
|
||||
Expected: []sql.Row{{1, 1, 2, 1, 3, 1}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;",
|
||||
Expected: []sql.Row{{uint16(1), 1, 2}},
|
||||
},
|
||||
// commit so we can merge again
|
||||
{
|
||||
Query: "CALL DOLT_COMMIT('-afm', 'committing merge conflicts');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('other2');",
|
||||
Expected: []sql.Row{{"", 0, 1, "conflicts found"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from parent;",
|
||||
Expected: []sql.Row{{1, 2}, {3, 1}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from child;",
|
||||
Expected: []sql.Row{{1, 2}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT base_col1, base_pk, our_col1, our_pk, their_col1, their_pk from dolt_conflicts_parent;",
|
||||
Expected: []sql.Row{{1, 1, 2, 1, 3, 1}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;",
|
||||
Expected: []sql.Row{{uint16(1), 1, 2}},
|
||||
},
|
||||
},
|
||||
},
|
||||
// Unique key violations
|
||||
{
|
||||
Name: "unique key violations that already exist in the left abort the merge with an error",
|
||||
SetUpScript: []string{
|
||||
"SET dolt_force_transaction_commit = on;",
|
||||
"CREATE TABLE t (pk int PRIMARY KEY, col1 int);",
|
||||
"CALL DOLT_ADD('.')",
|
||||
"CALL DOLT_COMMIT('-am', 'table');",
|
||||
"CALL DOLT_BRANCH('right');",
|
||||
"INSERT INTO t VALUES (1, 1), (2, 1);",
|
||||
"CALL DOLT_COMMIT('-am', 'data');",
|
||||
|
||||
"CALL DOLT_CHECKOUT('right');",
|
||||
"ALTER TABLE t ADD UNIQUE col1_uniq (col1);",
|
||||
"CALL DOLT_COMMIT('-am', 'unqiue constraint');",
|
||||
|
||||
"CALL DOLT_CHECKOUT('main');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('right');",
|
||||
ExpectedErrStr: "duplicate unique key given: [1]",
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from t",
|
||||
Expected: []sql.Row{{1, 1}, {2, 1}},
|
||||
},
|
||||
{
|
||||
Query: "show create table t",
|
||||
Expected: []sql.Row{{"t",
|
||||
"CREATE TABLE `t` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `col1` int,\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
// not a base case, but helpful to understand...
|
||||
{
|
||||
Name: "right adds a unique key constraint and fixes existing violations. On merge, because left still has the violation, merge is aborted.",
|
||||
SetUpScript: []string{
|
||||
"SET dolt_force_transaction_commit = on;",
|
||||
"CREATE TABLE t (pk int PRIMARY KEY, col1 int);",
|
||||
"CALL DOLT_ADD('.');",
|
||||
"INSERT INTO t VALUES (1, 1), (2, 1);",
|
||||
"CALL DOLT_COMMIT('-am', 'table and data');",
|
||||
|
||||
"CALL DOLT_CHECKOUT('-b', 'right');",
|
||||
"UPDATE t SET col1 = 2 where pk = 2;",
|
||||
"ALTER TABLE t ADD UNIQUE col1_uniq (col1);",
|
||||
"CALL DOLT_COMMIT('-am', 'right adds a unique index');",
|
||||
|
||||
"CALL DOLT_CHECKOUT('main');",
|
||||
"INSERT INTO t VALUES (3, 3);",
|
||||
"CALL DOLT_COMMIT('-am', 'left edit');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "CALL DOLT_MERGE('right');",
|
||||
ExpectedErrStr: "duplicate unique key given: [1]",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var GeneratedColumnMergeTestScripts = []queries.ScriptTest{
|
||||
{
|
||||
Name: "merge a generated stored column",
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
|
||||
"github.com/dolthub/dolt/go/store/prolly"
|
||||
"github.com/dolthub/dolt/go/store/prolly/tree"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
"github.com/dolthub/dolt/go/store/val"
|
||||
)
|
||||
|
||||
@@ -46,9 +45,6 @@ func ValidateDatabase(ctx context.Context, db sql.Database) (err error) {
|
||||
}
|
||||
|
||||
func ValidateDoltDatabase(ctx context.Context, db sqle.Database) (err error) {
|
||||
if !types.IsFormat_DOLT(db.GetDoltDB().Format()) {
|
||||
return nil
|
||||
}
|
||||
for _, stage := range validationStages {
|
||||
if err = stage(ctx, db); err != nil {
|
||||
return err
|
||||
@@ -137,10 +133,10 @@ func validateSecondaryIndexes(ctx context.Context, db sqle.Database) error {
|
||||
}
|
||||
|
||||
func validateIndexConsistency(
|
||||
ctx context.Context,
|
||||
sch schema.Schema,
|
||||
def schema.Index,
|
||||
primary, secondary prolly.MapInterface,
|
||||
ctx context.Context,
|
||||
sch schema.Schema,
|
||||
def schema.Index,
|
||||
primary, secondary prolly.MapInterface,
|
||||
) error {
|
||||
if schema.IsKeyless(sch) {
|
||||
return validateKeylessIndex(ctx, sch, def, primary, secondary)
|
||||
@@ -489,9 +485,9 @@ func ordinalMappingsForSecondaryIndex(sch schema.Schema, def schema.Index) (ord
|
||||
|
||||
// iterDatabaseTables is a utility to factor out common validation access patterns.
|
||||
func iterDatabaseTables(
|
||||
ctx context.Context,
|
||||
db sqle.Database,
|
||||
cb func(name doltdb.TableName, t *doltdb.Table, sch schema.Schema) (bool, error),
|
||||
ctx context.Context,
|
||||
db sqle.Database,
|
||||
cb func(name doltdb.TableName, t *doltdb.Table, sch schema.Schema) (bool, error),
|
||||
) error {
|
||||
ddb := db.GetDoltDB()
|
||||
branches, err := ddb.GetBranches(ctx)
|
||||
|
||||
@@ -1090,20 +1090,12 @@ func (t *WritableDoltTable) truncate(
|
||||
}
|
||||
|
||||
func copyConstraintViolationsAndConflicts(ctx context.Context, from, to *doltdb.Table) (*doltdb.Table, error) {
|
||||
if types.IsFormat_DOLT(to.Format()) {
|
||||
arts, err := from.GetArtifacts(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
to, err = to.SetArtifacts(ctx, arts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
panic("Unsupported format: " + to.Format().VersionString())
|
||||
types.AssertFormat_DOLT(to.Format())
|
||||
arts, err := from.GetArtifacts(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return to, nil
|
||||
return to.SetArtifacts(ctx, arts)
|
||||
}
|
||||
|
||||
// Updater implements sql.UpdatableTable
|
||||
@@ -2424,9 +2416,8 @@ func (t *AlterableDoltTable) RenameIndex(ctx *sql.Context, fromIndexName string,
|
||||
|
||||
// CreateFulltextIndex implements fulltext.IndexAlterableTable
|
||||
func (t *AlterableDoltTable) CreateFulltextIndex(ctx *sql.Context, idx sql.IndexDef, keyCols fulltext.KeyColumns, tableNames fulltext.IndexTableNames) error {
|
||||
if !types.IsFormat_DOLT(t.Format()) {
|
||||
return fmt.Errorf("FULLTEXT is not supported on storage format %s. Run `dolt migrate` to upgrade to the latest storage format.", t.Format().VersionString())
|
||||
}
|
||||
types.AssertFormat_DOLT(t.Format())
|
||||
|
||||
if err := dsess.CheckAccessForDb(ctx, t.db, branch_control.Permissions_Write); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user