Skip to content

Commit f30e5bd

Browse files
committed
Add cross cluster IT for rex
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent 3e008b5 commit f30e5bd

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,87 @@ public void testTimeBinCrossCluster() throws IOException {
239239
rows("2025-07-28 01:00:00", 7623),
240240
rows("2025-07-28 02:00:00", 9187));
241241
}
242+
243+
public void testCrossClusterRegexBasic() throws IOException {
244+
JSONObject result =
245+
executeQuery(
246+
String.format(
247+
"search source=%s | regex firstname='.*att.*' | fields firstname",
248+
TEST_INDEX_BANK_REMOTE));
249+
verifyDataRows(result, rows("Hattie"));
250+
}
251+
252+
@Test
253+
public void testCrossClusterRegexWithNegation() throws IOException {
254+
JSONObject result =
255+
executeQuery(
256+
String.format(
257+
"search source=%s | regex firstname!='.*att.*' | fields firstname",
258+
TEST_INDEX_BANK_REMOTE));
259+
verifyDataRows(
260+
result,
261+
rows("Virginia"),
262+
rows("Elinor"),
263+
rows("Dillard"),
264+
rows("Dale"),
265+
rows("Amber JOHnny"),
266+
rows("Nanette"));
267+
}
268+
269+
@Test
270+
public void testCrossClusterRexBasic() throws IOException {
271+
JSONObject result =
272+
executeQuery(
273+
String.format(
274+
"search source=%s | rex field=firstname \\\"(?<initial>^[A-Z])\\\" | fields"
275+
+ " firstname, initial | head 3",
276+
TEST_INDEX_BANK_REMOTE));
277+
verifyDataRows(result, rows("Amber JOHnny", "A"), rows("Hattie", "H"), rows("Nanette", "N"));
278+
}
279+
280+
@Test
281+
public void testCrossClusterRexMultipleGroups() throws IOException {
282+
JSONObject result =
283+
executeQuery(
284+
String.format(
285+
"search source=%s | rex field=lastname \\\"(?<first>[A-Z])(?<rest>[a-z]+)\\\" |"
286+
+ " fields lastname, first, rest | head 2",
287+
TEST_INDEX_BANK_REMOTE));
288+
verifyDataRows(result, rows("Duke Willmington", "D", "uke"), rows("Bond", "B", "ond"));
289+
}
290+
291+
@Test
292+
public void testCrossClusterRexSedMode() throws IOException {
293+
JSONObject result =
294+
executeQuery(
295+
String.format(
296+
"search source=%s | rex field=firstname mode=sed \\\"s/^[A-Z]/X/\\\" | fields"
297+
+ " firstname | head 3",
298+
TEST_INDEX_BANK_REMOTE));
299+
verifyDataRows(result, rows("Xmber JOHnny"), rows("Xattie"), rows("Xanette"));
300+
}
301+
302+
@Test
303+
public void testCrossClusterRexWithMaxMatch() throws IOException {
304+
JSONObject result =
305+
executeQuery(
306+
String.format(
307+
"search source=%s | rex field=firstname \\\"(?<letter>[A-Z])\\\" max_match=2 |"
308+
+ " fields firstname, letter | head 2",
309+
TEST_INDEX_BANK_REMOTE));
310+
verifyDataRows(
311+
result, rows("Amber JOHnny", new String[] {"A", "J"}), rows("Hattie", new String[] {"H"}));
312+
}
313+
314+
@Test
315+
public void testCrossClusterRexWithOffsetField() throws IOException {
316+
JSONObject result =
317+
executeQuery(
318+
String.format(
319+
"search source=%s | rex field=lastname \\\"(?<vowel>[aeiou])\\\" offset_field=pos |"
320+
+ " fields lastname, vowel, pos | head 2",
321+
TEST_INDEX_BANK_REMOTE));
322+
verifyDataRows(
323+
result, rows("Duke Willmington", "u", "vowel=1-1"), rows("Bond", "o", "vowel=1-1"));
324+
}
242325
}

0 commit comments

Comments
 (0)