Skip to content

Commit fb0463e

Browse files
authored
Merge pull request #185 from SiriDB/offset
Implement option for Offset
2 parents f0edd48 + 2b0b525 commit fb0463e

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

grammar/grammar.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class SiriGrammar(Grammar):
126126
k_ninf = Sequence('-', k_inf)
127127
k_now = Keyword('now')
128128
k_number = Keyword('number')
129+
k_offset = Keyword('offset')
129130
k_online = Keyword('online')
130131
k_open_files = Keyword('open_files')
131132
k_or = Keyword('or')
@@ -527,6 +528,9 @@ class SiriGrammar(Grammar):
527528
f_last = Sequence(
528529
k_last,
529530
'(', Optional(time_expr), ')')
531+
f_offset = Sequence(
532+
k_offset,
533+
'(', time_expr, ')')
530534
f_timeval = Sequence(
531535
k_timeval,
532536
'(', ')')
@@ -572,6 +576,7 @@ class SiriGrammar(Grammar):
572576

573577
aggregate_functions = List(Choice(
574578
f_all,
579+
f_offset,
575580
f_limit,
576581
f_mean,
577582
f_sum,

include/siri/grammar/grammar.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* should be used with the libcleri module.
66
*
77
* Source class: SiriGrammar
8-
* Created at: 2022-05-05 15:08:05
8+
* Created at: 2023-10-24 15:46:26
99
*/
1010
#ifndef CLERI_EXPORT_SIRI_GRAMMAR_GRAMMAR_H_
1111
#define CLERI_EXPORT_SIRI_GRAMMAR_GRAMMAR_H_
@@ -70,6 +70,7 @@ enum cleri_grammar_ids {
7070
CLERI_GID_F_MEDIAN_HIGH,
7171
CLERI_GID_F_MEDIAN_LOW,
7272
CLERI_GID_F_MIN,
73+
CLERI_GID_F_OFFSET,
7374
CLERI_GID_F_POINTS,
7475
CLERI_GID_F_PVARIANCE,
7576
CLERI_GID_F_STDDEV,
@@ -201,6 +202,7 @@ enum cleri_grammar_ids {
201202
CLERI_GID_K_NINF,
202203
CLERI_GID_K_NOW,
203204
CLERI_GID_K_NUMBER,
205+
CLERI_GID_K_OFFSET,
204206
CLERI_GID_K_ONLINE,
205207
CLERI_GID_K_OPEN_FILES,
206208
CLERI_GID_K_OR,

include/siri/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#define SIRIDB_VERSION_MAJOR 2
88
#define SIRIDB_VERSION_MINOR 0
9-
#define SIRIDB_VERSION_PATCH 50
9+
#define SIRIDB_VERSION_PATCH 51
1010

1111
/*
1212
* Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions.
@@ -15,7 +15,7 @@
1515
* Note that debian alpha packages should use versions like this:
1616
* 2.0.34-0alpha0
1717
*/
18-
#define SIRIDB_VERSION_PRE_RELEASE ""
18+
#define SIRIDB_VERSION_PRE_RELEASE "-alpha-2"
1919

2020
#ifndef NDEBUG
2121
#define SIRIDB_VERSION_BUILD_RELEASE "+debug"

src/siri/db/aggregate.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void siridb_init_aggregates(void)
206206
vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
207207
{
208208
uint32_t gid;
209-
siridb_aggr_t * aggr;
209+
siridb_aggr_t * aggr = NULL;
210210
vec_t * vec = vec_new(VEC_DEFAULT_SIZE);
211211
if (vec == NULL)
212212
{
@@ -221,6 +221,19 @@ vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
221221

222222
switch (gid)
223223
{
224+
case CLERI_GID_F_OFFSET:
225+
if (aggr == NULL || aggr->group_by == 0)
226+
{
227+
sprintf(err_msg,
228+
"Offset must be used after an aggregation method.");
229+
siridb_aggregate_list_free(vec);
230+
return NULL;
231+
}
232+
/* group_by is always > 0 */
233+
aggr->offset = CLERI_NODE_DATA(
234+
cleri_gn(cleri_gn(cleri_gn(children)
235+
->children)->children->next->next)) % aggr->group_by;
236+
break;
224237
case CLERI_GID_F_LIMIT:
225238
AGGR_NEW
226239
{
@@ -319,11 +332,6 @@ vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
319332
case CLERI_GID_F_TIMEVAL:
320333
case CLERI_GID_F_INTERVAL:
321334
AGGR_NEW
322-
{
323-
aggr->timespan = 1;
324-
aggr->group_by = 0;
325-
}
326-
327335
VEC_APPEND
328336

329337
break;

src/siri/grammar/grammar.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* should be used with the libcleri module.
66
*
77
* Source class: SiriGrammar
8-
* Created at: 2022-05-05 15:08:05
8+
* Created at: 2023-10-24 15:46:26
99
*/
1010

1111
#include "siri/grammar/grammar.h"
@@ -124,6 +124,7 @@ cleri_grammar_t * compile_siri_grammar_grammar(void)
124124
);
125125
cleri_t * k_now = cleri_keyword(CLERI_GID_K_NOW, "now", CLERI_CASE_SENSITIVE);
126126
cleri_t * k_number = cleri_keyword(CLERI_GID_K_NUMBER, "number", CLERI_CASE_SENSITIVE);
127+
cleri_t * k_offset = cleri_keyword(CLERI_GID_K_OFFSET, "offset", CLERI_CASE_SENSITIVE);
127128
cleri_t * k_online = cleri_keyword(CLERI_GID_K_ONLINE, "online", CLERI_CASE_SENSITIVE);
128129
cleri_t * k_open_files = cleri_keyword(CLERI_GID_K_OPEN_FILES, "open_files", CLERI_CASE_SENSITIVE);
129130
cleri_t * k_or = cleri_keyword(CLERI_GID_K_OR, "or", CLERI_CASE_SENSITIVE);
@@ -1050,6 +1051,14 @@ cleri_grammar_t * compile_siri_grammar_grammar(void)
10501051
cleri_optional(CLERI_NONE, time_expr),
10511052
cleri_token(CLERI_NONE, ")")
10521053
);
1054+
cleri_t * f_offset = cleri_sequence(
1055+
CLERI_GID_F_OFFSET,
1056+
4,
1057+
k_offset,
1058+
cleri_token(CLERI_NONE, "("),
1059+
time_expr,
1060+
cleri_token(CLERI_NONE, ")")
1061+
);
10531062
cleri_t * f_timeval = cleri_sequence(
10541063
CLERI_GID_F_TIMEVAL,
10551064
3,
@@ -1114,8 +1123,9 @@ cleri_grammar_t * compile_siri_grammar_grammar(void)
11141123
cleri_t * aggregate_functions = cleri_list(CLERI_GID_AGGREGATE_FUNCTIONS, cleri_choice(
11151124
CLERI_NONE,
11161125
CLERI_FIRST_MATCH,
1117-
21,
1126+
22,
11181127
f_all,
1128+
f_offset,
11191129
f_limit,
11201130
f_mean,
11211131
f_sum,

0 commit comments

Comments
 (0)