Skip to content

Commit 2838616

Browse files
Liu ZhengyunCRZbulabula
authored andcommitted
fix IT
1 parent eeeabc2 commit 2838616

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeConcurrentForecastIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class AINodeConcurrentForecastIT {
4949
private static final Logger LOGGER = LoggerFactory.getLogger(AINodeConcurrentForecastIT.class);
5050

5151
private static final String FORECAST_TABLE_FUNCTION_SQL_TEMPLATE =
52-
"SELECT * FROM FORECAST(model_id=>'%s', input=>(SELECT time,s FROM root.AI) ORDER BY time, output_length=>%d)";
52+
"SELECT * FROM FORECAST(model_id=>'%s', targets=>(SELECT time,s FROM root.AI) ORDER BY time, output_length=>%d)";
5353

5454
@BeforeClass
5555
public static void setUp() throws Exception {

integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeForecastIT.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public class AINodeForecastIT {
4747
private static final String FORECAST_TABLE_FUNCTION_SQL_TEMPLATE =
4848
"SELECT * FROM FORECAST("
4949
+ "model_id=>'%s', "
50-
+ "targets=>(SELECT time, s%d FROM db.AI), "
50+
+ "targets=>(SELECT time, s%d FROM db.AI WHERE time<%d ORDER BY time DESC LIMIT %d) ORDER BY time, "
5151
+ "output_start_time=>%d, "
5252
+ "output_length=>%d, "
53-
+ "output_interval=>'%s', "
53+
+ "output_interval=>%d, "
5454
+ "timecol=>'%s'"
5555
+ ")";
5656

@@ -63,7 +63,7 @@ public static void setUp() throws Exception {
6363
statement.execute("CREATE DATABASE db");
6464
statement.execute(
6565
"CREATE TABLE db.AI (s0 FLOAT FIELD, s1 DOUBLE FIELD, s2 INT32 FIELD, s3 INT64 FIELD)");
66-
for (int i = 0; i < 2880; i++) {
66+
for (int i = 0; i < 5760; i++) {
6767
statement.execute(
6868
String.format(
6969
"INSERT INTO db.AI(time,s0,s1,s2,s3) VALUES(%d,%f,%f,%d,%d)",
@@ -96,9 +96,11 @@ public void forecastTableFunctionTest(
9696
FORECAST_TABLE_FUNCTION_SQL_TEMPLATE,
9797
modelInfo.getModelId(),
9898
i,
99+
5760,
99100
2880,
101+
5760,
100102
96,
101-
"1s",
103+
1,
102104
"time");
103105
try (ResultSet resultSet = statement.executeQuery(forecastTableFunctionSQL)) {
104106
int count = 0;
@@ -129,52 +131,58 @@ public void forecastTableFunctionErrorTest(
129131
FORECAST_TABLE_FUNCTION_SQL_TEMPLATE,
130132
modelInfo.getModelId(),
131133
0,
132-
2879,
134+
5760,
135+
2880,
136+
5759,
133137
96,
134-
"1s",
138+
1,
135139
"time");
136140
errorTest(
137141
statement,
138142
invalidOutputStartTimeSQL,
139-
"The OUTPUT_START_TIME should be greater than the maximum timestamp of target time series. Expected greater than [2879] but found [2879].");
143+
"701: The OUTPUT_START_TIME should be greater than the maximum timestamp of target time series. Expected greater than [5759] but found [5759].");
140144

141145
// OUTPUT_LENGTH error
142146
String invalidOutputLengthSQL =
143147
String.format(
144-
FORECAST_TABLE_FUNCTION_SQL_TEMPLATE, modelInfo.getModelId(), 0, 2880, 0, "1s", "time");
145-
errorTest(statement, invalidOutputLengthSQL, "OUTPUT_LENGTH should be greater than 0");
148+
FORECAST_TABLE_FUNCTION_SQL_TEMPLATE,
149+
modelInfo.getModelId(),
150+
0,
151+
5760,
152+
2880,
153+
5760,
154+
0,
155+
1,
156+
"time");
157+
errorTest(statement, invalidOutputLengthSQL, "701: OUTPUT_LENGTH should be greater than 0");
146158

147159
// OUTPUT_INTERVAL error
148160
String invalidOutputIntervalSQL =
149161
String.format(
150162
FORECAST_TABLE_FUNCTION_SQL_TEMPLATE,
151163
modelInfo.getModelId(),
152164
0,
165+
5760,
153166
2880,
167+
5760,
154168
96,
155-
"0s",
169+
-1,
156170
"time");
157-
errorTest(statement, invalidOutputIntervalSQL, "OUTPUT_INTERVAL should be greater than 0");
171+
errorTest(statement, invalidOutputIntervalSQL, "701: OUTPUT_INTERVAL should be greater than 0");
158172

159-
// TIMECOL error-1
160-
String invalidTimecolSQL1 =
173+
// TIMECOL error
174+
String invalidTimecolSQL2 =
161175
String.format(
162176
FORECAST_TABLE_FUNCTION_SQL_TEMPLATE,
163177
modelInfo.getModelId(),
164178
0,
179+
5760,
165180
2880,
181+
5760,
166182
96,
167-
"1s",
168-
"nonexistent_column");
183+
1,
184+
"s0");
169185
errorTest(
170-
statement,
171-
invalidTimecolSQL1,
172-
"Required column [nonexistent_column] not found in the source table argument.");
173-
174-
// TIMECOL error-2
175-
String invalidTimecolSQL2 =
176-
String.format(
177-
FORECAST_TABLE_FUNCTION_SQL_TEMPLATE, modelInfo.getModelId(), 0, 2880, 96, "1s", "s0");
178-
errorTest(statement, invalidTimecolSQL2, "The type of the column s0 is not as expected.");
186+
statement, invalidTimecolSQL2, "701: The type of the column [s0] is not as expected.");
179187
}
180188
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.util.ArrayList;
5959
import java.util.Arrays;
6060
import java.util.Collections;
61+
import java.util.Comparator;
6162
import java.util.HashMap;
6263
import java.util.HashSet;
6364
import java.util.LinkedList;
@@ -275,7 +276,7 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) {
275276
}
276277

277278
long outputInterval = (long) ((ScalarArgument) arguments.get(OUTPUT_INTERVAL)).getValue();
278-
if (outputInterval <= 0) {
279+
if (outputInterval < 0) {
279280
throw new SemanticException(String.format("%s should be greater than 0", OUTPUT_INTERVAL));
280281
}
281282

@@ -470,6 +471,9 @@ public void finish(
470471

471472
int columnSize = properColumnBuilders.size();
472473

474+
// sort inputRecords in ascending order by timestamp
475+
inputRecords.sort(Comparator.comparingLong(record -> record.getLong(0)));
476+
473477
// time column
474478
long inputStartTime = inputRecords.getFirst().getLong(0);
475479
long inputEndTime = inputRecords.getLast().getLong(0);

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/TableFunctionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public void testForecastFunction() {
356356

357357
String sql =
358358
"SELECT * FROM FORECAST("
359-
+ "input => (SELECT time,s3 FROM table1 WHERE tag1='shanghai' AND tag2='A3' AND tag3='YY' ORDER BY time DESC LIMIT 1440), "
359+
+ "targets => (SELECT time,s3 FROM table1 WHERE tag1='shanghai' AND tag2='A3' AND tag3='YY' ORDER BY time DESC LIMIT 1440), "
360360
+ "model_id => 'timer_xl')";
361361
LogicalQueryPlan logicalQueryPlan = planTester.createPlan(sql);
362362

@@ -416,7 +416,7 @@ public void testForecastFunctionWithNoLowerCase() {
416416

417417
String sql =
418418
"SELECT * FROM FORECAST("
419-
+ "input => (SELECT time,s3 FROM table1 WHERE tag1='shanghai' AND tag2='A3' AND tag3='YY' ORDER BY time DESC LIMIT 1440), "
419+
+ "targets => (SELECT time,s3 FROM table1 WHERE tag1='shanghai' AND tag2='A3' AND tag3='YY' ORDER BY time DESC LIMIT 1440), "
420420
+ "model_id => 'timer_xl', timecol=>'TiME')";
421421
LogicalQueryPlan logicalQueryPlan = planTester.createPlan(sql);
422422

0 commit comments

Comments
 (0)