summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bbd1b99)
raw | patch | inline | side by side (parent: bbd1b99)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 20 May 2015 08:35:29 +0000 (10:35 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 20 May 2015 08:35:29 +0000 (10:35 +0200) |
src/parser/analyzer.c | patch | blob | history | |
src/parser/grammar.y | patch | blob | history | |
t/unit/core/store_lookup_test.c | patch | blob | history | |
t/unit/parser/parser_test.c | patch | blob | history |
diff --git a/src/parser/analyzer.c b/src/parser/analyzer.c
index 28d312142ddca8a33b580d06b1503d4d2248de7d..dea83d7e0c828d8966fbffe9e91a2895c466fdf7 100644 (file)
--- a/src/parser/analyzer.c
+++ b/src/parser/analyzer.c
}
if (context != UNSPEC_CONTEXT) {
- /* skip this check if we don't know the context; it's up to the
+ /* skip these checks if we don't know the context; it's up to the
* caller to check again once the right context information is
* available */
if ((context != SDB_ATTRIBUTE) && (v->type == SDB_FIELD_VALUE)) {
SDB_FIELD_TO_NAME(context));
return -1;
}
+ if ((context != SDB_METRIC) && (v->type == SDB_FIELD_TIMESERIES)) {
+ sdb_strbuf_sprintf(errbuf, "Invalid expression %s.timeseries",
+ SDB_FIELD_TO_NAME(context));
+ return -1;
+ }
}
return 0;
} /* analyze_value */
diff --git a/src/parser/grammar.y b/src/parser/grammar.y
index 339f17ae43432dbcafd9fe6c2d1b5d7aead796c6..1b6d208c385736bdb828adeedc4bb460d7d35782 100644 (file)
--- a/src/parser/grammar.y
+++ b/src/parser/grammar.y
BACKEND_T { $$ = SDB_FIELD_BACKEND; }
|
VALUE_T { $$ = SDB_FIELD_VALUE; }
+ |
+ TIMESERIES { $$ = SDB_FIELD_TIMESERIES; }
;
cmp:
index 33c9268cb01d29fc561987b9838eb86f12b213f6..33fd1d24ec4d55e257cd9ab49bbd6b76fcbbe840 100644 (file)
NULL, 1 },
{ "host.attribute['x1'] IS NULL",
NULL, 3 },
+ /* not a boolean so neither TRUE nor FALSE: */
+ { "attribute['k1'] IS TRUE", NULL, 0 },
+ { "attribute['k1'] IS FALSE", NULL, 0 },
{ "attribute['k1'] = 'v1'", NULL, 1 },
{ "attribute['k1'] = 'v1'",
"name != 'k1'", 0 },
index 4dcf684de06cc6c3b508fff98401883913bf7e6d..3d2e40cbc4df0b4e6c59e0415c421d3d996ae716 100644 (file)
{ "LOOKUP hosts MATCHING "
"NOT attribute['foo'] "
"IS FALSE", -1, 1, SDB_AST_TYPE_LOOKUP, SDB_HOST },
+ { "LOOKUP metrics MATCHING "
+ "timeseries IS TRUE", -1, 1, SDB_AST_TYPE_LOOKUP, SDB_METRIC },
/* invalid numeric constants */
{ "LOOKUP hosts MATCHING "
"value = 'a'", -1, -1, 0, 0 },
{ "LIST metrics FILTER "
"name.1 = 'a'", -1, -1, 0, 0 },
+ { "LIST hosts FILTER "
+ "timeseries IS TRUE", -1, -1, 0, 0 },
+ { "LIST services FILTER "
+ "timeseries IS TRUE", -1, -1, 0, 0 },
/* type mismatches */
{ "LOOKUP hosts MATCHING "
{ "ALL attribute.name !~ 'pattern'", -1, SDB_AST_ALL },
{ "ALL attribute.name &^ 'pattern'", -1, -1 },
{ "ANY attribute !~ 'pattern'", -1, -1 },
+
/* composite expressions */
{ "name =~ 'pattern' AND "
- "ANY service.name =~ 'pattern'", -1, SDB_AST_AND },
+ "ANY service.name =~ 'pattern'", -1, SDB_AST_AND },
{ "name =~ 'pattern' OR "
- "ANY service.name =~ 'pattern'", -1, SDB_AST_OR },
- { "NOT name = 'host'", -1, SDB_AST_NOT },
+ "ANY service.name =~ 'pattern'", -1, SDB_AST_OR },
+ { "NOT name = 'host'", -1, SDB_AST_NOT },
/* numeric expressions */
{ "attribute['foo'] < 123", -1, SDB_AST_LT },
{ "attribute['foo'] <= 123", -1, SDB_AST_LE },
{ "'be' NOT IN backend", -1, SDB_AST_NOT },
{ "['a','b'] IN backend", -1, SDB_AST_IN },
{ "['a','b'] NOT IN backend", -1, SDB_AST_NOT },
+ { "timeseries IS TRUE", -1, SDB_AST_ISTRUE },
+ { "timeseries IS FALSE", -1, SDB_AST_ISFALSE },
+ { "timeseries IS NOT TRUE", -1, SDB_AST_NOT },
+ { "timeseries IS NOT FALSE", -1, SDB_AST_NOT },
+ { "timeseries > 0", -1, -1 },
+ { "timeseries = TRUE", -1, -1 },
+ { "timeseries != FALSE", -1, -1 },
/* check operator precedence */
{ "name = 'name' OR "
{ "(age + age) * age", -1, SDB_AST_MUL, SDB_TYPE_DATETIME },
{ "age + (age * age)", -1, SDB_AST_ADD, SDB_TYPE_DATETIME },
+ /* boolean expressions */
+ { "timeseries + 1", -1, -1, -1 },
+ { "timeseries - 1", -1, -1, -1 },
+ { "timeseries * 1", -1, -1, -1 },
+ { "timeseries / 1", -1, -1, -1 },
+ { "timeseries \% 1", -1, -1, -1 },
+ { "timeseries CONCAT 1", -1, -1, -1 },
+ { "timeseries + timeseries", -1, -1, -1 },
+ { "timeseries - timeseries", -1, -1, -1 },
+ { "timeseries * timeseries", -1, -1, -1 },
+ { "timeseries / timeseries", -1, -1, -1 },
+ { "timeseries \% timeseries", -1, -1, -1 },
+ { "timeseries CONCAT timeseries", -1, -1, -1 },
+
/* syntax errors */
{ "LIST", -1, -1, -1 },
{ "foo &^ bar", -1, -1, -1 },