Skip to content

Commit a8df4e7

Browse files
committed
peng - simplify if
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent e0360a1 commit a8df4e7

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,25 +1003,23 @@ public UnresolvedPlan visitRexCommand(OpenSearchPPLParser.RexCommandContext ctx)
10031003
int maxMatchLimit =
10041004
(settings != null) ? settings.getSettingValue(Settings.Key.PPL_REX_MAX_MATCH_LIMIT) : 10;
10051005

1006+
int userMaxMatch = maxMatch.orElse(1);
10061007
int effectiveMaxMatch;
1007-
if (maxMatch.isPresent()) {
1008-
if (maxMatch.get() == 0) {
1009-
effectiveMaxMatch = maxMatchLimit;
1010-
} else if (maxMatch.get() > maxMatchLimit) {
1011-
throw new IllegalArgumentException(
1012-
String.format(
1013-
"Rex command max_match value (%d) exceeds the configured limit (%d). "
1014-
+ "Consider using a smaller max_match value"
1015-
+ (settings != null
1016-
? " or adjust the plugins.ppl.rex.max_match.limit setting."
1017-
: "."),
1018-
maxMatch.get(),
1019-
maxMatchLimit));
1020-
} else {
1021-
effectiveMaxMatch = maxMatch.get();
1022-
}
1008+
1009+
if (userMaxMatch == 0) {
1010+
effectiveMaxMatch = maxMatchLimit;
1011+
} else if (userMaxMatch > maxMatchLimit) {
1012+
throw new IllegalArgumentException(
1013+
String.format(
1014+
"Rex command max_match value (%d) exceeds the configured limit (%d). "
1015+
+ "Consider using a smaller max_match value"
1016+
+ (settings != null
1017+
? " or adjust the plugins.ppl.rex.max_match.limit setting."
1018+
: "."),
1019+
userMaxMatch,
1020+
maxMatchLimit));
10231021
} else {
1024-
effectiveMaxMatch = 1;
1022+
effectiveMaxMatch = userMaxMatch;
10251023
}
10261024

10271025
return new Rex(field, pattern, mode, Optional.of(effectiveMaxMatch));

0 commit comments

Comments
 (0)