equality test can now compare columns with different names #1003
+123
−49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves #1000
Problem
There is no way to compare two models using the
equality
test when the columns containing the same data have different column names. For example, if the first table has columnbiz_name
and the second table hasbusiness_name
, there is no way to compare them even if the data is the same.Solution
The compare_columns now optionally accepts a list of two column names. This allows the column names to be different between base model and other model when comparing two columns.
The body of the macro is also refactored to make it more DRY, and reduce convoluting the different steps and capabilities.
First, we gather a set of numeric column names that we need to round. This is referenced later.
Next, we build two lists of column names that we want to compare: one list per model. If compare_columns was given, we build the lists from that. Otherwise, read column names from the first model, filter the excluded column names, and use the result for both models, as we did before this commit.
Now that we have lists of column names, we can build comma-separated lists for each model. At this point, we do the number rounding expression if the column name is found in the set from step 1.
Note this refactoring also cleans up some weird inconsistencies that resulted from duplication of logic. For example, suppose a model's column name was uppercase, and your database is case-sensitive. If you did not specify a "precision" argument, then you need to provide an upper-case "compare_columns" argument. However, if you did specify a "precision" argument, then the "compare-columns" argument was NOT case-sensitive. It's pretty unexpected to have the case sensitivity of one argument be dependent on a seemingly-unrelated argument.
Checklist