diff

package
v0.40.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	From = "from"
	To   = "to"
)
View Source
const (
	// DiffTypeProp is the name of a property added to each split row which tells if its added, removed, the modified
	// old value, or the new value after modification
	DiffTypeProp = "difftype"

	// CollChangesProp is the name of a property added to each modified row which is a map from collumn name to the
	// type of change.
	CollChangesProp = "collchanges"
)

Variables

This section is empty.

Functions

func ColoringTransform

func ColoringTransform(r row.Row, props pipeline.ReadableMap) ([]*pipeline.TransformedRowResult, string)

Unused, color logic moved to ColorDiffSink. Still handy.

func DiffSchColumns

func DiffSchColumns(fromSch, toSch schema.Schema) (map[uint64]ColumnDifference, []uint64)

DiffSchColumns compares two schemas by looking at columns with the same tag.

func DocsDiff

func DocsDiff(ctx context.Context, root *doltdb.RootValue, other *doltdb.RootValue, docs doltdocs.Docs) (added, modified, removed []string, err error)

DocsDiff returns the added, modified and removed docs when comparing a root value with an other (newer) value. If the other value, is not provided, then we compare the docs on the root value to the docs provided.

func DocsDiffToComparisons

func DocsDiffToComparisons(ctx context.Context, root *doltdb.RootValue, other *doltdb.RootValue, docs doltdocs.Docs) ([]docComparison, error)

DocsDiffToComparisons returns the docComparisons between an old root, a new root, and a set of docs. It is exported due to the cli usage of doc diffs.

func FromColNamer

func FromColNamer(name string) string

func GetDocDiffs

func GetDocDiffs(
	ctx context.Context,
	roots doltdb.Roots,
	docsOnDisk doltdocs.Docs,
) (*DocDiffs, *DocDiffs, error)

GetDocDiffs retrieves staged and unstaged DocDiffs.

func Summary

func Summary(ctx context.Context, ch chan DiffSummaryProgress, from, to types.Map) (err error)

todo: make package private once dolthub is migrated Summary reports a summary of diff changes between two values Summary reports a summary of diff changes between two values

func SummaryForTableDelta

func SummaryForTableDelta(ctx context.Context, ch chan DiffSummaryProgress, td TableDelta) error

func ToColNamer

func ToColNamer(name string) string

Types

type AsyncDiffer

type AsyncDiffer struct {
	// contains filtered or unexported fields
}

todo: make package private

func NewAsyncDiffer

func NewAsyncDiffer(bufferedDiffs int) *AsyncDiffer

todo: make package private once dolthub is migrated

func (*AsyncDiffer) Close

func (ad *AsyncDiffer) Close() error

func (*AsyncDiffer) GetDiffs

func (ad *AsyncDiffer) GetDiffs(numDiffs int, timeout time.Duration) ([]*diff.Difference, bool, error)

func (*AsyncDiffer) GetDiffsWithFilter

func (ad *AsyncDiffer) GetDiffsWithFilter(numDiffs int, timeout time.Duration, filterByChangeType types.DiffChangeType) ([]*diff.Difference, bool, error)

func (*AsyncDiffer) GetDiffsWithoutTimeout

func (ad *AsyncDiffer) GetDiffsWithoutTimeout(numDiffs int) ([]*diff.Difference, bool, error)

func (*AsyncDiffer) GetDiffsWithoutTimeoutWithFilter

func (ad *AsyncDiffer) GetDiffsWithoutTimeoutWithFilter(numDiffs int, filterByChangeType types.DiffChangeType) ([]*diff.Difference, bool, error)

func (*AsyncDiffer) Start

func (ad *AsyncDiffer) Start(ctx context.Context, from, to types.Map)

func (*AsyncDiffer) StartWithRange

func (ad *AsyncDiffer) StartWithRange(ctx context.Context, from, to types.Map, start types.Value, inRange types.ValueInRange)

type ColorDiffSink

type ColorDiffSink struct {
	// contains filtered or unexported fields
}

func NewColorDiffSink

func NewColorDiffSink(wr io.WriteCloser, sch schema.Schema, numHeaderRows int) (*ColorDiffSink, error)

NewColorDiffSink returns a ColorDiffSink that uses the writer and schema given to print its output. numHeaderRows will change how many rows of output are considered part of the table header. Use 1 for diffs where the schemas are the same between the two table revisions, and 2 for when they differ.

func (*ColorDiffSink) Close

func (cds *ColorDiffSink) Close() error

Close should release resources being held

func (*ColorDiffSink) GetSchema

func (cds *ColorDiffSink) GetSchema() schema.Schema

GetSchema gets the schema of the rows that this writer writes

func (*ColorDiffSink) ProcRowWithProps

func (cds *ColorDiffSink) ProcRowWithProps(r row.Row, props pipeline.ReadableMap) error

type ColorFunc

type ColorFunc func(...interface{}) string

type ColumnDifference

type ColumnDifference struct {
	DiffType SchemaChangeType
	Tag      uint64
	Old      *schema.Column
	New      *schema.Column
}

ColumnDifference is the result of comparing two columns from two schemas.

type DiffChType

type DiffChType int

DiffChType is an enum that represents the type of change

const (
	// DiffAdded is the DiffTypeProp value for a row that was newly added (In new, but not in old)
	DiffAdded DiffChType = iota

	// DiffRemoved is the DiffTypeProp value for a row that was newly deleted (In old, but not in new)
	DiffRemoved

	// DiffModifiedOld is the DiffTypeProp value for the row which represents the old value of the row before it was changed.
	DiffModifiedOld

	// DiffModifiedNew is the DiffTypeProp value for the row which represents the new value of the row after it was changed.
	DiffModifiedNew
)

type DiffRow

type DiffRow struct {
	row.Row
	// contains filtered or unexported fields
}

DiffRow is a row.Row with a change type associated with it.

func (*DiffRow) DiffType

func (dr *DiffRow) DiffType() DiffChType

DiffType gets the DiffChType for the row.

type DiffSplitter

type DiffSplitter struct {
	// contains filtered or unexported fields
}

DiffSplitter is a struct that can take a diff which is represented by a row with a column for every field in the old version, and a column for every field in the new version and split it into two rows with properties which annotate what each row is. This is used to show diffs as 2 lines, instead of 1.

func NewDiffSplitter

func NewDiffSplitter(joiner *rowconv.Joiner, oldConv, newConv *rowconv.RowConverter) *DiffSplitter

NewDiffSplitter creates a DiffSplitter

func (*DiffSplitter) SplitDiffIntoOldAndNew

func (ds *DiffSplitter) SplitDiffIntoOldAndNew(inRow row.Row, props pipeline.ReadableMap) (rowData []*pipeline.TransformedRowResult, badRowDetails string)

SplitDiffIntoOldAndNew is a pipeline.TransformRowFunc which can be used in a pipeline to split single row diffs, into 2 row diffs.

type DiffSummaryProgress

type DiffSummaryProgress struct {
	Adds, Removes, Changes, CellChanges, NewSize, OldSize uint64
}

type DiffTyped

type DiffTyped interface {
	// DiffType gets the DiffChType of an object
	DiffType() DiffChType
}

DiffTyped is an interface for an object that has a DiffChType

type DocDiffType

type DocDiffType int
const (
	AddedDoc DocDiffType = iota
	ModifiedDoc
	RemovedDoc
)

type DocDiffs

type DocDiffs struct {
	NumAdded    int
	NumModified int
	NumRemoved  int
	DocToType   map[string]DocDiffType
	Docs        []string
}

func NewDocDiffs

func NewDocDiffs(ctx context.Context, older *doltdb.RootValue, newer *doltdb.RootValue, docs doltdocs.Docs) (*DocDiffs, error)

NewDocDiffs returns DocDiffs for Dolt Docs between two roots.

func (*DocDiffs) Len

func (nd *DocDiffs) Len() int

Len returns the number of docs in a DocDiffs

