Skip to content

Commit

Permalink
Upd with offset
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed Oct 24, 2023
1 parent f0edd48 commit 526c6d4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 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,
'(', Optional(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 14:29:56
*/
#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-0"

#ifndef NDEBUG
#define SIRIDB_VERSION_BUILD_RELEASE "+debug"
Expand Down
31 changes: 25 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,30 @@ 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;
}
if (cleri_gn(cleri_gn(children)->children)
->children->next->next->next != NULL)
{
/* result is always positive, checked earlier */
aggr->offset = CLERI_NODE_DATA(
cleri_gn(cleri_gn(cleri_gn(cleri_gn(children)
->children)->children->next->next)->children));

if (aggr->offset >= aggr->group_by)
{
sprintf(err_msg, "Offset too large.");
siridb_aggregate_list_free(vec);
return NULL;
}
}
break;
case CLERI_GID_F_LIMIT:
AGGR_NEW
{
Expand Down Expand Up @@ -319,11 +343,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
17 changes: 14 additions & 3 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 14:29:56
*/

#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, "("),
cleri_optional(CLERI_NONE, time_expr),
cleri_token(CLERI_NONE, ")")
);
cleri_t * f_timeval = cleri_sequence(
CLERI_GID_F_TIMEVAL,
3,
Expand Down Expand Up @@ -1094,7 +1103,8 @@ cleri_grammar_t * compile_siri_grammar_grammar(void)
cleri_choice(
CLERI_NONE,
CLERI_FIRST_MATCH,
13,
14,
k_offset,
k_mean,
k_median,
k_median_high,
Expand All @@ -1114,8 +1124,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 526c6d4

Please sign in to comment.