Skip to content

Commit 555bdec

Browse files
author
Liu Zhengyun
committed
add throw exception sentences in some cases
1 parent dae76be commit 555bdec

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
public class AINodeForecastIT {
4545

4646
private static final String FORECAST_TABLE_FUNCTION_SQL_TEMPLATE =
47-
"SELECT * FROM FORECAST(model_id=>'%s', input=>(SELECT time, s%d FROM db.AI) ORDER BY time)";
47+
"SELECT * FROM FORECAST(model_id=>'%s', targets=>(SELECT time, s%d FROM db.AI) ORDER BY time)";
4848

4949
@BeforeClass
5050
public static void setUp() throws Exception {
@@ -81,7 +81,7 @@ public void forecastTableFunctionTest() throws SQLException {
8181

8282
public void forecastTableFunctionTest(
8383
Statement statement, AINodeTestUtils.FakeModelInfo modelInfo) throws SQLException {
84-
// Invoke call inference for specified models, there should exist result.
84+
// Invoke forecast table function for specified models, there should exist result.
8585
for (int i = 0; i < 4; i++) {
8686
String forecastTableFunctionSQL =
8787
String.format(FORECAST_TABLE_FUNCTION_SQL_TEMPLATE, modelInfo.getModelId(), i);
@@ -90,7 +90,7 @@ public void forecastTableFunctionTest(
9090
while (resultSet.next()) {
9191
count++;
9292
}
93-
// Ensure the call inference return results
93+
// Ensure the forecast sentence return results
9494
Assert.assertTrue(count > 0);
9595
}
9696
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ public void finish(
344344

345345
private TsBlock classify() {
346346
int outputLength = inputRecords.size();
347+
// construct inputTSBlock for AINode
347348
while (!inputRecords.isEmpty()) {
348349
Record row = inputRecords.removeFirst();
349350
inputTsBlockBuilder.getTimeColumnBuilder().writeLong(row.getLong(0));

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) {
292292

293293
List<Type> targetColumnTypes = new ArrayList<>();
294294
List<Optional<String>> allInputColumnsName = targets.getFieldNames();
295-
List<Type> allTargetColumnsType = targets.getFieldTypes();
295+
List<Type> allInputColumnsType = targets.getFieldTypes();
296296

297297
// predicated columns = all input columns except timecol / partition by columns
298298
for (int i = 0, size = allInputColumnsName.size(); i < size; i++) {
@@ -302,13 +302,20 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) {
302302
continue;
303303
}
304304

305-
Type columnType = allTargetColumnsType.get(i);
305+
Type columnType = allInputColumnsType.get(i);
306306
targetColumnTypes.add(columnType);
307307
checkType(columnType, fieldName.get());
308308
requiredIndexList.add(i);
309309
properColumnSchemaBuilder.addField(fieldName.get(), columnType);
310310
}
311311

312+
if (targetColumnTypes.size() > 1) {
313+
throw new SemanticException(
314+
String.format(
315+
"%s should not contain more than one target column, found [%s] target columns.",
316+
TARGETS_PARAMETER_NAME, targetColumnTypes.size()));
317+
}
318+
312319
boolean keepInput =
313320
(boolean) ((ScalarArgument) arguments.get(KEEP_INPUT_PARAMETER_NAME)).getValue();
314321
if (keepInput) {
@@ -478,6 +485,12 @@ public void finish(
478485
}
479486
long outputTime =
480487
(outputStartTime == Long.MIN_VALUE) ? (inputEndTime + interval) : outputStartTime;
488+
if (outputTime <= inputEndTime) {
489+
throw new SemanticException(
490+
String.format(
491+
"The %s should be greater than the maximum timestamp of target time series. Expected greater than [%s] but found [%s].",
492+
OUTPUT_START_TIME, inputEndTime, outputTime));
493+
}
481494
for (int i = 0; i < outputLength; i++) {
482495
properColumnBuilders.get(0).writeLong(outputTime + interval * i);
483496
}
@@ -517,6 +530,7 @@ public void finish(
517530
}
518531

519532
private TsBlock forecast() {
533+
// construct inputTSBlock for AINode
520534
while (!inputRecords.isEmpty()) {
521535
Record row = inputRecords.removeFirst();
522536
inputTsBlockBuilder.getTimeColumnBuilder().writeLong(row.getLong(0));

0 commit comments

Comments
 (0)