This is an automated email from the ASF dual-hosted git repository.
JackieTien97 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 0c7dcd8a5f1 Fix IndexOutOfBoundsException and improve validation in
pattern_match TVF (#17574)
0c7dcd8a5f1 is described below
commit 0c7dcd8a5f10eddc762251f697c892bcd9b6eeb5
Author: Lin Xintao <[email protected]>
AuthorDate: Wed Apr 29 07:51:09 2026 +0800
Fix IndexOutOfBoundsException and improve validation in pattern_match TVF
(#17574)
---
.../iotdb/relational/it/db/it/IoTDBWindowTVFIT.java | 18 ++++++++++++++++++
.../plan/relational/analyzer/StatementAnalyzer.java | 6 ++++--
.../relational/function/tvf/match/QetchAlgorithm.java | 16 ++++++++++++++++
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBWindowTVFIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBWindowTVFIT.java
index dc12a4ec098..20339d4bf1f 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBWindowTVFIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBWindowTVFIT.java
@@ -893,5 +893,23 @@ public class IoTDBWindowTVFIT {
"select * from pattern_match(data => t1 ORDER BY time, time_col =>
'time', data_col => 'value', pattern => '1.0,2.0,1.0', smooth => 0.5, threshold
=> 10.0, width => 1000.0, height => -10.0, smooth_on_pattern => false)",
"height must be a non-negative number",
DATABASE_NAME);
+
+ // test invalid pattern with non-numeric characters should be rejected
+ tableAssertTestFail(
+ "select * from pattern_match(data => t1 ORDER BY time, time_col =>
'time', data_col => 'value', pattern => 'abc,def,ghi', smooth => 0.5, threshold
=> 10.0, width => 1000.0, height => 500.0, smooth_on_pattern => false)",
+ "Invalid pattern",
+ DATABASE_NAME);
+
+ // test empty pattern should be rejected
+ tableAssertTestFail(
+ "select * from pattern_match(data => t1 ORDER BY time, time_col =>
'time', data_col => 'value', pattern => '', smooth => 0.5, threshold => 10.0,
width => 1000.0, height => 500.0, smooth_on_pattern => false)",
+ "Invalid pattern",
+ DATABASE_NAME);
+
+ // test single-point pattern should be rejected (need at least 2 points)
+ tableAssertTestFail(
+ "select * from pattern_match(data => t1 ORDER BY time, time_col =>
'time', data_col => 'value', pattern => '1', smooth => 0.5, threshold => 10.0,
width => 1000.0, height => 500.0, smooth_on_pattern => false)",
+ "Invalid pattern",
+ DATABASE_NAME);
}
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
index 2c838406f47..6d3326dd402 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
@@ -5280,8 +5280,10 @@ public class StatementAnalyzer {
} else {
throw new SemanticException(
String.format(
- "Invalid scalar argument value. Expected type %s, got %s",
- argumentSpecification.getType(),
constantValue.getClass().getSimpleName()));
+ "Invalid scalar argument '%s'. Expected type %s, got %s",
+ argumentSpecification.getName(),
+ argumentSpecification.getType(),
+ constantValue.getClass().getSimpleName()));
}
}
for (Function<Object, String> checker :
argumentSpecification.getCheckers()) {
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/function/tvf/match/QetchAlgorithm.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/function/tvf/match/QetchAlgorithm.java
index 8f290ee02d5..15d843537dd 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/function/tvf/match/QetchAlgorithm.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/function/tvf/match/QetchAlgorithm.java
@@ -242,6 +242,22 @@ public class QetchAlgorithm {
// divided the pattern to multi DataSegment with the regex information
List<PatternSegment> patternSegments = parsePattern2DataSegment(pattern);
+ // Validate that pattern contains at least one data segment with >= 2
points
+ boolean hasDataSegment = false;
+ for (PatternSegment segment : patternSegments) {
+ if (!segment.isConstantChar()) {
+ hasDataSegment = true;
+ break;
+ }
+ }
+ if (!hasDataSegment) {
+ throw new IllegalArgumentException(
+ "Invalid pattern: '"
+ + pattern
+ + "'. Pattern must contain at least two numeric data points
separated by commas,"
+ + " e.g., '1,2,3'");
+ }
+
// trans multi dataSegment to automaton
transDataSegment2Automation(patternSegments);
}