mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-15 02:52:55 -05:00
Diff summary for new format
This commit is contained in:
@@ -403,7 +403,7 @@ func diffUserTables(ctx context.Context, dEnv *env.DoltEnv, dArgs *diffArgs) (ve
|
||||
|
||||
if dArgs.diffParts&Summary != 0 {
|
||||
numCols := fromSch.GetAllCols().Size()
|
||||
verr = diffSummary(ctx, td, numCols)
|
||||
verr = printNomsDiffSummary(ctx, td, numCols)
|
||||
}
|
||||
|
||||
if dArgs.diffParts&SchemaOnlyDiff != 0 {
|
||||
@@ -836,7 +836,7 @@ func printTableDiffSummary(td diff.TableDelta) {
|
||||
}
|
||||
}
|
||||
|
||||
func diffSummary(ctx context.Context, td diff.TableDelta, colLen int) errhand.VerboseError {
|
||||
func printNomsDiffSummary(ctx context.Context, td diff.TableDelta, colLen int) errhand.VerboseError {
|
||||
// todo: use errgroup.Group
|
||||
ae := atomicerr.New()
|
||||
ch := make(chan diff.DiffSummaryProgress)
|
||||
|
||||
@@ -103,6 +103,7 @@ func nomsSummary(ctx context.Context, ch chan DiffSummaryProgress, from, to dura
|
||||
return nil
|
||||
}
|
||||
|
||||
// SummaryForTableDelta pushes diff summary progress messages for the table delta given to the channel given
|
||||
func SummaryForTableDelta(ctx context.Context, ch chan DiffSummaryProgress, td TableDelta) error {
|
||||
fromSch, toSch, err := td.GetSchemas(ctx)
|
||||
if err != nil {
|
||||
@@ -118,23 +119,50 @@ func SummaryForTableDelta(ctx context.Context, ch chan DiffSummaryProgress, td T
|
||||
return err
|
||||
}
|
||||
|
||||
fromRows, toRows, err := td.GetMaps(ctx)
|
||||
fromRows, toRows, err := td.GetRowData(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if types.IsFormat_DOLT_1(td.Format()) {
|
||||
if keyless {
|
||||
return fmt.Errorf("keyless diff not supported for format %s", td.Format().VersionString())
|
||||
}
|
||||
return diffProllyTrees(ctx, ch, durable.ProllyMapFromIndex(fromRows), durable.ProllyMapFromIndex(toRows))
|
||||
} else {
|
||||
return diffNomsMaps(ctx, ch, keyless, fromRows, toRows)
|
||||
}
|
||||
}
|
||||
|
||||
func diffNomsMaps(ctx context.Context, ch chan DiffSummaryProgress, keyless bool, fromRows durable.Index, toRows durable.Index) error {
|
||||
var rpr reporter
|
||||
if keyless {
|
||||
rpr = reportKeylessChanges
|
||||
} else {
|
||||
rpr = reportNomsPkChanges
|
||||
ch <- DiffSummaryProgress{
|
||||
OldSize: fromRows.Len(),
|
||||
NewSize: toRows.Len(),
|
||||
OldSize: fromRows.Count(),
|
||||
NewSize: toRows.Count(),
|
||||
}
|
||||
}
|
||||
|
||||
return summaryWithReporter(ctx, ch, fromRows, toRows, rpr)
|
||||
return summaryWithReporter(ctx, ch, durable.NomsMapFromIndex(fromRows), durable.NomsMapFromIndex(toRows), rpr)
|
||||
}
|
||||
|
||||
func diffProllyTrees(ctx context.Context, ch chan DiffSummaryProgress, from, to prolly.Map) error {
|
||||
diffSummary, err := prolly.DiffMapSummary(ctx, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ch <- DiffSummaryProgress{
|
||||
Adds: diffSummary.Adds,
|
||||
Removes: diffSummary.Removes,
|
||||
Changes: diffSummary.Changes,
|
||||
CellChanges: diffSummary.CellChanges,
|
||||
NewSize: diffSummary.NewSize,
|
||||
OldSize: diffSummary.OldSize,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func summaryWithReporter(ctx context.Context, ch chan DiffSummaryProgress, from, to types.Map, rpr reporter) (err error) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb/durable"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/set"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
@@ -309,6 +310,14 @@ func (td TableDelta) GetSchemas(ctx context.Context) (from, to schema.Schema, er
|
||||
return td.FromSch, td.ToSch, nil
|
||||
}
|
||||
|
||||
// Format returns the format of the tables in this delta.
|
||||
func (td TableDelta) Format() *types.NomsBinFormat {
|
||||
if td.FromTable != nil {
|
||||
return td.FromTable.Format()
|
||||
}
|
||||
return td.ToTable.Format()
|
||||
}
|
||||
|
||||
func (td TableDelta) IsKeyless(ctx context.Context) (bool, error) {
|
||||
f, t, err := td.GetSchemas(ctx)
|
||||
if err != nil {
|
||||
@@ -326,7 +335,8 @@ func (td TableDelta) IsKeyless(ctx context.Context) (bool, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetMaps returns the table's row map at the fromRoot and toRoot, or and empty map if the table did not exist.
|
||||
// GetMaps returns the table's row map at the fromRoot and toRoot, or an empty map if the table did not exist.
|
||||
// Deprecated: only compatible with LD1 storage format. Use GetRowData instead
|
||||
func (td TableDelta) GetMaps(ctx context.Context) (from, to types.Map, err error) {
|
||||
if td.FromTable != nil {
|
||||
from, err = td.FromTable.GetNomsRowData(ctx)
|
||||
@@ -349,6 +359,31 @@ func (td TableDelta) GetMaps(ctx context.Context) (from, to types.Map, err error
|
||||
return from, to, nil
|
||||
}
|
||||
|
||||
// GetRowData returns the table's row data at the fromRoot and toRoot, or an empty map if the table did not exist.
|
||||
func (td TableDelta) GetRowData(ctx context.Context) (from, to durable.Index, err error) {
|
||||
if td.FromTable != nil {
|
||||
from, err = td.FromTable.GetRowData(ctx)
|
||||
if err != nil {
|
||||
return from, to, err
|
||||
}
|
||||
} else {
|
||||
// TODO: need a different schema here?
|
||||
from, _ = durable.NewEmptyIndex(ctx, td.ToTable.ValueReadWriter(), td.FromSch)
|
||||
}
|
||||
|
||||
if td.ToTable != nil {
|
||||
to, err = td.ToTable.GetRowData(ctx)
|
||||
if err != nil {
|
||||
return from, to, err
|
||||
}
|
||||
} else {
|
||||
// TODO: need a different schema here?
|
||||
to, _ = durable.NewEmptyIndex(ctx, td.FromTable.ValueReadWriter(), td.ToSch)
|
||||
}
|
||||
|
||||
return from, to, nil
|
||||
}
|
||||
|
||||
func fkSlicesAreEqual(from, to []doltdb.ForeignKey) bool {
|
||||
if len(from) != len(to) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user