diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index ab9345e22c80272b6cbd4b84b0fd7ce4472fda87..2872bcf447fdeacb561aae754b9c85420a3fddc7 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
%type <data> data
interval interval_elem
+ array array_elem_list
%type <datetime> datetime
start_clause end_clause
sdb_conn_node_t *n;
n = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_expr_t, conn_expr_destroy));
- n->cmd = CONNECTION_EXPR;
+ n->cmd = SDB_CONNECTION_EXPR;
CONN_EXPR(n)->expr = $1;
sdb_llist_append(pt, SDB_OBJ(n));
CONN_FETCH($$)->host = $3;
CONN_FETCH($$)->name = NULL;
CONN_FETCH($$)->filter = CONN_MATCHER($4);
- $$->cmd = CONNECTION_FETCH;
+ $$->cmd = SDB_CONNECTION_FETCH;
}
|
FETCH object_type STRING '.' STRING filter_clause
CONN_FETCH($$)->host = $3;
CONN_FETCH($$)->name = $5;
CONN_FETCH($$)->filter = CONN_MATCHER($6);
- $$->cmd = CONNECTION_FETCH;
+ $$->cmd = SDB_CONNECTION_FETCH;
}
;
conn_list_t, conn_list_destroy));
CONN_LIST($$)->type = $2;
CONN_LIST($$)->filter = CONN_MATCHER($3);
- $$->cmd = CONNECTION_LIST;
+ $$->cmd = SDB_CONNECTION_LIST;
}
;
* Returns detailed information about <type> matching condition.
*/
lookup_statement:
- LOOKUP HOSTS_T matching_clause filter_clause
+ LOOKUP object_type_plural matching_clause filter_clause
{
- /* TODO: support other types as well */
-
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_lookup_t, conn_lookup_destroy));
- CONN_LOOKUP($$)->type = SDB_HOST;
+ CONN_LOOKUP($$)->type = $2;
CONN_LOOKUP($$)->matcher = CONN_MATCHER($3);
CONN_LOOKUP($$)->filter = CONN_MATCHER($4);
- $$->cmd = CONNECTION_LOOKUP;
+ $$->cmd = SDB_CONNECTION_LOOKUP;
}
;
CONN_TS($$)->metric = $4;
CONN_TS($$)->opts.start = $5;
CONN_TS($$)->opts.end = $6;
- $$->cmd = CONNECTION_TIMESERIES;
+ $$->cmd = SDB_CONNECTION_TIMESERIES;
}
;
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_matcher_t, conn_matcher_destroy));
- $$->cmd = CONNECTION_MATCHER;
+ $$->cmd = SDB_CONNECTION_MATCHER;
CONN_MATCHER($$)->matcher = $1;
}
;
sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
}
|
- HOST_T
- {
- /* TODO: this only works as long as queries
- * are limited to hosts */
- $$ = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
- }
- |
field
{
$$ = sdb_store_expr_fieldvalue($1);
METRIC_T { $$ = SDB_METRIC; }
|
ATTRIBUTE_T { $$ = SDB_ATTRIBUTE; }
+ |
+ BACKEND_T { $$ = SDB_FIELD_BACKEND; }
;
field:
datetime { $$.type = SDB_TYPE_DATETIME; $$.data.datetime = $1; }
|
interval { $$ = $1; }
+ |
+ array { $$ = $1; }
;
datetime:
unit = sdb_strpunit($2);
if (! unit) {
sdb_fe_yyerrorf(&yylloc, scanner,
- YY_("invalid time unit %s"), $2);
+ YY_("syntax error, invalid time unit %s"), $2);
free($2); $2 = NULL;
YYABORT;
}
}
;
+array:
+ '[' array_elem_list ']'
+ {
+ $$ = $2;
+ }
+ ;
+
+array_elem_list:
+ array_elem_list ',' data
+ {
+ size_t elem_size;
+
+ if (($3.type & SDB_TYPE_ARRAY) || (($1.type & 0xff) != $3.type)) {
+ sdb_fe_yyerrorf(&yylloc, scanner, YY_("syntax error, "
+ "cannot use element of type %s in array of type %s"),
+ SDB_TYPE_TO_STRING($3.type),
+ SDB_TYPE_TO_STRING($1.type));
+ sdb_data_free_datum(&$1);
+ sdb_data_free_datum(&$3);
+ YYABORT;
+ }
+
+ elem_size = sdb_data_sizeof($3.type);
+ $1.data.array.values = realloc($1.data.array.values,
+ ($1.data.array.length + 1) * elem_size);
+ if (! $1.data.array.values) {
+ sdb_fe_yyerror(&yylloc, scanner, YY_("out of memory"));
+ YYABORT;
+ }
+
+ memcpy((char *)$1.data.array.values
+ + $1.data.array.length * elem_size,
+ &$3.data, elem_size);
+ ++$1.data.array.length;
+
+ $$ = $1;
+ }
+ |
+ data
+ {
+ size_t elem_size;
+
+ if ($1.type & SDB_TYPE_ARRAY) {
+ sdb_fe_yyerrorf(&yylloc, scanner, YY_("syntax error, "
+ "cannot construct array of type %s"),
+ SDB_TYPE_TO_STRING($1.type));
+ sdb_data_free_datum(&$1);
+ YYABORT;
+ }
+
+ $$ = $1;
+ $$.type = $1.type | SDB_TYPE_ARRAY;
+ $$.data.array.length = 1;
+ elem_size = sdb_data_sizeof($1.type);
+ $$.data.array.values = malloc(elem_size);
+ if (! $$.data.array.values ) {
+ sdb_fe_yyerror(&yylloc, scanner, YY_("out of memory"));
+ YYABORT;
+ }
+ memcpy($$.data.array.values, &$1.data, elem_size);
+ }
+ ;
+
%%
void
sdb_store_matcher_t *m, *tmp = NULL;
assert(cb);
- /* TODO: this only works as long as queries
- * are limited to hosts */
+ /* hosts are never iterable */
if (type == SDB_HOST) {
return NULL;
}
- e = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
+ if (type == SDB_FIELD_BACKEND)
+ e = sdb_store_expr_fieldvalue(type);
+ else
+ e = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
m = cb(e, expr);
if (m_type == MATCHER_ANY)
tmp = sdb_store_any_matcher(type, m);