Skip to content

Commit 3cc1cf2

Browse files
committed
chen - limit offset field only in extraction mode
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent 702ac02 commit 3cc1cf2

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

docs/user/ppl/cmd/rex.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ rex [mode=<mode>] field=<field> <pattern> [max_match=<int>] [offset_field=<strin
3535
- Backreferences: ``\1``, ``\2``, etc. reference captured groups in replacement
3636

3737
* max_match: optional integer (default=1). Maximum number of matches to extract. If greater than 1, extracted fields become arrays. The value 0 means unlimited matches, but is automatically capped to the configured limit (default: 10, configurable via ``plugins.ppl.rex.max_match.limit``).
38-
* offset_field: optional string. Field name to store the character offset positions of matches.
38+
* offset_field: optional string. Field name to store the character offset positions of matches. Only available in extract mode.
3939

4040
Example 1: Basic Field Extraction
4141
==================================

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,12 @@ public UnresolvedPlan visitRexCommand(OpenSearchPPLParser.RexCommandContext ctx)
10141014
}
10151015
}
10161016

1017+
if (mode == Rex.RexMode.SED && offsetField.isPresent()) {
1018+
throw new IllegalArgumentException(
1019+
"Rex command: offset_field cannot be used with mode=sed. "
1020+
+ "The offset_field option is only supported in extract mode.");
1021+
}
1022+
10171023
int maxMatchLimit =
10181024
(settings != null) ? settings.getSettingValue(Settings.Key.PPL_REX_MAX_MATCH_LIMIT) : 10;
10191025

ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,4 +1090,10 @@ public void testBinCommandDuplicateParameter() {
10901090
// Test that duplicate parameters throw an exception
10911091
plan("search source=test | bin index_field span=10 span=20");
10921092
}
1093+
1094+
@Test(expected = IllegalArgumentException.class)
1095+
public void testRexSedModeWithOffsetFieldThrowsException() {
1096+
// Test that SED mode and offset_field cannot be used together (align with Splunk behavior)
1097+
plan("source=test | rex field=email mode=sed offset_field=matchpos \"s/@.*/@company.com/\"");
1098+
}
10931099
}

0 commit comments

Comments
 (0)