4444public class AINodeForecastIT {
4545
4646 private static final String FORECAST_TABLE_FUNCTION_SQL_TEMPLATE =
47- "SELECT * FROM FORECAST(model_id=>'%s', targets=>(SELECT time, s%d FROM db.AI) ORDER BY time)" ;
47+ "SELECT * FROM FORECAST(" +
48+ "model_id=>'%s', " +
49+ "targets=>(SELECT time, s%d FROM db.AI), " +
50+ "output_start_time=>%d, " +
51+ "output_length=>%d, " +
52+ "output_interval=>'%s', " +
53+ "timecol=>'%s'" +
54+ ")" ;
4855
4956 @ BeforeClass
5057 public static void setUp () throws Exception {
@@ -84,7 +91,11 @@ public void forecastTableFunctionTest(
8491 // Invoke forecast table function for specified models, there should exist result.
8592 for (int i = 0 ; i < 4 ; i ++) {
8693 String forecastTableFunctionSQL =
87- String .format (FORECAST_TABLE_FUNCTION_SQL_TEMPLATE , modelInfo .getModelId (), i );
94+ String .format (
95+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
96+ modelInfo .getModelId (),
97+ i , 2880 , 96 , "1s" , "time"
98+ );
8899 try (ResultSet resultSet = statement .executeQuery (forecastTableFunctionSQL )) {
89100 int count = 0 ;
90101 while (resultSet .next ()) {
@@ -95,4 +106,59 @@ public void forecastTableFunctionTest(
95106 }
96107 }
97108 }
109+
110+ @ Test
111+ public void forecastTableFunctionErrorTest () throws SQLException {
112+ for (AINodeTestUtils .FakeModelInfo modelInfo : BUILTIN_MODEL_MAP .values ()) {
113+ try (Connection connection = EnvFactory .getEnv ().getConnection (BaseEnv .TABLE_SQL_DIALECT );
114+ Statement statement = connection .createStatement ()) {
115+ forecastTableFunctionErrorTest (statement , modelInfo );
116+ }
117+ }
118+ }
119+ public void forecastTableFunctionErrorTest (
120+ Statement statement , AINodeTestUtils .FakeModelInfo modelInfo ) throws SQLException {
121+ // OUTPUT_START_TIME error
122+ String invalidOutputStartTimeSQL = String .format (
123+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
124+ modelInfo .getModelId (),
125+ 0 , 2879 , 96 , "1s" , "time"
126+ );
127+ errorTest (statement , invalidOutputStartTimeSQL ,
128+ "The OUTPUT_START_TIME should be greater than the maximum timestamp of target time series. Expected greater than [2879] but found [2879]." );
129+
130+ // OUTPUT_LENGTH error
131+ String invalidOutputLengthSQL = String .format (
132+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
133+ modelInfo .getModelId (),
134+ 0 , 2880 , 0 , "1s" , "time"
135+ );
136+ errorTest (statement , invalidOutputLengthSQL , "OUTPUT_LENGTH should be greater than 0" );
137+
138+ // OUTPUT_INTERVAL error
139+ String invalidOutputIntervalSQL = String .format (
140+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
141+ modelInfo .getModelId (),
142+ 0 , 2880 , 96 , "0s" , "time"
143+ );
144+ errorTest (statement , invalidOutputIntervalSQL , "OUTPUT_INTERVAL should be greater than 0" );
145+
146+ // TIMECOL error-1
147+ String invalidTimecolSQL1 = String .format (
148+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
149+ modelInfo .getModelId (),
150+ 0 , 2880 , 96 , "1s" , "nonexistent_column"
151+ );
152+ errorTest (statement , invalidTimecolSQL1 ,
153+ "Required column [nonexistent_column] not found in the source table argument." );
154+
155+ // TIMECOL error-2
156+ String invalidTimecolSQL2 = String .format (
157+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
158+ modelInfo .getModelId (),
159+ 0 , 2880 , 96 , "1s" , "s0"
160+ );
161+ errorTest (statement , invalidTimecolSQL2 , "The type of the column s0 is not as expected." );
162+ }
163+
98164}
0 commit comments