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

Changeset values should honor comparators #238

Merged
merged 4 commits into from
Apr 24, 2024

Conversation

ets
Copy link
Contributor

@ets ets commented Apr 24, 2024

What type of PR is this?

This is an improvement PR with the goal of adjusting change column behavior so that it honors comparators when determining what fields have "changed".

What this PR does / why we need it:

If fields A and B differ from left to right for row1 then the changeset column produces an array [A, B] for row1.
If you then configure a comparator to equate the values in A, the changset column still produces an array [A, B] instead of the expected array [B]

Acceptance criteria / Notes for the reviewer

This PR alters the behavior and adds a test to verify it.

Copy link
Contributor

@EnricoMi EnricoMi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent catch! Only minor changes requested.

.filter(_.nonEmpty)
.map(columns =>
concat(
columns
.map(c => when(left(backticks(c)) <=> right(backticks(c)), array()).otherwise(array(lit(c)))): _*
.map(entry => when(entry._2.equiv(left(backticks(entry._1)), right(backticks(entry._1))), array()).otherwise(array(lit(entry._1)))): _*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer naming the tuple elements, rather than using _1 and _2:

Suggested change
.map(entry => when(entry._2.equiv(left(backticks(entry._1)), right(backticks(entry._1))), array()).otherwise(array(lit(entry._1)))): _*
.map { case (c, cmp) =>
when(cmp.equiv(left(backticks(c)), right(backticks(c))), array()).otherwise(array(lit(c)))
}: _*

val rs = left.diff(right, changesetOptions, "id")
assert(rs.where($"diff" === "C").count() == 1, "Only id=3 should differ with the numeric comparator applied")
val differingRow: Row = rs.where($"diff" === "C").head
assert(differingRow.getList(1).size() == 1, "Only floatVal differs after considering the comparators so the changeset should be size 1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than testing for the size, can we test for the actual list content here?

@EnricoMi
Copy link
Contributor

Snapshot CI issues to be fixed in #1103.

Copy link
Contributor

@EnricoMi EnricoMi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@EnricoMi
Copy link
Contributor

Thanks for raising and fixing this!

Copy link

github-actions bot commented Apr 24, 2024

Test Results

   631 files  ± 0     631 suites  ±0   1h 44m 58s ⏱️ -1s
   499 tests + 1     499 ✅ + 1   0 💤 ±0  0 ❌ ±0 
19 419 runs  +27  19 355 ✅ +27  64 💤 ±0  0 ❌ ±0 

Results for commit 2e405f3. ± Comparison against base commit 9ef0526.

♻️ This comment has been updated with latest results.

@EnricoMi
Copy link
Contributor

Please run mvn spotless:apply to fix the lint errors.

@EnricoMi EnricoMi enabled auto-merge April 24, 2024 21:04
@EnricoMi EnricoMi added this pull request to the merge queue Apr 24, 2024
Merged via the queue into G-Research:master with commit d08a4c3 Apr 24, 2024
91 checks passed
@EnricoMi
Copy link
Contributor

This has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants