|
8 | 8 | import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; |
9 | 9 | import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG; |
10 | 10 | import static org.opensearch.sql.util.MatcherUtils.columnName; |
| 11 | +import static org.opensearch.sql.util.MatcherUtils.rows; |
11 | 12 | import static org.opensearch.sql.util.MatcherUtils.schema; |
12 | 13 | import static org.opensearch.sql.util.MatcherUtils.verifyColumn; |
| 14 | +import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; |
13 | 15 | import static org.opensearch.sql.util.MatcherUtils.verifySchema; |
14 | 16 |
|
15 | 17 | import java.io.IOException; |
@@ -146,4 +148,88 @@ public void testCrossClusterFieldsAndTableEquivalence() throws IOException { |
146 | 148 | verifySchema(fieldsResult, schema("dog_name", "string"), schema("age", "bigint")); |
147 | 149 | verifySchema(tableResult, schema("dog_name", "string"), schema("age", "bigint")); |
148 | 150 | } |
| 151 | + |
| 152 | + @Test |
| 153 | + public void testCrossClusterRegexBasic() throws IOException { |
| 154 | + JSONObject result = |
| 155 | + executeQuery( |
| 156 | + String.format( |
| 157 | + "search source=%s | regex firstname='.*att.*' | fields firstname", |
| 158 | + TEST_INDEX_BANK_REMOTE)); |
| 159 | + verifyDataRows(result, rows("Hattie")); |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + public void testCrossClusterRegexWithNegation() throws IOException { |
| 164 | + JSONObject result = |
| 165 | + executeQuery( |
| 166 | + String.format( |
| 167 | + "search source=%s | regex firstname!='.*att.*' | fields firstname", |
| 168 | + TEST_INDEX_BANK_REMOTE)); |
| 169 | + verifyDataRows( |
| 170 | + result, |
| 171 | + rows("Virginia"), |
| 172 | + rows("Elinor"), |
| 173 | + rows("Dillard"), |
| 174 | + rows("Dale"), |
| 175 | + rows("Amber JOHnny"), |
| 176 | + rows("Nanette")); |
| 177 | + } |
| 178 | + |
| 179 | + @Test |
| 180 | + public void testCrossClusterRexBasic() throws IOException { |
| 181 | + JSONObject result = |
| 182 | + executeQuery( |
| 183 | + String.format( |
| 184 | + "search source=%s | rex field=firstname \\\"(?<initial>^[A-Z])\\\" | fields" |
| 185 | + + " firstname, initial | head 3", |
| 186 | + TEST_INDEX_BANK_REMOTE)); |
| 187 | + verifyDataRows(result, rows("Amber JOHnny", "A"), rows("Hattie", "H"), rows("Nanette", "N")); |
| 188 | + } |
| 189 | + |
| 190 | + @Test |
| 191 | + public void testCrossClusterRexMultipleGroups() throws IOException { |
| 192 | + JSONObject result = |
| 193 | + executeQuery( |
| 194 | + String.format( |
| 195 | + "search source=%s | rex field=lastname \\\"(?<first>[A-Z])(?<rest>[a-z]+)\\\" |" |
| 196 | + + " fields lastname, first, rest | head 2", |
| 197 | + TEST_INDEX_BANK_REMOTE)); |
| 198 | + verifyDataRows(result, rows("Duke Willmington", "D", "uke"), rows("Bond", "B", "ond")); |
| 199 | + } |
| 200 | + |
| 201 | + @Test |
| 202 | + public void testCrossClusterRexSedMode() throws IOException { |
| 203 | + JSONObject result = |
| 204 | + executeQuery( |
| 205 | + String.format( |
| 206 | + "search source=%s | rex field=firstname mode=sed \\\"s/^[A-Z]/X/\\\" | fields" |
| 207 | + + " firstname | head 3", |
| 208 | + TEST_INDEX_BANK_REMOTE)); |
| 209 | + verifyDataRows(result, rows("Xmber JOHnny"), rows("Xattie"), rows("Xanette")); |
| 210 | + } |
| 211 | + |
| 212 | + @Test |
| 213 | + public void testCrossClusterRexWithMaxMatch() throws IOException { |
| 214 | + JSONObject result = |
| 215 | + executeQuery( |
| 216 | + String.format( |
| 217 | + "search source=%s | rex field=firstname \\\"(?<letter>[A-Z])\\\" max_match=2 |" |
| 218 | + + " fields firstname, letter | head 2", |
| 219 | + TEST_INDEX_BANK_REMOTE)); |
| 220 | + verifyDataRows( |
| 221 | + result, rows("Amber JOHnny", new String[] {"A", "J"}), rows("Hattie", new String[] {"H"})); |
| 222 | + } |
| 223 | + |
| 224 | + @Test |
| 225 | + public void testCrossClusterRexWithOffsetField() throws IOException { |
| 226 | + JSONObject result = |
| 227 | + executeQuery( |
| 228 | + String.format( |
| 229 | + "search source=%s | rex field=lastname \\\"(?<vowel>[aeiou])\\\" offset_field=pos |" |
| 230 | + + " fields lastname, vowel, pos | head 2", |
| 231 | + TEST_INDEX_BANK_REMOTE)); |
| 232 | + verifyDataRows( |
| 233 | + result, rows("Duke Willmington", "u", "vowel=1-1"), rows("Bond", "o", "vowel=1-1")); |
| 234 | + } |
149 | 235 | } |
0 commit comments