Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for dolt_patch #6367

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading