3434#define FLB_SP_COUNT 3
3535#define FLB_SP_MIN 4
3636#define FLB_SP_MAX 5
37+ #define FLB_SP_FORECAST 6
38+
39+ /* Update this whenever a new aggregate function is added */
40+ #define AGGREGATE_FUNCTIONS 6
3741
3842/* Date time functions */
3943#define FLB_SP_NOW 10
4347#define FLB_SP_RECORD_TAG 20
4448#define FLB_SP_RECORD_TIME 21
4549
46- /* Timeseries functions */
47- #define FLB_SP_TIMESERIES_START 30
48- #define FLB_SP_FORECAST 30
49- #define FLB_SP_FORECAST_R 31
50- #define FLB_SP_TIMESERIES_END 39
51-
5250/* Status */
5351#define FLB_SP_OK 0
5452#define FLB_SP_ERROR -1
@@ -78,7 +76,6 @@ enum Expressions {
7876 FLB_EXP_NULL ,
7977 FLB_EXP_FUNC ,
8078 FLB_EXP_PARAM ,
81- FLB_EXP_TIMESERIES ,
8279};
8380
8481/* Logical operation */
@@ -124,13 +121,13 @@ struct flb_sp_cmd_key {
124121 int aggr_func ; /* Aggregation function */
125122 int time_func ; /* Time function */
126123 int record_func ; /* Record function */
127- int timeseries_func ; /* Timeseries function */
128124 flb_sds_t name ; /* Parent Key name */
129125 flb_sds_t alias ; /* Key output alias (key AS alias) */
130- flb_sds_t name_keys ; /* Key name with sub-keys */
131126 void * gb_key ; /* Key name reference to gb_key */
127+ // TODO: make it a general union type (or array of values)
128+ int constant ; /* constant parameter value
129+ (used specifically for timeseries_forecast) */
132130 struct mk_list * subkeys ; /* sub-keys selection */
133- struct flb_exp_timeseries * timeseries ; /* Timeseries functions */
134131 struct mk_list _head ; /* Link to flb_sp_cmd->keys */
135132};
136133
@@ -158,13 +155,7 @@ struct flb_sp_cmd {
158155 struct flb_sp_window window ; /* WINDOW window in select statement */
159156
160157 struct mk_list gb_keys ; /* list head of group-by record fields */
161-
162- int timeseries_num ; /* Number of timeseries functions */
163- /*
164- * This keeps the temporary list of parameters parameters in timeseries
165- * functions during SQL statement parsing.
166- */
167- struct mk_list * tmp_params ;
158+ char * alias ;
168159
169160 /*
170161 * When parsing a SQL statement that have references to keys with sub-keys
@@ -244,21 +235,6 @@ struct flb_exp_param {
244235 struct flb_exp * param ;
245236};
246237
247- struct flb_exp_timeseries {
248- int type ;
249- struct mk_list _head ;
250- struct mk_list params ;
251-
252- struct timeseries * (* cb_func_alloc ) (int );
253- struct timeseries * (* cb_func_clone ) (struct timeseries * );
254- void (* cb_func_add ) (struct timeseries * , struct flb_time * );
255- void (* cb_func_rem ) (struct timeseries * , struct timeseries * ,
256- struct flb_time * );
257- void (* cb_func_calc ) (struct timeseries * , struct flb_sp_cmd_key * ,
258- msgpack_packer * , int , struct flb_time * );
259- void (* cb_func_destroy ) (struct timeseries * );
260- };
261-
262238struct flb_sp_cmd * flb_sp_cmd_create (const char * sql );
263239void flb_sp_cmd_destroy (struct flb_sp_cmd * cmd );
264240
@@ -271,9 +247,9 @@ void flb_sp_cmd_stream_prop_del(struct flb_sp_cmd_prop *prop);
271247const char * flb_sp_cmd_stream_prop_get (struct flb_sp_cmd * cmd , const char * key );
272248
273249/* Selection keys */
274- int flb_sp_cmd_key_add (struct flb_sp_cmd * cmd , int func ,
275- const char * key_name , const char * key_alias );
250+ int flb_sp_cmd_key_add (struct flb_sp_cmd * cmd , int func , const char * key_name );
276251void flb_sp_cmd_key_del (struct flb_sp_cmd_key * key );
252+ void flb_sp_cmd_alias_add (struct flb_sp_cmd * cmd , const char * key_alias );
277253int flb_sp_cmd_source (struct flb_sp_cmd * cmd , int type , const char * source );
278254void flb_sp_cmd_dump (struct flb_sp_cmd * cmd );
279255
@@ -307,9 +283,7 @@ void flb_sp_cmd_gb_key_del(struct flb_sp_cmd_gb_key *key);
307283
308284void flb_sp_cmd_limit_add (struct flb_sp_cmd * cmd , int limit );
309285
310- /* Timeseries */
311- int flb_sp_cmd_param_add (struct flb_sp_cmd * cmd , int func , struct flb_exp * param );
312- int flb_sp_cmd_timeseries (struct flb_sp_cmd * cmd , char * func , const char * key_alias );
313- void flb_cmd_params_del (struct mk_list * params );
286+ int flb_sp_cmd_timeseries_forecast (struct flb_sp_cmd * cmd , int func ,
287+ const char * key_name , int seconds );
314288
315289#endif
0 commit comments