- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
Convert more classes to record classes #13328
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
Conversation
| Hi, you can merge main into your branch and hopefully checks pass. For some packages like the "codecs" one, the new code requires you to also document all record components with  | 
        
          
                lucene/core/src/java/org/apache/lucene/util/packed/PackedInts.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | I addressed your comments in the new revision and all the checks are passing now after your fix. Thanks! | 
| Thanks, looks fine. I have no time to do another closer review, please give me some time to proceed. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through the first few files and have some changes:
- there were some hashCodes revoed but equals survied, please remove both
- some toString may be obsolete, too (unless the exact formatting is important)
- some ctors with exact same parameers like default can be rewritten to use the default syntax and remove the field assignments
I will proceed later on the weekend with other classes.
| implements Comparable<Weighted<T>> { | ||
|  | ||
| @Override | ||
| public boolean equals(Object o) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be removed, too
| return Objects.hash(word, score); | ||
| } | ||
|  | ||
| @Override | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep that one, as the toString output is different from default
| */ | ||
| public record TermAndBoost(BytesRef term, float boost) { | ||
| /** Creates a new TermAndBoost */ | ||
| public TermAndBoost(BytesRef term, float boost) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be converted to the generic ctor without parameters:
public TermAndBoost {
  term = BytesRef.deepCopyOf(term);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!.....I changed others such occurrences that I could find as well
        
          
                lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/FSTOrdsOutputs.java
          
            Show resolved
            Hide resolved
        
              
          
                lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java
          
            Show resolved
            Hide resolved
        
      | record Cell( | ||
| PointTree index, int readerIndex, byte[] minPacked, byte[] maxPacked, double distanceSortKey) | ||
| implements Comparable<Cell> { | ||
| Cell( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove that ctor and replace by default ctor and only copy minPacked and maxPacked (see above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution! | 
| Hi @shubhamvishu, | 
| Hi @uschindler , sorry I was on vacation until last week, so this PR stalled. I'll take a look at the comments today or tomorrow. Update : Got stuck with some other work. Will take a look at this sometime this week. | 
| Hi @uschindler , thanks for the review. I took another pass at the changes and pushed some commits addressing your comments. Please have a look when you get a chance. Thanks! | 
| This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution! | 
| Hi @uschindler, Could you please review the current code changes once you get some time and if it looks good maybe we can move this forward? | 
| This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution! | 
| Added the blocker label to draw attention to this PR for the Lucene 10 release. | 
0b39341    to
    f8e9ff1      
    Compare
  
    | Hi @uschindler @mikemccand @jpountz , I fixed the recent merge conflicts and looking for reviews as 10.0 release is blocked on this change. This PR has been attracting merge conflicts frequently since its touching 200+ files, so hoping we could close this sooner. Let me know if there is any concerns here(I'm up for quick followups). Thanks! | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some minor comments but the change looks good to me in general. Can you add an entry to lucene/MIGRATE.txt that explains that TopDocs, CollectionStatistics, TermStatistics and LeafMetadata were converted to records? I'm only considering mentioning these because these are the most user-facing APIs that are migrated to a record from what I can tell (please let me know if you think I'm missing an important one).
        
          
                lucene/core/src/java/org/apache/lucene/search/CollectionStatistics.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | @Override | ||
| public String toString() { | ||
| return "TwoLongs:" + first + "," + second; | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll get a different toString() but I think it's fine in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, its fine in this case.
        
          
                lucene/monitor/src/java/org/apache/lucene/monitor/HighlightsMatch.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | if (o == null || getClass() != o.getClass()) return false; | ||
| FieldAndWeight that = (FieldAndWeight) o; | ||
| return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field); | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you note remove this equals override because the record would behave differently? (I tried to quickly look up what record does wrt equality for floats and doubles but couldn't find it, will look later)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I think its a leftover.I'll change it. Found similar one TermAndBoost in SynonymQuery also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I tried to quickly look up what record does wrt equality for floats and doubles but couldn't find it, will look later)
I found one mention of floating point numbers in the JEP for records:
In addition, for all record classes the implicitly declared equals method is implemented so that it is reflexive and that it behaves consistently with hashCode for record classes that have floating point components. Again, explicitly declared equals and hashCode methods should behave similarly.
I'm not sure I understand that paragraph :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
The equals methods for floats is generated by invokedynamic at runtime using a bootstrapping:
The class file of a record only contains a stub equals/hashcode/to string which delegates to an invokedynamic call passing the class which allows the bootstrapped to get all record components and construct a method handle for the whole method implementation.
When a record component is a float, the autogenerated impl using this impl to handle floats. It compares them using this code:
The method handles used by the code generator are saved in a map:
This is equivalent to the already existing code. So please remove all custom equals methods.
Unfortunately in the merged PR there are some more. Please remove them in a followup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I'll check and followup with removing others I could find.
        
          
                ...est-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingLiveDocsFormat.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                lucene/test-framework/src/java/org/apache/lucene/tests/index/AssertingLeafReader.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | this.bits = bits; | ||
| this.length = length; | ||
| } | ||
| record FixedBits(long[] bits, int length) implements Bits { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't really fit my mental model for a record, maybe undo the refactoring on this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
| @jpountz I addressed your comments and added a CHANGES, MIGRATE entry now. Thanks for reviewing! | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for persisting here @shubhamvishu -- this is a massive rote refactoring change. We should rather bias towards quickly merging such changes since they pick up conflicts so quickly. I just left some minor feedback about wording in CHANGES and MIGRATE, else +1 to merge.
        
          
                lucene/CHANGES.txt
              
                Outdated
          
        
      | argument with a `FacetsCollectorManager` and update the return type to include both `TopDocs` results as well as | ||
| facets results. (Luca Cavanna) | ||
|  | ||
| * GITHUB#13328: Convert CollectionStatistics, TermStatistics and LeafMetadata etc. to record classes. (Shubham Chaudhary) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reword to Convert many basic Lucene classes to record classes, including X, Y, and Z?  It's not just these three classes, if I'm reading the PR correctly, and the etc. should not have so much power ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks better indeed. I'll reword it.
        
          
                lucene/MIGRATE.md
              
                Outdated
          
        
      |  | ||
| - `IOContext`, `MergeInfo`, and `FlushInfo` (GITHUB#13205) | ||
| - `BooleanClause` (GITHUB#13261) | ||
| - `CollectionStatistics`, `TermStatistics` and `LeafMetadata` (GITHUB#13328) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And  maybe change this wording too (same as CHANGES.txt)?  I think @jpountz asked for TopDocs to also be mentioned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll reword. I haven't changed TopDocs in this PR and hence I didn't include it. Maybe some confusion(prolly because there are just too many classes changed here)
| if (o == null || getClass() != o.getClass()) return false; | ||
| FieldAndWeight that = (FieldAndWeight) o; | ||
| return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field); | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I tried to quickly look up what record does wrt equality for floats and doubles but couldn't find it, will look later)
I found one mention of floating point numbers in the JEP for records:
In addition, for all record classes the implicitly declared equals method is implemented so that it is reflexive and that it behaves consistently with hashCode for record classes that have floating point components. Again, explicitly declared equals and hashCode methods should behave similarly.
I'm not sure I understand that paragraph :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one as symmetry in removal of equals/hashcode.
Please fix this in a new PR.
| return docBase == result.docBase && Float.compare(result.score, score) == 0; | ||
| } | ||
|  | ||
| @Override | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also remove the equals, see this comment: #13328 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To string is also useless here. Please remove, too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll fix it in a followup PR. I could only find this instance in the classes changed to records where we have removable custom equals/toString but I'll take another pass to be sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a followup PR #13769. Thanks!
Description
mainbranch to record classes on main (Lucene 10 only).TotalHitsandSynonymMapas the PR is already very big and including those were leading to a lot more changes. Maybe we could do those as a separate PR.Raising this PR since all the tests are passing(
./gradlew test) butrenderJavadoctask is complaining about missing java docs on some record classes(converted in this PR) which I see has the javadocs already eg:TermStats,ReaderSlice. I'm not sure why its flagging those incorrectly or if maybe I'm missing something.