Skip to content

Commit

Permalink
Merge pull request #6367 from dolthub/fulghum/dolt_patch
Browse files Browse the repository at this point in the history
Bug fixes for `dolt_patch`
  • Loading branch information
fulghum authored Jul 21, 2023
2 parents 02b9bcd + 2b45c6b commit 1623798
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 67 deletions.
15 changes: 12 additions & 3 deletions go/libraries/doltcore/diff/diffsplitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ func mapQuerySchemaToTargetSchema(query, target sql.Schema) (mapping []int, err
} else {
return nil, errors.New("expected column prefix of 'to_' or 'from_' (" + col.Name + ")")
}
if mapping[i] < 0 { // sanity check
return nil, errors.New("failed to map diff column: " + col.Name)
}
}
return
}
Expand Down Expand Up @@ -163,6 +160,10 @@ func (ds DiffSplitter) SplitDiffResultRow(row sql.Row) (from, to RowDiff, err er
from.RowDiff = Removed
for i := 0; i < ds.splitIdx; i++ {
j := ds.queryToTarget[i]
// skip any columns that aren't mapped
if j < 0 {
continue
}
from.Row[j] = row[i]
from.ColDiffs[j] = Removed
}
Expand All @@ -172,6 +173,10 @@ func (ds DiffSplitter) SplitDiffResultRow(row sql.Row) (from, to RowDiff, err er
to.RowDiff = Added
for i := ds.splitIdx; i < len(row); i++ {
j := ds.queryToTarget[i]
// skip any columns that aren't mapped
if j < 0 {
continue
}
to.Row[j] = row[i]
to.ColDiffs[j] = Added
}
Expand All @@ -181,6 +186,10 @@ func (ds DiffSplitter) SplitDiffResultRow(row sql.Row) (from, to RowDiff, err er
from.RowDiff = ModifiedOld
for i := 0; i < ds.splitIdx; i++ {
j := ds.queryToTarget[i]
// skip any columns that aren't mapped
if j < 0 {
continue
}
from.Row[j] = row[i]
}
to.Row = make(sql.Row, len(ds.targetSch))
Expand Down
3 changes: 3 additions & 0 deletions go/libraries/doltcore/diff/table_deltas.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ func GetDataDiffStatement(tableName string, sch schema.Schema, row sql.Row, rowD
updatedCols.Add(sch.GetAllCols().GetByIndex(i).Name)
}
}
if updatedCols.Size() == 0 {
return "", nil
}
return sqlfmt.SqlRowAsUpdateStmt(row, tableName, sch, updatedCols)
case ModifiedOld:
// do nothing, we only issue UPDATE for ModifiedNew
Expand Down
18 changes: 8 additions & 10 deletions go/libraries/doltcore/sqle/dolt_patch_table_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,7 @@ func canGetDataDiff(ctx *sql.Context, td diff.TableDelta) bool {
})
return false
}
// cannot sql diff
if td.ToSch == nil || (td.FromSch != nil && !schema.SchemasAreEqual(td.FromSch, td.ToSch)) {
// TODO(8/24/22 Zach): this is overly broad, we can absolutely do better
ctx.Session.Warn(&sql.Warning{
Level: "Warning",
Code: mysql.ERNotSupportedYet,
Message: fmt.Sprintf("Incompatible schema change, skipping data diff for table '%s'", td.ToName),
})
return false
}

return true
}

Expand Down Expand Up @@ -574,6 +565,13 @@ func GetNonCreateNonDropTableSqlSchemaDiff(td diff.TableDelta, toSchemas map[str
}
}

// Handle charset/collation changes
toCollation := toSch.GetCollation()
fromCollation := fromSch.GetCollation()
if toCollation != fromCollation {
ddlStatements = append(ddlStatements, sqlfmt.AlterTableCollateStmt(td.ToName, fromCollation, toCollation))
}

return ddlStatements, nil
}

Expand Down
Loading

0 comments on commit 1623798

Please sign in to comment.