From 1317ea0bfadf2f010ea5b59045f593558015b443 Mon Sep 17 00:00:00 2001 From: James Cor Date: Tue, 30 Apr 2024 12:55:56 -0700 Subject: [PATCH 1/7] implement table-only diff --- go/cmd/dolt/commands/diff.go | 46 ++++++++++++++++++----------- go/cmd/dolt/commands/diff_output.go | 4 +++ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/go/cmd/dolt/commands/diff.go b/go/cmd/dolt/commands/diff.go index 3796b67aad0..eea1fe784c1 100644 --- a/go/cmd/dolt/commands/diff.go +++ b/go/cmd/dolt/commands/diff.go @@ -48,10 +48,11 @@ type diffOutput int type diffPart int const ( - SchemaOnlyDiff diffPart = 1 // 0b0001 - DataOnlyDiff diffPart = 2 // 0b0010 - Stat diffPart = 4 // 0b0100 - Summary diffPart = 8 // 0b1000 + SchemaOnlyDiff diffPart = 1 // 0b0000 0001 + DataOnlyDiff diffPart = 2 // 0b0000 0010 + TableOnlyDiff diffPart = 4 // 0b0000 0100 + Stat diffPart = 8 // 0b0000 1000 + Summary diffPart = 16 // 0b0001 0000 SchemaAndDataDiff = SchemaOnlyDiff | DataOnlyDiff @@ -59,16 +60,17 @@ const ( SQLDiffOutput diffOutput = 2 JsonDiffOutput diffOutput = 3 - DataFlag = "data" - SchemaFlag = "schema" - StatFlag = "stat" - SummaryFlag = "summary" - whereParam = "where" - limitParam = "limit" - SkinnyFlag = "skinny" - MergeBase = "merge-base" - DiffMode = "diff-mode" - ReverseFlag = "reverse" + DataFlag = "data" + SchemaFlag = "schema" + TableOnlyFlag = "table-only" + StatFlag = "stat" + SummaryFlag = "summary" + whereParam = "where" + limitParam = "limit" + SkinnyFlag = "skinny" + MergeBase = "merge-base" + DiffMode = "diff-mode" + ReverseFlag = "reverse" ) var diffDocs = cli.CommandDocumentationContent{ @@ -174,6 +176,7 @@ func (cmd DiffCmd) ArgParser() *argparser.ArgParser { ap.SupportsFlag(MergeBase, "", "Uses merge base of the first commit and second commit (or HEAD if not supplied) as the first commit") ap.SupportsString(DiffMode, "", "diff mode", "Determines how to display modified rows with tabular output. Valid values are row, line, in-place, context. Defaults to context.") ap.SupportsFlag(ReverseFlag, "R", "Reverses the direction of the diff.") + ap.SupportsFlag(TableOnlyFlag, "", "Only shows table names.") return ap } @@ -238,6 +241,8 @@ func parseDiffDisplaySettings(apr *argparser.ArgParseResults) *diffDisplaySettin displaySettings.diffParts = Stat } else if apr.Contains(SummaryFlag) { displaySettings.diffParts = Summary + } else if apr.Contains(TableOnlyFlag) { + displaySettings.diffParts = TableOnlyDiff } displaySettings.skinny = apr.Contains(SkinnyFlag) @@ -1034,9 +1039,11 @@ func diffUserTable( fromTable := tableSummary.FromTableName toTable := tableSummary.ToTableName - err := dw.BeginTable(tableSummary.FromTableName, tableSummary.ToTableName, tableSummary.IsAdd(), tableSummary.IsDrop()) - if err != nil { - return errhand.VerboseErrorFromError(err) + if dArgs.diffParts&TableOnlyDiff == 0 { + err := dw.BeginTable(tableSummary.FromTableName, tableSummary.ToTableName, tableSummary.IsAdd(), tableSummary.IsDrop()) + if err != nil { + return errhand.VerboseErrorFromError(err) + } } var fromTableInfo, toTableInfo *diff.TableInfo @@ -1055,6 +1062,11 @@ func diffUserTable( tableName = toTable } + if dArgs.diffParts&TableOnlyDiff != 0 { + cli.Println(tableName) + return errhand.VerboseErrorFromError(nil) + } + if dArgs.diffParts&Stat != 0 { var areTablesKeyless = false diff --git a/go/cmd/dolt/commands/diff_output.go b/go/cmd/dolt/commands/diff_output.go index 6465452d8b5..6e8e5359ece 100644 --- a/go/cmd/dolt/commands/diff_output.go +++ b/go/cmd/dolt/commands/diff_output.go @@ -71,6 +71,10 @@ func newDiffWriter(diffOutput diffOutput) (diffWriter, error) { } } +func printTableOnlyDiff(tableName string) { + cli.Println(tableName) +} + func printDiffStat(diffStats []diffStatistics, oldColLen, newColLen int, areTablesKeyless bool) errhand.VerboseError { acc := diff.DiffStatProgress{} var count int64 From d3a856a9c0ebb31065ef66b5479d502c3074f4ed Mon Sep 17 00:00:00 2001 From: James Cor Date: Tue, 30 Apr 2024 13:39:15 -0700 Subject: [PATCH 2/7] adding tests --- go/cmd/dolt/commands/diff.go | 6 ++++ go/cmd/dolt/commands/diff_output.go | 4 --- integration-tests/bats/diff.bats | 52 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/go/cmd/dolt/commands/diff.go b/go/cmd/dolt/commands/diff.go index eea1fe784c1..322f82f9d43 100644 --- a/go/cmd/dolt/commands/diff.go +++ b/go/cmd/dolt/commands/diff.go @@ -219,6 +219,12 @@ func (cmd DiffCmd) validateArgs(apr *argparser.ArgParseResults) errhand.VerboseE } } + if apr.Contains(TableOnlyFlag) { + if apr.Contains(SchemaFlag) || apr.Contains(DataFlag) || apr.Contains(StatFlag) || apr.Contains(SummaryFlag) { + return errhand.BuildDError("invalid Arguments: --table-only cannot be combined with --schema, --data, --stat, or --summary").Build() + } + } + f, _ := apr.GetValue(FormatFlag) switch strings.ToLower(f) { case "tabular", "sql", "json", "": diff --git a/go/cmd/dolt/commands/diff_output.go b/go/cmd/dolt/commands/diff_output.go index 6e8e5359ece..6465452d8b5 100644 --- a/go/cmd/dolt/commands/diff_output.go +++ b/go/cmd/dolt/commands/diff_output.go @@ -71,10 +71,6 @@ func newDiffWriter(diffOutput diffOutput) (diffWriter, error) { } } -func printTableOnlyDiff(tableName string) { - cli.Println(tableName) -} - func printDiffStat(diffStats []diffStatistics, oldColLen, newColLen int, areTablesKeyless bool) errhand.VerboseError { acc := diff.DiffStatProgress{} var count int64 diff --git a/integration-tests/bats/diff.bats b/integration-tests/bats/diff.bats index b1f734c78b3..d04e7d0b235 100644 --- a/integration-tests/bats/diff.bats +++ b/integration-tests/bats/diff.bats @@ -1709,3 +1709,55 @@ SQL [[ "$output" =~ "CREATE TRIGGER trigger1 BEFORE INSERT ON mytable FOR EACH ROW SET new.v1 = -2*new.v1;" ]] || false [[ "$output" =~ "CREATE VIEW view1 AS SELECT v1 FROM mytable;" ]] || false } + +@test "diff: table-only option" { + dolt sql < Date: Tue, 30 Apr 2024 13:46:00 -0700 Subject: [PATCH 3/7] adding false --- integration-tests/bats/diff.bats | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration-tests/bats/diff.bats b/integration-tests/bats/diff.bats index d04e7d0b235..14842615d04 100644 --- a/integration-tests/bats/diff.bats +++ b/integration-tests/bats/diff.bats @@ -1747,17 +1747,17 @@ SQL run dolt diff --table-only --schema [ $status -eq 1 ] - [[ $output =~ "invalid Arguments" ]] + [[ $output =~ "invalid Arguments" ]] || false run dolt diff --table-only --data [ $status -eq 1 ] - [[ $output =~ "invalid Arguments" ]] + [[ $output =~ "invalid Arguments" ]] || false run dolt diff --table-only --stat [ $status -eq 1 ] - [[ $output =~ "invalid Arguments" ]] + [[ $output =~ "invalid Arguments" ]] || false run dolt diff --table-only --summary [ $status -eq 1 ] - [[ $output =~ "invalid Arguments" ]] + [[ $output =~ "invalid Arguments" ]] || false } \ No newline at end of file From 266e110426289b73afbfb707879c9ac292420193 Mon Sep 17 00:00:00 2001 From: jycor Date: Tue, 30 Apr 2024 20:53:32 +0000 Subject: [PATCH 4/7] [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh --- go/cmd/dolt/cli/cli_context.go | 1 + 1 file changed, 1 insertion(+) diff --git a/go/cmd/dolt/cli/cli_context.go b/go/cmd/dolt/cli/cli_context.go index ce44b13c611..5e1bc23aa4b 100644 --- a/go/cmd/dolt/cli/cli_context.go +++ b/go/cmd/dolt/cli/cli_context.go @@ -17,6 +17,7 @@ package cli import ( "context" "errors" + "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/dolt/go/cmd/dolt/errhand" From 9678faa7c2f61d71dd8fe97a8c49cfb73ddde11b Mon Sep 17 00:00:00 2001 From: James Cor Date: Tue, 30 Apr 2024 14:05:23 -0700 Subject: [PATCH 5/7] rename to name only --- go/cmd/dolt/commands/diff.go | 10 +++++----- integration-tests/bats/diff.bats | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/go/cmd/dolt/commands/diff.go b/go/cmd/dolt/commands/diff.go index 322f82f9d43..fa90930fe1f 100644 --- a/go/cmd/dolt/commands/diff.go +++ b/go/cmd/dolt/commands/diff.go @@ -62,7 +62,7 @@ const ( DataFlag = "data" SchemaFlag = "schema" - TableOnlyFlag = "table-only" + NameOnlyFlag = "name-only" StatFlag = "stat" SummaryFlag = "summary" whereParam = "where" @@ -176,7 +176,7 @@ func (cmd DiffCmd) ArgParser() *argparser.ArgParser { ap.SupportsFlag(MergeBase, "", "Uses merge base of the first commit and second commit (or HEAD if not supplied) as the first commit") ap.SupportsString(DiffMode, "", "diff mode", "Determines how to display modified rows with tabular output. Valid values are row, line, in-place, context. Defaults to context.") ap.SupportsFlag(ReverseFlag, "R", "Reverses the direction of the diff.") - ap.SupportsFlag(TableOnlyFlag, "", "Only shows table names.") + ap.SupportsFlag(NameOnlyFlag, "", "Only shows table names.") return ap } @@ -219,9 +219,9 @@ func (cmd DiffCmd) validateArgs(apr *argparser.ArgParseResults) errhand.VerboseE } } - if apr.Contains(TableOnlyFlag) { + if apr.Contains(NameOnlyFlag) { if apr.Contains(SchemaFlag) || apr.Contains(DataFlag) || apr.Contains(StatFlag) || apr.Contains(SummaryFlag) { - return errhand.BuildDError("invalid Arguments: --table-only cannot be combined with --schema, --data, --stat, or --summary").Build() + return errhand.BuildDError("invalid Arguments: --name-only cannot be combined with --schema, --data, --stat, or --summary").Build() } } @@ -247,7 +247,7 @@ func parseDiffDisplaySettings(apr *argparser.ArgParseResults) *diffDisplaySettin displaySettings.diffParts = Stat } else if apr.Contains(SummaryFlag) { displaySettings.diffParts = Summary - } else if apr.Contains(TableOnlyFlag) { + } else if apr.Contains(NameOnlyFlag) { displaySettings.diffParts = TableOnlyDiff } diff --git a/integration-tests/bats/diff.bats b/integration-tests/bats/diff.bats index 14842615d04..be59754fd35 100644 --- a/integration-tests/bats/diff.bats +++ b/integration-tests/bats/diff.bats @@ -1738,26 +1738,26 @@ SQL [ "${lines[6]}" = "| t4 | added | false | true |" ] [ "${lines[7]}" = "+------------+-----------+-------------+---------------+" ] - run dolt diff --table-only + run dolt diff --name-only [ $status -eq 0 ] [ "${lines[0]}" = "t1" ] [ "${lines[1]}" = "t2" ] [ "${lines[2]}" = "t3" ] [ "${lines[3]}" = "t4" ] - run dolt diff --table-only --schema + run dolt diff --name-only --schema [ $status -eq 1 ] [[ $output =~ "invalid Arguments" ]] || false - run dolt diff --table-only --data + run dolt diff --name-only --data [ $status -eq 1 ] [[ $output =~ "invalid Arguments" ]] || false - run dolt diff --table-only --stat + run dolt diff --name-only --stat [ $status -eq 1 ] [[ $output =~ "invalid Arguments" ]] || false - run dolt diff --table-only --summary + run dolt diff --name-only --summary [ $status -eq 1 ] [[ $output =~ "invalid Arguments" ]] || false } \ No newline at end of file From 4a76f29a3abd37b1f91d64556941aae4d9490516 Mon Sep 17 00:00:00 2001 From: James Cor Date: Tue, 30 Apr 2024 14:06:44 -0700 Subject: [PATCH 6/7] missed some --- go/cmd/dolt/commands/diff.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/go/cmd/dolt/commands/diff.go b/go/cmd/dolt/commands/diff.go index fa90930fe1f..30da4c49800 100644 --- a/go/cmd/dolt/commands/diff.go +++ b/go/cmd/dolt/commands/diff.go @@ -50,7 +50,7 @@ type diffPart int const ( SchemaOnlyDiff diffPart = 1 // 0b0000 0001 DataOnlyDiff diffPart = 2 // 0b0000 0010 - TableOnlyDiff diffPart = 4 // 0b0000 0100 + NameOnlyDiff diffPart = 4 // 0b0000 0100 Stat diffPart = 8 // 0b0000 1000 Summary diffPart = 16 // 0b0001 0000 @@ -248,7 +248,7 @@ func parseDiffDisplaySettings(apr *argparser.ArgParseResults) *diffDisplaySettin } else if apr.Contains(SummaryFlag) { displaySettings.diffParts = Summary } else if apr.Contains(NameOnlyFlag) { - displaySettings.diffParts = TableOnlyDiff + displaySettings.diffParts = NameOnlyDiff } displaySettings.skinny = apr.Contains(SkinnyFlag) @@ -1045,7 +1045,7 @@ func diffUserTable( fromTable := tableSummary.FromTableName toTable := tableSummary.ToTableName - if dArgs.diffParts&TableOnlyDiff == 0 { + if dArgs.diffParts&NameOnlyDiff == 0 { err := dw.BeginTable(tableSummary.FromTableName, tableSummary.ToTableName, tableSummary.IsAdd(), tableSummary.IsDrop()) if err != nil { return errhand.VerboseErrorFromError(err) @@ -1068,7 +1068,7 @@ func diffUserTable( tableName = toTable } - if dArgs.diffParts&TableOnlyDiff != 0 { + if dArgs.diffParts&NameOnlyDiff != 0 { cli.Println(tableName) return errhand.VerboseErrorFromError(nil) } From 348fdf5c77fc27c1810a613978a38c2224afb2fe Mon Sep 17 00:00:00 2001 From: jycor Date: Tue, 30 Apr 2024 21:13:58 +0000 Subject: [PATCH 7/7] [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh --- go/cmd/dolt/commands/diff.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/go/cmd/dolt/commands/diff.go b/go/cmd/dolt/commands/diff.go index 30da4c49800..76e5ccf830a 100644 --- a/go/cmd/dolt/commands/diff.go +++ b/go/cmd/dolt/commands/diff.go @@ -50,7 +50,7 @@ type diffPart int const ( SchemaOnlyDiff diffPart = 1 // 0b0000 0001 DataOnlyDiff diffPart = 2 // 0b0000 0010 - NameOnlyDiff diffPart = 4 // 0b0000 0100 + NameOnlyDiff diffPart = 4 // 0b0000 0100 Stat diffPart = 8 // 0b0000 1000 Summary diffPart = 16 // 0b0001 0000 @@ -60,17 +60,17 @@ const ( SQLDiffOutput diffOutput = 2 JsonDiffOutput diffOutput = 3 - DataFlag = "data" - SchemaFlag = "schema" - NameOnlyFlag = "name-only" - StatFlag = "stat" - SummaryFlag = "summary" - whereParam = "where" - limitParam = "limit" - SkinnyFlag = "skinny" - MergeBase = "merge-base" - DiffMode = "diff-mode" - ReverseFlag = "reverse" + DataFlag = "data" + SchemaFlag = "schema" + NameOnlyFlag = "name-only" + StatFlag = "stat" + SummaryFlag = "summary" + whereParam = "where" + limitParam = "limit" + SkinnyFlag = "skinny" + MergeBase = "merge-base" + DiffMode = "diff-mode" + ReverseFlag = "reverse" ) var diffDocs = cli.CommandDocumentationContent{