type EmptyRowDiffer

type EmptyRowDiffer struct {
}

func (EmptyRowDiffer) Close

func (e EmptyRowDiffer) Close() error

func (EmptyRowDiffer) GetDiffs

func (e EmptyRowDiffer) GetDiffs(numDiffs int, timeout time.Duration) ([]*diff.Difference, bool, error)

func (EmptyRowDiffer) GetDiffsWithFilter

func (e EmptyRowDiffer) GetDiffsWithFilter(numDiffs int, timeout time.Duration, filterByChangeType types.DiffChangeType) ([]*diff.Difference, bool, error)

func (EmptyRowDiffer) Start

func (e EmptyRowDiffer) Start(ctx context.Context, from, to types.Map)

type ForeignKeyDifference

type ForeignKeyDifference struct {
	DiffType SchemaChangeType
	From     doltdb.ForeignKey
	To       doltdb.ForeignKey
}

func DiffForeignKeys

func DiffForeignKeys(fromFks, toFKs []doltdb.ForeignKey) (diffs []ForeignKeyDifference)

DiffForeignKeys matches two sets of ForeignKeys based on column definitions. It returns matched and unmatched ForeignKeys as a slice of ForeignKeyDifferences.

type IndexDifference

type IndexDifference struct {
	DiffType SchemaChangeType
	From     schema.Index
	To       schema.Index
}

func DiffSchIndexes

func DiffSchIndexes(fromSch, toSch schema.Schema) (diffs []IndexDifference)

DiffSchIndexes matches two sets of Indexes based on column definitions. It returns matched and unmatched Indexes as a slice of IndexDifferences.

type RowDiffSource

type RowDiffSource struct {
	// contains filtered or unexported fields
}

func NewRowDiffSource

func NewRowDiffSource(ad RowDiffer, joiner *rowconv.Joiner, warnFn rowconv.WarnFunction) *RowDiffSource

func (*RowDiffSource) AddInputRowConversion

func (rdRd *RowDiffSource) AddInputRowConversion(oldConv, newConv *rowconv.RowConverter)

func (*RowDiffSource) Close

func (rdRd *RowDiffSource) Close() error

Close should release resources being held

func (*RowDiffSource) GetSchema

func (rdRd *RowDiffSource) GetSchema() schema.Schema

GetSchema gets the schema of the rows that this reader will return

func (*RowDiffSource) NextDiff

func (rdRd *RowDiffSource) NextDiff() (row.Row, pipeline.ImmutableProperties, error)

NextDiff reads a row from a table. If there is a bad row the returned error will be non nil, and calling IsBadRow(err) will be return true. This is a potentially non-fatal error and callers can decide if they want to continue on a bad row, or fail.

type RowDiffer

type RowDiffer interface {
	// Start starts the RowDiffer.
	Start(ctx context.Context, from, to types.Map)

	// GetDiffs returns the requested number of diff.Differences, or times out.
	GetDiffs(numDiffs int, timeout time.Duration) ([]*diff.Difference, bool, error)

	// GetDiffsWithFilter returns the requested number of filtered diff.Differences, or times out.
	GetDiffsWithFilter(numDiffs int, timeout time.Duration, filterByChangeType types.DiffChangeType) ([]*diff.Difference, bool, error)

	// Close closes the RowDiffer.
	Close() error
}

func NewRowDiffer

func NewRowDiffer(ctx context.Context, fromSch, toSch schema.Schema, buf int) RowDiffer

type SQLDiffSink

type SQLDiffSink struct {
	// contains filtered or unexported fields
}

func NewSQLDiffSink

func NewSQLDiffSink(wr io.WriteCloser, sch schema.Schema, tableName string) (*SQLDiffSink, error)

NewSQLDiffSink creates a SQLDiffSink for a diff pipeline.

func (*SQLDiffSink) Close

func (sds *SQLDiffSink) Close() error

Close should release resources being held

func (*SQLDiffSink) GetSchema

func (sds *SQLDiffSink) GetSchema() schema.Schema

