-
Notifications
You must be signed in to change notification settings - Fork 180
Add hashCode() and equals() to the value class of ExprJavaType #4885
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
Signed-off-by: Lantao Jin <[email protected]>
WalkthroughThis pull request addresses a regression where joins on IP-type fields returned empty results. It adds a Lombok annotation to ExprIpValue to generate equals() and hashCode() methods, clarifies requirements in ExprJavaType's Javadoc, and introduces an integration test validating hash joins on IP types function correctly. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
core/src/main/java/org/opensearch/sql/calcite/type/ExprJavaType.java (1)
16-19: Javadoc clearly encodes the equals/hashCode contractThe added note that
javaClazzmust overrideequals()andhashCode()makes the hashing/join requirements explicit and ties nicely to theExprIpValueexample. One small follow-up: please verify that{@link ExprIPType}resolves correctly in Javadoc (and fully-qualify it if needed) so the example link doesn’t break.integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/4726.yml (2)
32-57: Minor mapping/name mismatch in test dataThe index mapping for
test1defines atimestampfield, but the bulk docs usedatetime. It doesn’t affect this test (the query never touches the time field), but for clarity you may want to either rename the mapping property todatetimeor adjust the docs to usetimestampso index structure and data are aligned.
67-83: Make result ordering deterministic to avoid potential test flakinessThe
matchondatarowsasserts an exact ordered array of rows. Unless the PPL pipeline guarantees ordering for this query, this can be brittle. Consider adding an explicitsort client_ip(or similar) at the end of the PPL query so the result order is deterministic, or relaxing the assertion if the test framework supports order-insensitive checks.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
core/src/main/java/org/opensearch/sql/calcite/type/ExprJavaType.java(1 hunks)core/src/main/java/org/opensearch/sql/data/model/ExprIpValue.java(1 hunks)integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/4726.yml(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
core/src/main/java/org/opensearch/sql/data/model/ExprIpValue.java (2)
opensearch/src/main/java/org/opensearch/sql/opensearch/data/type/OpenSearchDataType.java (1)
EqualsAndHashCode(21-323)opensearch/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java (1)
EqualsAndHashCode(1072-1089)
🔇 Additional comments (1)
core/src/main/java/org/opensearch/sql/data/model/ExprIpValue.java (1)
8-17: Value-based equals/hashCode forExprIpValueis appropriate for HashJoinUsing
@EqualsAndHashCode(callSuper = false)on this value class makesequals()/hashCode()depend solely on theIPAddress valuefield, which is exactly what HashMap/HashJoin need and keeps semantics aligned with the existingequal(ExprValue)/comparebehavior. If additional fields are ever added toExprIpValue, it’d be worth double-checking that they’re intended to participate in equality, but for the current shape this looks correct.
Description
The query above is optimized to
HashJoinsince the left output comes from an aggregation. UnlikeMergeJoin, theHashJoinuseshashCode()to get the equivalence key from a HashMap. The value objectExprIpValueofExprIPTypeshould override the hashCode() and equals() methods. (If the join isMergeJoin, there is no issue sinceExprIpValuehas already implementedComparable.Related Issues
Resolves #4726
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
Summary by CodeRabbit
Improvements
Tests
✏️ Tip: You can customize this high-level summary in your review settings.