Skip to content

Commit 65a3eff

Browse files
committed
peng - Add test for verify the fix for parse and yamlIT
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent 9f14294 commit 65a3eff

2 files changed

Lines changed: 140 additions & 0 deletions

File tree

‎integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteParseCommandIT.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
package org.opensearch.sql.calcite.remote;
77

8+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
9+
10+
import java.io.IOException;
11+
import org.junit.Test;
812
import org.opensearch.sql.ppl.ParseCommandIT;
913

1014
public class CalciteParseCommandIT extends ParseCommandIT {
@@ -13,4 +17,18 @@ public void init() throws Exception {
1317
super.init();
1418
enableCalcite();
1519
}
20+
21+
@Test
22+
public void testParseErrorUnderscoreInGroupNames() throws IOException {
23+
try {
24+
executeQuery(
25+
String.format(
26+
"source=%s | parse email '.+@(?<host_name>.+)' | fields email", TEST_INDEX_BANK));
27+
fail("Should have thrown an exception for underscore in named capture group");
28+
} catch (Exception e) {
29+
assertTrue(
30+
e.getMessage()
31+
.contains("Underscores are not permitted in Java Regex capture group names"));
32+
}
33+
}
1634
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
setup:
2+
- do:
3+
query.settings:
4+
body:
5+
transient:
6+
plugins.calcite.enabled : true
7+
8+
- do:
9+
indices.create:
10+
index: accounts
11+
body:
12+
settings:
13+
number_of_shards: 1
14+
number_of_replicas: 0
15+
mappings:
16+
properties:
17+
email:
18+
type: text
19+
20+
---
21+
teardown:
22+
- do:
23+
query.settings:
24+
body:
25+
transient:
26+
plugins.calcite.enabled : false
27+
28+
---
29+
"Enhanced error handling for underscores in rex regex capture group names":
30+
- skip:
31+
features:
32+
- headers
33+
- allowed_warnings
34+
- do:
35+
bulk:
36+
index: accounts
37+
refresh: true
38+
body:
39+
- '{"index": {}}'
40+
- '{"email": "john@example.com"}'
41+
42+
- do:
43+
catch: bad_request
44+
headers:
45+
Content-Type: 'application/json'
46+
ppl:
47+
body:
48+
query: source=accounts | rex field=email ".+@(?<domain_name>.+)" | fields email, domain_name
49+
50+
- match: { $body: "{\n \"error\": {\n \"reason\": \"Invalid Query\",\n \"details\": \"Underscores are not permitted in Java Regex capture group names\",\n \"type\": \"IllegalArgumentException\"\n },\n \"status\": 400\n}" }
51+
52+
---
53+
"Enhanced error handling for underscores in parse regex capture group names":
54+
- skip:
55+
features:
56+
- headers
57+
- allowed_warnings
58+
- do:
59+
bulk:
60+
index: accounts
61+
refresh: true
62+
body:
63+
- '{"index": {}}'
64+
- '{"email": "john@example.com"}'
65+
66+
- do:
67+
catch: bad_request
68+
headers:
69+
Content-Type: 'application/json'
70+
ppl:
71+
body:
72+
query: source=accounts | parse email ".+@(?<host_name>.+)" | fields email, host_name
73+
74+
- match: { $body: "{\n \"error\": {\n \"reason\": \"Invalid Query\",\n \"details\": \"Underscores are not permitted in Java Regex capture group names\",\n \"type\": \"IllegalArgumentException\"\n },\n \"status\": 400\n}" }
75+
76+
---
77+
"Rex command should work with valid group names without underscores":
78+
- skip:
79+
features:
80+
- headers
81+
- allowed_warnings
82+
- do:
83+
bulk:
84+
index: accounts
85+
refresh: true
86+
body:
87+
- '{"index": {}}'
88+
- '{"email": "john@example.com"}'
89+
90+
- do:
91+
headers:
92+
Content-Type: 'application/json'
93+
ppl:
94+
body:
95+
query: source=accounts | rex field=email ".+@(?<domain>.+)" | fields email, domain
96+
97+
- match: { total: 1 }
98+
- match: { datarows: [["john@example.com", "example.com"]] }
99+
100+
---
101+
"Parse command should work with valid group names without underscores":
102+
- skip:
103+
features:
104+
- headers
105+
- allowed_warnings
106+
- do:
107+
bulk:
108+
index: accounts
109+
refresh: true
110+
body:
111+
- '{"index": {}}'
112+
- '{"email": "john@example.com"}'
113+
114+
- do:
115+
headers:
116+
Content-Type: 'application/json'
117+
ppl:
118+
body:
119+
query: source=accounts | parse email ".+@(?<host>.+)" | fields email, host
120+
121+
- match: { total: 1 }
122+
- match: { datarows: [["john@example.com", "example.com"]] }

0 commit comments

Comments
 (0)