|
11 | 11 | import static org.opensearch.sql.expression.function.FunctionDSL.define; |
12 | 12 | import static org.opensearch.sql.expression.function.FunctionDSL.impl; |
13 | 13 | import static org.opensearch.sql.expression.function.FunctionDSL.nullMissingHandling; |
14 | | -import static org.opensearch.sql.planner.logical.LogicalParse.typeStrToExprType; |
15 | 14 |
|
16 | | -import java.util.HashMap; |
17 | | -import java.util.LinkedHashMap; |
18 | | -import java.util.Map; |
19 | | -import java.util.regex.Matcher; |
20 | | -import java.util.regex.Pattern; |
21 | 15 | import lombok.experimental.UtilityClass; |
22 | 16 | import org.opensearch.sql.data.model.ExprIntegerValue; |
23 | 17 | import org.opensearch.sql.data.model.ExprStringValue; |
24 | 18 | import org.opensearch.sql.data.model.ExprValue; |
25 | | -import org.opensearch.sql.exception.SemanticCheckException; |
26 | | -import org.opensearch.sql.expression.DSL; |
27 | | -import org.opensearch.sql.expression.Expression; |
28 | 19 | import org.opensearch.sql.expression.function.BuiltinFunctionName; |
29 | 20 | import org.opensearch.sql.expression.function.BuiltinFunctionRepository; |
30 | 21 | import org.opensearch.sql.expression.function.FunctionName; |
@@ -63,7 +54,6 @@ public void register(BuiltinFunctionRepository repository) { |
63 | 54 | repository.register(left()); |
64 | 55 | repository.register(ascii()); |
65 | 56 | repository.register(locate()); |
66 | | - repository.register(regex()); |
67 | 57 | repository.register(replace()); |
68 | 58 | } |
69 | 59 |
|
@@ -263,11 +253,6 @@ private FunctionResolver replace() { |
263 | 253 | impl(nullMissingHandling(TextFunction::exprReplace), STRING, STRING, STRING, STRING)); |
264 | 254 | } |
265 | 255 |
|
266 | | - private FunctionResolver regex() { |
267 | | - return define(BuiltinFunctionName.REGEX.getName(), |
268 | | - impl(nullMissingHandling(TextFunction::exprRegex), STRING, STRING, STRING, STRING)); |
269 | | - } |
270 | | - |
271 | 256 | private static ExprValue exprSubstrStart(ExprValue exprValue, ExprValue start) { |
272 | 257 | int startIdx = start.integerValue(); |
273 | 258 | if (startIdx == 0) { |
@@ -328,32 +313,6 @@ private static ExprValue exprLocate(ExprValue subStr, ExprValue str, ExprValue p |
328 | 313 | str.stringValue().indexOf(subStr.stringValue(), pos.integerValue() - 1) + 1); |
329 | 314 | } |
330 | 315 |
|
331 | | - static int n = 1; |
332 | | - |
333 | | - private static ExprValue exprRegex(ExprValue str, ExprValue pattern, ExprValue group) { |
334 | | - String rawPattern = pattern.stringValue(); |
335 | | - String targetGroup = group.stringValue(); |
336 | | - Map<String, String> groups = new HashMap<>(); |
337 | | - Matcher m = Pattern.compile("\\(\\?<([a-zA-Z][a-zA-Z0-9]*?)>").matcher(rawPattern); |
338 | | - while (m.find()) { |
339 | | - groups.put(m.group(1), ""); |
340 | | - } |
341 | | -// System.out.println(" ❗groups: " + groups); |
342 | | - |
343 | | - Matcher matcher = Pattern.compile(rawPattern).matcher(str.stringValue()); |
344 | | - Map<String, ExprValue> exprValueMap = new LinkedHashMap<>(); |
345 | | - if (matcher.matches()) { |
346 | | - groups.forEach((field, rawType) -> { |
347 | | - String rawMatch = matcher.group(field); |
348 | | -// System.out.println(" ❗field: " + field); |
349 | | -// System.out.println(" ❗rawMatch: " + rawMatch); |
350 | | - exprValueMap.put(field, new ExprStringValue(rawMatch)); |
351 | | - }); |
352 | | - } |
353 | | - System.out.println(" ❗n: " + n++); |
354 | | - return exprValueMap.get(targetGroup); |
355 | | - } |
356 | | - |
357 | 316 | private static ExprValue exprReplace(ExprValue str, ExprValue from, ExprValue to) { |
358 | 317 | return new ExprStringValue(str.stringValue().replaceAll(from.stringValue(), to.stringValue())); |
359 | 318 | } |
|
0 commit comments