Skip to content

Commit

Permalink
patch with tag collision test (#8567)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Nov 15, 2024
1 parent 78627a2 commit 37985bf
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 3 deletions.
18 changes: 15 additions & 3 deletions go/libraries/doltcore/diff/table_deltas.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,21 @@ func matchTableDeltas(fromDeltas, toDeltas []TableDelta) (deltas []TableDelta) {
}

func schemasOverlap(from, to schema.Schema) bool {
f := set.NewUint64Set(from.GetAllCols().Tags)
t := set.NewUint64Set(to.GetAllCols().Tags)
return f.Intersection(t).Size() > 0
fromCols := from.GetAllCols()
toCols := to.GetAllCols()
fromColSet := set.NewUint64Set(fromCols.Tags)
toColSet := set.NewUint64Set(toCols.Tags)

overlappingTags := fromColSet.Intersection(toColSet)
numOverlaps := overlappingTags.Size()
for _, tag := range overlappingTags.AsSlice() {
fromCol, _ := fromCols.GetByTag(tag)
toCol, _ := toCols.GetByTag(tag)
if fromCol.Name != toCol.Name {
numOverlaps--
}
}
return numOverlaps > 0
}

// IsAdd returns true if the table was added between the fromRoot and toRoot.
Expand Down
99 changes: 99 additions & 0 deletions go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -3639,6 +3639,105 @@ var PatchTableFunctionScriptTests = []queries.ScriptTest{
},
},
},
{
Name: "tag collision",
SetUpScript: []string{
"CALL dolt_checkout('-b', 'other')",
"CREATE TABLE `MOTOR_TARIFA_COEFICIENTE_RIESGO_144_075_01` (\n" +
" `ID` varchar(8) NOT NULL,\n" +
" `PRODUCTO` varchar(255),\n" +
" `TARIFA` int,\n" +
" `VERSION_INICIO` int,\n" +
" `VERSION_FIN` int,\n" +
" `COBERTURA` varchar(255),\n" +
" `INDICADOR_NM` varchar(255),\n" +
" `ANOS_COMPANIA_PROCEDENCIA_MIN` int,\n" +
" `ANOS_COMPANIA_PROCEDENCIA_MAX` int,\n" +
" `COEFICIENTE` double,\n" +
" `DWB_IDENTITY` varchar(64),\n" +
" PRIMARY KEY (`ID`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
"CREATE TABLE `MOTOR_TARIFA_COEFICIENTE_RIESGO_144_075` (\n" +
" `ID` varchar(8) NOT NULL,\n" +
" `PRODUCTO` varchar(255),\n" +
" `TARIFA` int,\n" +
" `VERSION_INICIO` int,\n" +
" `VERSION_FIN` int,\n" +
" `COBERTURA` varchar(255),\n" +
" `INDICADOR_NM` varchar(255),\n" +
" `ANOS_COMPANIA_PROCEDENCIA_MIN` int,\n" +
" `ANOS_COMPANIA_PROCEDENCIA_MAX` int,\n" +
" `COEFICIENTE` double,\n" +
" `DWB_IDENTITY` varchar(64),\n" +
" PRIMARY KEY (`ID`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
"CALL dolt_commit('-A', '-m', 'create tables on other');",

"CALL dolt_checkout('main')",
"CREATE TABLE `MOTOR_TARIFA_COEFICIENTE_RIESGO_060` (\n" +
" `ID` varchar(8) NOT NULL,\n" +
" `PRODUCTO` varchar(255),\n" +
" `TARIFA` int,\n" +
" `VERSION_INICIO` int,\n" +
" `VERSION_FIN` int,\n" +
" `COBERTURA` varchar(255),\n" +
" `FRECUENCIA_PAGO` varchar(255),\n" +
" `COEFICIENTE` double,\n" +
" `DWB_IDENTITY` varchar(64),\n" +
" PRIMARY KEY (`ID`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
"CREATE TABLE `MOTOR_TARIFA_COEFICIENTE_RIESGO_060_01` (\n" +
" `ID` varchar(8) NOT NULL,\n" +
" `PRODUCTO` varchar(255),\n" +
" `TARIFA` int,\n" +
" `VERSION_INICIO` int,\n" +
" `VERSION_FIN` int,\n" +
" `COBERTURA` varchar(255),\n" +
" `FRECUENCIA_PAGO` varchar(255),\n" +
" `COEFICIENTE` double,\n" +
" `DWB_IDENTITY` varchar(64),\n" +
" PRIMARY KEY (`ID`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
"call dolt_commit('-A', '-m', 'create tables on main');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT statement FROM dolt_patch('main', 'other') ORDER BY statement_order",
Expected: []sql.Row{
{"DROP TABLE `MOTOR_TARIFA_COEFICIENTE_RIESGO_060`;"},
{"DROP TABLE `MOTOR_TARIFA_COEFICIENTE_RIESGO_060_01`;"},
{"CREATE TABLE `MOTOR_TARIFA_COEFICIENTE_RIESGO_144_075` (\n" +
" `ID` varchar(8) NOT NULL,\n" +
" `PRODUCTO` varchar(255),\n" +
" `TARIFA` int,\n" +
" `VERSION_INICIO` int,\n" +
" `VERSION_FIN` int,\n" +
" `COBERTURA` varchar(255),\n" +
" `INDICADOR_NM` varchar(255),\n" +
" `ANOS_COMPANIA_PROCEDENCIA_MIN` int,\n" +
" `ANOS_COMPANIA_PROCEDENCIA_MAX` int,\n" +
" `COEFICIENTE` double,\n" +
" `DWB_IDENTITY` varchar(64),\n" +
" PRIMARY KEY (`ID`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
{"CREATE TABLE `MOTOR_TARIFA_COEFICIENTE_RIESGO_144_075_01` (\n" +
" `ID` varchar(8) NOT NULL,\n" +
" `PRODUCTO` varchar(255),\n" +
" `TARIFA` int,\n" +
" `VERSION_INICIO` int,\n" +
" `VERSION_FIN` int,\n" +
" `COBERTURA` varchar(255),\n" +
" `INDICADOR_NM` varchar(255),\n" +
" `ANOS_COMPANIA_PROCEDENCIA_MIN` int,\n" +
" `ANOS_COMPANIA_PROCEDENCIA_MAX` int,\n" +
" `COEFICIENTE` double,\n" +
" `DWB_IDENTITY` varchar(64),\n" +
" PRIMARY KEY (`ID`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
},
},
},
},
}

var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{
Expand Down

0 comments on commit 37985bf

Please sign in to comment.