Add id to MetadataKey so that we can change the key order#9159
Add id to MetadataKey so that we can change the key order#9159Jackie-Jiang merged 1 commit intoapache:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9159 +/- ##
============================================
- Coverage 69.98% 69.96% -0.02%
+ Complexity 4758 4757 -1
============================================
Files 1847 1847
Lines 98555 98566 +11
Branches 14969 14972 +3
============================================
- Hits 68972 68961 -11
- Misses 24741 24755 +14
- Partials 4842 4850 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
|
Part of me thinks that people really need to read the code (javadoc just above the enum) before making bad changes of inserting keys in the middle. So, we should try to stick to current mechanism if possible. |
pinot-common/src/main/java/org/apache/pinot/common/utils/DataTable.java
Outdated
Show resolved
Hide resolved
+1. Enums should be treated as append-only code constructs. |
Following conventions is a good convention, but making the code structure enforce or incentivize conventions may be even better. IMHO, it's not too controversial to add a manually maintained ID for enums that need to be sent across processes or persisted across restarts of the same process (i.e. any enum that will potentially be produced by one version of the software and consumed by another). Using the enum's built-in ordinal is error-prone, since it doesn’t survive re-ordering, nor insertions and removals from the middle. Using a manually-maintained ID on the other hand is resilient to all these scenarios. |
5c6ef7b to
ee84e5d
Compare
|
@siddharthteotia @richardstartin Example PRs that breaks the backward compatibility: |
Clearly a very simple regression test can prevent changes like this from getting merged (and from someone accidentally adding a duplicate id, against which there are currently no guards). Code review shouldn’t focus on things which can be automated simply because hardly anyone has (or should have) the attention span to verify trivialities like these. |
We may add a regression test to verify all the existing keys still have the same ordinal, but we also need to take extra effort maintaining the test whenever a new key is added. E.g. #8884 can still happen if the previous PR didn't add the new keys to the test We do check duplicate id in the static block. Assigning an id has extra benefits though:
|
|
Let me go through the change once today/tomorrow |
ee84e5d to
2853d2a
Compare
siddharthteotia
left a comment
There was a problem hiding this comment.
I am ok with this to make things more resilient against some of the problems caused by few recent PRs.
However, if as a reviewer we come across a change (e.g reordering enums entries (without a stronger reason)), then I suggest we still push back / advocate for adding entries at the end and other hygiene / practices.
Assign an id to each
MetadataKeyin theDataTableso that we can change the key order (insert new keys) if necessary for readability. There have been multiple issues caused by people adding keys in the middle