Repository navigation
Add filter option for diff command - #3499
ksankeerth wants to merge 3 commits into
Conversation
I have done the following changes. 1. Diff for docs 2. Diff for rows 3. Diff for Table summary 4. Diff schema change and creation
I have added filter the following functions.
1. Diff for docs
2. Diff for rows
3. Diff for Table summary
4. Diff schema change and creation
| ap.SupportsString(whereParam, "", "column", "filters columns based on values in the diff. See {{.EmphasisLeft}}dolt diff --help{{.EmphasisRight}} for details.") | ||
| ap.SupportsInt(limitParam, "", "record_count", "limits to the first N diffs.") | ||
| ap.SupportsFlag(CachedFlag, "c", "Show only the unstaged data changes.") | ||
| ap.SupportsString(filterParam, "", "diff_type", "filters(inserts|updates|deletes) based on type of modifications.") |
There was a problem hiding this comment.
For consistency, how about using the existing diff_type strings that the Dolt diff tables use? Something like:
filters results based on the type of modification (added, modified, removed).
@timsehn – since you specifically mentioned insert/update/delete in the original issue, let us know if you still prefer those. Otherwise, added/modified/removed seems more consistent with the other diff_type uses in Dolt and maps to schema changes better.
There was a problem hiding this comment.
I'm fine with "added/modified/removed".
|
|
||
| if fromCreateStmt != toCreateStmt { | ||
| cli.Println(textdiff.LineDiff(fromCreateStmt, toCreateStmt)) | ||
| if fromCreateStmt == "" && toSch.GetAllCols().Size() > fromSch.GetAllCols().Size() { |
There was a problem hiding this comment.
If we go with diff_types of added, modified, removed... this could probably be simplified a bit...
You could use td.IsAdd() && (filter == FilterAdded || filter == NoFilter) to identify added tables, td.Drop() to identify dropped tables, and just rely on everything else being a table modification (e.g. renames, column adds/deletes, etc). Slightly different than the insert/add/delete mapping you proposed, but it would match up better with the existing Dolt diff_types.
Also... it might be worth creating a small private struct in this file for the filter. Then you could clean up some of the filter checking logic a bit, make the code read a little smoother, and not have to pass around a string as the filter. For example, I'm imagining usage like:
if (td.Add() && filter.includeAdds()) {
That would give a little more typing/structure and also removes the need to check for NoFilter directly in many places. It also potentially sets us up to more easily support multiple filters in the future (e.g. including all deletes and all modifications).
|
|
||
| if td.IsDrop() { | ||
| cli.Println(sqlfmt.DropTableStmt(td.FromName)) | ||
| if filter == NoFilter || filter == FilterDeletes { |
There was a problem hiding this comment.
(minor) If you go with the diffTypeFilter struct idea above, this could be simple enough to roll into the existing if statement above; something like if td.IsDrop() && diffTypeFilter.includeDrops() {
| _, _ = bold.Printf("diff --dolt a/%s b/%s\n", td.ToName, td.ToName) | ||
| _, _ = bold.Println("added table") | ||
| } else { | ||
|
|
There was a problem hiding this comment.
(minor) This extra newline can be trimmed out please.
| newColsCount int | ||
| } | ||
|
|
||
| func NewDiffFilterTrans(filterBy string, newColsCount int) *DiffFilterTransform { |
There was a problem hiding this comment.
(minor) Might as well add the "form" at the end just to be complete and consistent with other method naming. Four extra chars isn't too big of a deal anyway.
|
|
||
| v, ok := joinedRowAsMap[0] | ||
| if v != nil && ok { | ||
| if df.newColsCount < len(joinedRowAsMap) { |
There was a problem hiding this comment.
This should also simplify nicely if we look at diff_type as added/modified/removed and treat any schema change as modified, table create as add, and table delete as remove. I suspect this might be easier/cleaner if you do this check when you have a TableDelta object (instead of in this pipeline step).
| } | ||
|
|
||
|
|
||
| @test "diff: filter table diffs" { |
|
Awesome contribution @ksankeerth! My biggest feedback is switching the Thanks a ton for this contribution and for including awesome tests, too. 😄 Let us know if you have questions about any of the feedback, and of course, feel free to hit us up on Discord, too. |
|
@fulghum Thanks for the feedback and review. I'll go through them and push the changes. Yeah, If We consider added/modified/removed instead of inserts/updates/deletes, it going to be very simple |
I have done the following changes. 1. Made changes as per the suggestions. 2. Added/Modified/Removed instead of inserts/updates/deletes 3. td.IsDrop() and td.IsAdd() were used to identity the diff types 4. removed transform which was added in the previous commit since the filter type can be identified early with the new approach(3) 5. added struct to manage the filter
|
Hi @fulghum, Could you please have look at the latest commit when you have time. Let me know your feedback. Previously, I filtered each table row based on inserts/updates/deletes/. Now I use td.IsAdd() and td.IsDrop() to identity the diff type, so it seems that not necessary to have the transform. |
|
Jason is on vacation today so likely, he'll get to this Monday. |
fulghum
left a comment
There was a problem hiding this comment.
Nice work with these changes @ksankeerth. It's definitely getting closer and the code is looking cleaner.
I left a few small comments; I think this is missing some code in the diffRows function that will help the filter work for row-level adds/drops/modifies, in addition to table-level adds/drops/modifies.
Thanks for all the effort on this one! It's getting closer.
| return errhand.VerboseErrorFromError(err) | ||
| } | ||
| } | ||
| td.IsDrop() |
There was a problem hiding this comment.
(minor) looks like this can be removed.
| } | ||
|
|
||
| doesFilterMatchDiff := false | ||
| if (td.IsAdd() && dArgs.filter.includeAddsOrAll()) || (td.IsDrop() && dArgs.filter.includeDropsOrAll()) || (!td.IsAdd() && !td.IsDrop() && dArgs.filter.includeModificationsOrAll()) { |
There was a problem hiding this comment.
This is looking very close and will work for table adds and table drops, but not yet for table modifications or row adds/drops/modifications.
For table modifications, you can use something like tableModified := tableDelta.HasSchemaChanged(ctx) || tableDelta.IsRename().
For row adds/drops/modifications, you'll need something in the diffRows method, where row contents are diffed. You might be able to revive some code from the earlier PR version, but I think something will need to be in this function in order to detect row data changes.
| fromSch = toSch | ||
| } | ||
| if !doesFilterMatchDiff { | ||
| return nil |
There was a problem hiding this comment.
fyi... these return nils will prevent other TableDeltas from being looked at in the for loop, so I don't think this is correct. Take a closer look at these two return nils and see if there's a cleaner way to control the flow through this block. Happy to provide more suggestions if you can't come up with anything.
| } | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
(minor) would be good to clean up this extra whitespace for consistency with the existing codebase.
|
Any chance you'll get to this @ksankeerth ? |
|
I'm going to close this. Reopen if you ever revisit the feedback. |
This PR closes #1430
Description :
The following assumptions were taken for diff filter.
For docs
For Table
The
filterflag is not allowed with--summaryTests
Please check the changes and let me know your feedback.
Thanks