Skip to content

Commit

Permalink
Merge pull request #185 from SiriDB/offset
Browse files Browse the repository at this point in the history
Implement option for Offset
  • Loading branch information
joente authored Oct 24, 2023
2 parents f0edd48 + 2b0b525 commit fb0463e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions grammar/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class SiriGrammar(Grammar):
k_ninf = Sequence('-', k_inf)
k_now = Keyword('now')
k_number = Keyword('number')
k_offset = Keyword('offset')
k_online = Keyword('online')
k_open_files = Keyword('open_files')
k_or = Keyword('or')
Expand Down Expand Up @@ -527,6 +528,9 @@ class SiriGrammar(Grammar):
f_last = Sequence(
k_last,
'(', Optional(time_expr), ')')
f_offset = Sequence(
k_offset,
'(', time_expr, ')')
f_timeval = Sequence(
k_timeval,
'(', ')')
Expand Down Expand Up @@ -572,6 +576,7 @@ class SiriGrammar(Grammar):

aggregate_functions = List(Choice(
f_all,
f_offset,
f_limit,
f_mean,
f_sum,
Expand Down
4 changes: 3 additions & 1 deletion include/siri/grammar/grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* should be used with the libcleri module.
*
* Source class: SiriGrammar
* Created at: 2022-05-05 15:08:05
* Created at: 2023-10-24 15:46:26
*/
#ifndef CLERI_EXPORT_SIRI_GRAMMAR_GRAMMAR_H_
#define CLERI_EXPORT_SIRI_GRAMMAR_GRAMMAR_H_
Expand Down Expand Up @@ -70,6 +70,7 @@ enum cleri_grammar_ids {
CLERI_GID_F_MEDIAN_HIGH,
CLERI_GID_F_MEDIAN_LOW,
CLERI_GID_F_MIN,
CLERI_GID_F_OFFSET,
CLERI_GID_F_POINTS,
CLERI_GID_F_PVARIANCE,
CLERI_GID_F_STDDEV,
Expand Down Expand Up @@ -201,6 +202,7 @@ enum cleri_grammar_ids {
CLERI_GID_K_NINF,
CLERI_GID_K_NOW,
CLERI_GID_K_NUMBER,
CLERI_GID_K_OFFSET,
CLERI_GID_K_ONLINE,
CLERI_GID_K_OPEN_FILES,
CLERI_GID_K_OR,
Expand Down
4 changes: 2 additions & 2 deletions include/siri/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define SIRIDB_VERSION_MAJOR 2
#define SIRIDB_VERSION_MINOR 0
#define SIRIDB_VERSION_PATCH 50
#define SIRIDB_VERSION_PATCH 51

/*
* Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions.
Expand All @@ -15,7 +15,7 @@
* Note that debian alpha packages should use versions like this:
* 2.0.34-0alpha0
*/
#define SIRIDB_VERSION_PRE_RELEASE ""
#define SIRIDB_VERSION_PRE_RELEASE "-alpha-2"

#ifndef NDEBUG
#define SIRIDB_VERSION_BUILD_RELEASE "+debug"
Expand Down
20 changes: 14 additions & 6 deletions src/siri/db/aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void siridb_init_aggregates(void)
vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
{
uint32_t gid;
siridb_aggr_t * aggr;
siridb_aggr_t * aggr = NULL;
vec_t * vec = vec_new(VEC_DEFAULT_SIZE);
if (vec == NULL)
{
Expand All @@ -221,6 +221,19 @@ vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)

switch (gid)
{
case CLERI_GID_F_OFFSET:
if (aggr == NULL || aggr->group_by == 0)
{
sprintf(err_msg,
"Offset must be used after an aggregation method.");
siridb_aggregate_list_free(vec);
return NULL;
}
/* group_by is always > 0 */
aggr->offset = CLERI_NODE_DATA(
cleri_gn(cleri_gn(cleri_gn(children)
->children)->children->next->next)) % aggr->group_by;
break;
case CLERI_GID_F_LIMIT:
AGGR_NEW
{
Expand Down Expand Up @@ -319,11 +332,6 @@ vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
case CLERI_GID_F_TIMEVAL:
case CLERI_GID_F_INTERVAL:
AGGR_NEW
{
aggr->timespan = 1;
aggr->group_by = 0;
}

VEC_APPEND

break;
Expand Down
14 changes: 12 additions & 2 deletions src/siri/grammar/grammar.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* should be used with the libcleri module.
*
* Source class: SiriGrammar
* Created at: 2022-05-05 15:08:05
* Created at: 2023-10-24 15:46:26
*/

#include "siri/grammar/grammar.h"
Expand Down Expand Up @@ -124,6 +124,7 @@ cleri_grammar_t * compile_siri_grammar_grammar(void)
);
cleri_t * k_now = cleri_keyword(CLERI_GID_K_NOW, "now", CLERI_CASE_SENSITIVE);
cleri_t * k_number = cleri_keyword(CLERI_GID_K_NUMBER, "number", CLERI_CASE_SENSITIVE);
cleri_t * k_offset = cleri_keyword(CLERI_GID_K_OFFSET, "offset", CLERI_CASE_SENSITIVE);
cleri_t * k_online = cleri_keyword(CLERI_GID_K_ONLINE, "online", CLERI_CASE_SENSITIVE);
cleri_t * k_open_files = cleri_keyword(CLERI_GID_K_OPEN_FILES, "open_files", CLERI_CASE_SENSITIVE);
cleri_t * k_or = cleri_keyword(CLERI_GID_K_OR, "or", CLERI_CASE_SENSITIVE);
Expand Down Expand Up @@ -1050,6 +1051,14 @@ cleri_grammar_t * compile_siri_grammar_grammar(void)
cleri_optional(CLERI_NONE, time_expr),
cleri_token(CLERI_NONE, ")")
);
cleri_t * f_offset = cleri_sequence(
CLERI_GID_F_OFFSET,
4,
k_offset,
cleri_token(CLERI_NONE, "("),
time_expr,
cleri_token(CLERI_NONE, ")")
);
cleri_t * f_timeval = cleri_sequence(
CLERI_GID_F_TIMEVAL,
3,
Expand Down Expand Up @@ -1114,8 +1123,9 @@ cleri_grammar_t * compile_siri_grammar_grammar(void)
cleri_t * aggregate_functions = cleri_list(CLERI_GID_AGGREGATE_FUNCTIONS, cleri_choice(
CLERI_NONE,
CLERI_FIRST_MATCH,
21,
22,
f_all,
f_offset,
f_limit,
f_mean,
f_sum,
Expand Down

0 comments on commit fb0463e

Please sign in to comment.