GetSchema gets the schema that the SQLDiffSink was created with.

func (*SQLDiffSink) ProcRowForExport

func (sds *SQLDiffSink) ProcRowForExport(r row.Row, _ pipeline.ReadableMap) error

ProcRowWithProps satisfies pipeline.SinkFunc; it writes rows as SQL statements.

func (*SQLDiffSink) ProcRowWithProps

func (sds *SQLDiffSink) ProcRowWithProps(r row.Row, props pipeline.ReadableMap) error

ProcRowWithProps satisfies pipeline.SinkFunc; it writes SQL diff statements to output.

type SchemaChangeType

type SchemaChangeType int
const (
	// SchDiffNone is the SchemaChangeType for two columns with the same tag that are identical
	SchDiffNone SchemaChangeType = iota
	// SchDiffAdded is the SchemaChangeType when a column is in the new schema but not the old
	SchDiffAdded
	// SchDiffRemoved is the SchemaChangeType when a column is in the old schema but not the new
	SchDiffRemoved
	// SchDiffModified is the SchemaChangeType for two columns with the same tag that are different
	SchDiffModified
)

type TableDelta

type TableDelta struct {
	FromName         string
	ToName           string
	FromTable        *doltdb.Table
	ToTable          *doltdb.Table
	FromSch          schema.Schema
	ToSch            schema.Schema
	FromFks          []doltdb.ForeignKey
	ToFks            []doltdb.ForeignKey
	ToFksParentSch   map[string]schema.Schema
	FromFksParentSch map[string]schema.Schema
}

TableDelta represents the change of a single table between two roots. FromFKs and ToFKs contain Foreign Keys that constrain columns in this table, they do not contain Foreign Keys that reference this table.

func GetStagedUnstagedTableDeltas

func GetStagedUnstagedTableDeltas(ctx context.Context, roots doltdb.Roots) (staged, unstaged []TableDelta, err error)

GetStagedUnstagedTableDeltas represents staged and unstaged changes as TableDelta slices.

func GetTableDeltas

func GetTableDeltas(ctx context.Context, fromRoot, toRoot *doltdb.RootValue) (deltas []TableDelta, err error)

GetTableDeltas returns a slice of TableDelta objects for each table that changed between fromRoot and toRoot. It matches tables across roots by finding Schemas with Column tags in common.

func (TableDelta) CurName

func (td TableDelta) CurName() string

CurName returns the most recent name of the table.

func (TableDelta) GetMaps

func (td TableDelta) GetMaps(ctx context.Context) (from, to types.Map, err error)

GetMaps returns the table's row map at the fromRoot and toRoot, or and empty map if the table did not exist.

func (TableDelta) GetSchemas

func (td TableDelta) GetSchemas(ctx context.Context) (from, to schema.Schema, err error)

GetSchemas returns the table's schema at the fromRoot and toRoot, or schema.Empty if the table did not exist.

func (TableDelta) HasChanges

func (td TableDelta) HasChanges() (bool, error)

func (TableDelta) HasFKChanges

func (td TableDelta) HasFKChanges() bool

func (TableDelta) HasHashChanged

func (td TableDelta) HasHashChanged() (bool, error)

func (TableDelta) HasPrimaryKeySetChanged

func (td TableDelta) HasPrimaryKeySetChanged() bool

func (TableDelta) IsAdd

func (td TableDelta) IsAdd() bool

IsAdd returns true if the table was added between the fromRoot and toRoot.

func (TableDelta) IsDrop

func (td TableDelta) IsDrop() bool

IsDrop returns true if the table was dropped between the fromRoot and toRoot.

func (TableDelta) IsKeyless

func (td TableDelta) IsKeyless(ctx context.Context) (bool, error)

func (TableDelta) IsRename

func (td TableDelta) IsRename() bool

IsRename return true if the table was renamed between the fromRoot and toRoot.

type TableDiffType

type TableDiffType int
const (
	AddedTable TableDiffType = iota
	ModifiedTable
	RenamedTable
	RemovedTable
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL