Skip to content

Commit 07e2cfb

Browse files
authored
fix(tvf): validate non-negative width and height in pattern_match (#17515)
1 parent aa4b551 commit 07e2cfb

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBWindowTVFIT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,5 +881,17 @@ public void testPatternMatchFunction() {
881881
"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 => -1.1, width => 1000.0, height => 500.0, smooth_on_pattern => false)",
882882
"threshold must be a non-negative number",
883883
DATABASE_NAME);
884+
885+
// test negative width should be rejected
886+
tableAssertTestFail(
887+
"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 => -1.0, height => 500.0, smooth_on_pattern => false)",
888+
"width must be a non-negative number",
889+
DATABASE_NAME);
890+
891+
// test negative height should be rejected
892+
tableAssertTestFail(
893+
"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)",
894+
"height must be a non-negative number",
895+
DATABASE_NAME);
884896
}
885897
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/tvf/PatternMatchTableFunction.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDF
107107

108108
Double smoothValue = (Double) ((ScalarArgument) arguments.get(SMOOTH_PARAM)).getValue();
109109
Double thresholdValue = (Double) ((ScalarArgument) arguments.get(THRESHOLD_PARAM)).getValue();
110+
Double widthValue = (Double) ((ScalarArgument) arguments.get(WIDTH_PARAM)).getValue();
111+
Double heightValue = (Double) ((ScalarArgument) arguments.get(HEIGHT_PARAM)).getValue();
110112
if (smoothValue < 0) {
111113
throw new UDFException("smooth must be a non-negative number, but got: " + smoothValue);
112114
}
113115
if (thresholdValue < 0) {
114116
throw new UDFException("threshold must be a non-negative number, but got: " + thresholdValue);
115117
}
118+
if (widthValue < 0) {
119+
throw new UDFException("width must be a non-negative number, but got: " + widthValue);
120+
}
121+
if (heightValue < 0) {
122+
throw new UDFException("height must be a non-negative number, but got: " + heightValue);
123+
}
116124

117125
// outputColumnSchema description
118126
DescribedSchema properColumnSchema =

0 commit comments

Comments
 (0)