Skip to content

Commit 4635716

Browse files
committed
Revert "WIP regex function implementation"
This reverts commit 230be89. Signed-off-by: Joshua Li <joshuali925@gmail.com>
1 parent b218fbe commit 4635716

6 files changed

Lines changed: 2 additions & 46 deletions

File tree

core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public enum BuiltinFunctionName {
150150
ASCII(FunctionName.of("ascii")),
151151
LOCATE(FunctionName.of("locate")),
152152
REPLACE(FunctionName.of("replace")),
153-
REGEX(FunctionName.of("regex")),
154153

155154
/**
156155
* NULL Test.

core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,11 @@
1111
import static org.opensearch.sql.expression.function.FunctionDSL.define;
1212
import static org.opensearch.sql.expression.function.FunctionDSL.impl;
1313
import static org.opensearch.sql.expression.function.FunctionDSL.nullMissingHandling;
14-
import static org.opensearch.sql.planner.logical.LogicalParse.typeStrToExprType;
1514

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;
2115
import lombok.experimental.UtilityClass;
2216
import org.opensearch.sql.data.model.ExprIntegerValue;
2317
import org.opensearch.sql.data.model.ExprStringValue;
2418
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;
2819
import org.opensearch.sql.expression.function.BuiltinFunctionName;
2920
import org.opensearch.sql.expression.function.BuiltinFunctionRepository;
3021
import org.opensearch.sql.expression.function.FunctionName;
@@ -63,7 +54,6 @@ public void register(BuiltinFunctionRepository repository) {
6354
repository.register(left());
6455
repository.register(ascii());
6556
repository.register(locate());
66-
repository.register(regex());
6757
repository.register(replace());
6858
}
6959

@@ -263,11 +253,6 @@ private FunctionResolver replace() {
263253
impl(nullMissingHandling(TextFunction::exprReplace), STRING, STRING, STRING, STRING));
264254
}
265255

266-
private FunctionResolver regex() {
267-
return define(BuiltinFunctionName.REGEX.getName(),
268-
impl(nullMissingHandling(TextFunction::exprRegex), STRING, STRING, STRING, STRING));
269-
}
270-
271256
private static ExprValue exprSubstrStart(ExprValue exprValue, ExprValue start) {
272257
int startIdx = start.integerValue();
273258
if (startIdx == 0) {
@@ -328,32 +313,6 @@ private static ExprValue exprLocate(ExprValue subStr, ExprValue str, ExprValue p
328313
str.stringValue().indexOf(subStr.stringValue(), pos.integerValue() - 1) + 1);
329314
}
330315

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-
357316
private static ExprValue exprReplace(ExprValue str, ExprValue from, ExprValue to) {
358317
return new ExprStringValue(str.stringValue().replaceAll(from.stringValue(), to.stringValue()));
359318
}

ppl/src/main/antlr/OpenSearchPPLLexer.g4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ LEFT: 'LEFT';
226226
ASCII: 'ASCII';
227227
LOCATE: 'LOCATE';
228228
REPLACE: 'REPLACE';
229-
REGEX: 'REGEX';
230229

231230
// BOOL FUNCTIONS
232231
LIKE: 'LIKE';

ppl/src/main/antlr/OpenSearchPPLParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ conditionFunctionBase
284284

285285
textFunctionBase
286286
: SUBSTR | SUBSTRING | TRIM | LTRIM | RTRIM | LOWER | UPPER | CONCAT | CONCAT_WS | LENGTH | STRCMP
287-
| RIGHT | LEFT | ASCII | LOCATE | REPLACE | REGEX
287+
| RIGHT | LEFT | ASCII | LOCATE | REPLACE
288288
;
289289

290290
/** operators */

sql/src/main/antlr/OpenSearchSQLLexer.g4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ POW: 'POW';
227227
POWER: 'POWER';
228228
RADIANS: 'RADIANS';
229229
RAND: 'RAND';
230-
REGEX: 'REGEX';
231230
REPLACE: 'REPLACE';
232231
RINT: 'RINT';
233232
ROUND: 'ROUND';

sql/src/main/antlr/OpenSearchSQLParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ dateTimeFunctionName
370370
textFunctionName
371371
: SUBSTR | SUBSTRING | TRIM | LTRIM | RTRIM | LOWER | UPPER
372372
| CONCAT | CONCAT_WS | SUBSTR | LENGTH | STRCMP | RIGHT | LEFT
373-
| ASCII | LOCATE | REPLACE | REGEX
373+
| ASCII | LOCATE | REPLACE
374374
;
375375

376376
flowControlFunctionName

0 commit comments

Comments
 (0)