Code

frontend/grammar: Let LOOKUP support all object types.
authorSebastian Harl <sh@tokkee.org>
Wed, 5 Nov 2014 23:50:40 +0000 (00:50 +0100)
committerSebastian Harl <sh@tokkee.org>
Wed, 5 Nov 2014 23:50:40 +0000 (00:50 +0100)
src/frontend/grammar.y
t/unit/frontend/parser_test.c

index ab9345e22c80272b6cbd4b84b0fd7ce4472fda87..2e5274469057b12ac195997982e4018df727268e 100644 (file)
@@ -323,13 +323,11 @@ list_statement:
  * 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;
@@ -519,8 +517,9 @@ expression:
        |
        HOST_T
                {
-                       /* TODO: this only works as long as queries
-                        * are limited to hosts */
+                       /* XXX: this doesn't work correctly when not
+                        * querying hosts => use <type>.<field> instead
+                        * and let the analyzer verify <type> */
                        $$ = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
                }
        |
index 8af046a1de93c4ece48f5dbc6c3d3d3bcf983579..947ef710cb44f232a208fcf99d0b7d6d1663c1be 100644 (file)
@@ -107,6 +107,12 @@ START_TEST(test_parse)
                  "host =~ 'p' "
                  "FILTER age>"
                  "interval",           -1,   1, CONNECTION_LOOKUP },
+               { "LOOKUP services",    -1,   1, CONNECTION_LOOKUP },
+               { "LOOKUP services MATCHING ANY "
+                 "attribute =~ 'a'",   -1,   1, CONNECTION_LOOKUP },
+               { "LOOKUP metrics",     -1,   1, CONNECTION_LOOKUP },
+               { "LOOKUP metrics MATCHING ANY "
+                 "attribute =~ 'a'",   -1,   1, CONNECTION_LOOKUP },
 
                { "TIMESERIES 'host'.'metric' "
                  "START 2014-01-01 "
@@ -262,6 +268,20 @@ START_TEST(test_parse)
                { "LOOKUP hosts MATCHING "
                  "attribute['foo'] <= "
                  "'f' || oo",           -1, -1, 0 },
+               { "LOOKUP hosts MATCHING "
+                 "ANY host = 'host'",   -1, -1, 0 },
+               { "LOOKUP services MATCHING "
+                 "ANY host = 'host'",   -1, -1, 0 },
+               { "LOOKUP services MATCHING "
+                 "ANY service = 'svc'", -1, -1, 0 },
+               { "LOOKUP services MATCHING "
+                 "ANY metric = 'm'",    -1, -1, 0 },
+               { "LOOKUP metrics MATCHING "
+                 "ANY host = 'host'",   -1, -1, 0 },
+               { "LOOKUP metrics MATCHING "
+                 "ANY service = 'svc'", -1, -1, 0 },
+               { "LOOKUP metrics MATCHING "
+                 "ANY metric = 'm'",    -1, -1, 0 },
        };
 
        sdb_strbuf_t *errbuf = sdb_strbuf_create(64);