4444public class AINodeForecastIT {
4545
4646 private static final String FORECAST_TABLE_FUNCTION_SQL_TEMPLATE =
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- ")" ;
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+ + ")" ;
5555
5656 @ BeforeClass
5757 public static void setUp () throws Exception {
@@ -91,11 +91,14 @@ public void forecastTableFunctionTest(
9191 // Invoke forecast table function for specified models, there should exist result.
9292 for (int i = 0 ; i < 4 ; i ++) {
9393 String forecastTableFunctionSQL =
94- String .format (
95- FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
96- modelInfo .getModelId (),
97- i , 2880 , 96 , "1s" , "time"
98- );
94+ String .format (
95+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
96+ modelInfo .getModelId (),
97+ i ,
98+ 2880 ,
99+ 96 ,
100+ "1s" ,
101+ "time" );
99102 try (ResultSet resultSet = statement .executeQuery (forecastTableFunctionSQL )) {
100103 int count = 0 ;
101104 while (resultSet .next ()) {
@@ -107,58 +110,70 @@ public void forecastTableFunctionTest(
107110 }
108111 }
109112
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." );
113+ @ Test
114+ public void forecastTableFunctionErrorTest () throws SQLException {
115+ for (AINodeTestUtils .FakeModelInfo modelInfo : BUILTIN_MODEL_MAP .values ()) {
116+ try (Connection connection = EnvFactory .getEnv ().getConnection (BaseEnv .TABLE_SQL_DIALECT );
117+ Statement statement = connection .createStatement ()) {
118+ forecastTableFunctionErrorTest (statement , modelInfo );
119+ }
162120 }
121+ }
163122
123+ public void forecastTableFunctionErrorTest (
124+ Statement statement , AINodeTestUtils .FakeModelInfo modelInfo ) throws SQLException {
125+ // OUTPUT_START_TIME error
126+ String invalidOutputStartTimeSQL =
127+ String .format (
128+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
129+ modelInfo .getModelId (),
130+ 0 ,
131+ 2879 ,
132+ 96 ,
133+ "1s" ,
134+ "time" );
135+ errorTest (
136+ statement ,
137+ invalidOutputStartTimeSQL ,
138+ "The OUTPUT_START_TIME should be greater than the maximum timestamp of target time series. Expected greater than [2879] but found [2879]." );
139+
140+ // OUTPUT_LENGTH error
141+ String invalidOutputLengthSQL =
142+ String .format (
143+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE , modelInfo .getModelId (), 0 , 2880 , 0 , "1s" , "time" );
144+ errorTest (statement , invalidOutputLengthSQL , "OUTPUT_LENGTH should be greater than 0" );
145+
146+ // OUTPUT_INTERVAL error
147+ String invalidOutputIntervalSQL =
148+ String .format (
149+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
150+ modelInfo .getModelId (),
151+ 0 ,
152+ 2880 ,
153+ 96 ,
154+ "0s" ,
155+ "time" );
156+ errorTest (statement , invalidOutputIntervalSQL , "OUTPUT_INTERVAL should be greater than 0" );
157+
158+ // TIMECOL error-1
159+ String invalidTimecolSQL1 =
160+ String .format (
161+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE ,
162+ modelInfo .getModelId (),
163+ 0 ,
164+ 2880 ,
165+ 96 ,
166+ "1s" ,
167+ "nonexistent_column" );
168+ errorTest (
169+ statement ,
170+ invalidTimecolSQL1 ,
171+ "Required column [nonexistent_column] not found in the source table argument." );
172+
173+ // TIMECOL error-2
174+ String invalidTimecolSQL2 =
175+ String .format (
176+ FORECAST_TABLE_FUNCTION_SQL_TEMPLATE , modelInfo .getModelId (), 0 , 2880 , 96 , "1s" , "s0" );
177+ errorTest (statement , invalidTimecolSQL2 , "The type of the column s0 is not as expected." );
178+ }
164179}
0 commit comments