Skip to content

Commit 61e52c5

Browse files
Add hashCode() and equals() to the implmentation classes of ExprJavaType (#4885) (#4891)
(cherry picked from commit 96370bf) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent ae83a65 commit 61e52c5

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

core/src/main/java/org/opensearch/sql/calcite/type/ExprJavaType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
/**
1616
* The JavaType for ExprUDT. The UDT which needs to use self-implemented java class should extend
17-
* this.
17+
* this. Its javaClazz should override equals() and hashCode() methods. For example, {@link
18+
* org.opensearch.sql.data.model.ExprIpValue} (javaClazz of {@link ExprIPType}) overrides the
19+
* equals() and hashCode().
1820
*/
1921
public class ExprJavaType extends AbstractExprRelDataType<JavaType> {
2022
public ExprJavaType(OpenSearchTypeFactory typeFactory, ExprUDT exprUDT, Class<?> javaClazz) {

core/src/main/java/org/opensearch/sql/data/model/ExprIpValue.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
package org.opensearch.sql.data.model;
77

88
import inet.ipaddr.IPAddress;
9+
import lombok.EqualsAndHashCode;
910
import org.opensearch.sql.data.type.ExprCoreType;
1011
import org.opensearch.sql.data.type.ExprType;
1112
import org.opensearch.sql.utils.IPUtils;
1213

1314
/** Expression IP Address Value. */
15+
@EqualsAndHashCode(callSuper = false)
1416
public class ExprIpValue extends AbstractExprValue {
1517
private final IPAddress value;
1618

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
setup:
2+
- do:
3+
query.settings:
4+
body:
5+
transient:
6+
plugins.calcite.enabled : true
7+
- do:
8+
indices.create:
9+
index: test1
10+
body:
11+
mappings:
12+
properties:
13+
"timestamp":
14+
type: date
15+
"status":
16+
type: integer
17+
"client_ip":
18+
type: ip
19+
- do:
20+
indices.create:
21+
index: test2
22+
body:
23+
mappings:
24+
properties:
25+
"client_ip":
26+
type: ip
27+
"city":
28+
type: keyword
29+
"country":
30+
type: keyword
31+
- do:
32+
bulk:
33+
index: test1
34+
refresh: true
35+
body:
36+
- '{"index":{}}'
37+
- '{"datetime":"2025-01-15T00:30:00Z","status":200,"client_ip":"10.0.0.1"}'
38+
- '{"index":{}}'
39+
- '{"datetime":"2025-01-15T02:15:00Z","status":200,"client_ip":"10.0.0.2"}'
40+
- '{"index":{}}'
41+
- '{"datetime":"2025-01-15T10:50:00Z","status":200,"client_ip":"10.0.0.11"}'
42+
- '{"index":{}}'
43+
- '{"datetime":"2025-01-15T23:45:00Z","status":200,"client_ip":"10.0.0.24"}'
44+
- do:
45+
bulk:
46+
index: test2
47+
refresh: true
48+
body:
49+
- '{"index":{}}'
50+
- '{"client_ip": "10.0.0.1","country": "Canada","city": "Toronto"}'
51+
- '{"index":{}}'
52+
- '{"client_ip": "10.0.0.24","country": "UK","city": "London"}'
53+
- '{"index":{}}'
54+
- '{"client_ip": "10.0.1.1","country": "USA","city": "New York"}'
55+
- '{"index":{}}'
56+
- '{"client_ip": "10.0.1.2","country": "USA","city": "Seattle"}'
57+
58+
---
59+
teardown:
60+
- do:
61+
query.settings:
62+
body:
63+
transient:
64+
plugins.calcite.enabled : false
65+
66+
---
67+
"hash join on IP type should work":
68+
- skip:
69+
features:
70+
- headers
71+
- allowed_warnings
72+
- do:
73+
allowed_warnings:
74+
- 'Loading the fielddata on the _id field is deprecated and will be removed in future versions. If you require sorting or aggregating on this field you should also include the id in the body of your documents, and map this field as a keyword field that has [doc_values] enabled'
75+
headers:
76+
Content-Type: 'application/json'
77+
ppl:
78+
body:
79+
query: source=test1 | stats count() as cnt by client_ip | join type=inner client_ip test2 | fields client_ip, cnt
80+
81+
82+
- match: { total: 2 }
83+
- match: {"datarows": [["10.0.0.1", 1], ["10.0.0.24", 1]]}

0 commit comments

Comments
 (0)