Code

Query language: Changed 'LOOKUP .. WHERE' to 'LOOKUP .. MATCHING'.
authorSebastian Harl <sh@tokkee.org>
Sun, 27 Jul 2014 16:42:23 +0000 (18:42 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 27 Jul 2014 16:42:23 +0000 (18:42 +0200)
'WHERE' was too SQL-like while it has somewhat different semantics. Using a
different keyword will hopefully avoid any confusion.

doc/sysdbql.7.txt
src/frontend/grammar.y
src/frontend/scanner.l
t/integration/simple_query.sh
t/unit/frontend/parser_test.c

index c4f52a9a8c1110ac3880b7c03b849eeb6b75d991..447950d37ec00ad11c8dbd403212895e2be346a1 100644 (file)
@@ -11,7 +11,7 @@ SYNOPSIS
 
   LIST;
 
 
   LIST;
 
-  QUERY hosts WHERE attribute.architecture = 'amd64';
+  LOOKUP hosts MATCHING attribute.architecture = 'amd64';
 
 DESCRIPTION
 -----------
 
 DESCRIPTION
 -----------
@@ -39,20 +39,20 @@ value includes the hostname, a list of services referenced by the host, and a
 list of attributes for the host and each service. If the host does not exist,
 an error is returned.
 
 list of attributes for the host and each service. If the host does not exist,
 an error is returned.
 
-*LOOKUP* hosts *WHERE* '<search_condition>'::
+*LOOKUP* hosts *MATCHING* '<search_condition>'::
 Retrieve detailed information about all host objects matching the specified
 search condition. The return value is a list of detailed information for each
 matching host providing the same details as returned by the *FETCH* command.
 Retrieve detailed information about all host objects matching the specified
 search condition. The return value is a list of detailed information for each
 matching host providing the same details as returned by the *FETCH* command.
-See the section "WHERE clause" for more details about how to specify the
+See the section "MATCHING clause" for more details about how to specify the
 search condition.
 
 search condition.
 
-WHERE clause
-~~~~~~~~~~~~
-The *WHERE* clause in a query specifies a boolean expression which is used to
-match host objects based on their names, their attributes, or services
-referenced by the host. Each *WHERE* clause may be made up of one or multiple
-subexpressions each matching on one criteria. The following subexpressions
-are supported by SysDB:
+MATCHING clause
+~~~~~~~~~~~~~~~
+The *MATCHING* clause in a query specifies a boolean expression which is used
+to match host objects based on their names, their attributes, or services
+referenced by the host. Each *MATCHING* clause may be made up of one or
+multiple subexpressions each matching on one criteria. The following
+subexpressions are supported by SysDB:
 
 '<field>' '<operator>' '<value>'::
        Match a named field against the specified value. See below for what fields
 
 '<field>' '<operator>' '<value>'::
        Match a named field against the specified value. See below for what fields
@@ -158,7 +158,7 @@ replies look like. The replies are pretty-printed to more easily follow them.
           ...
         }]}
 
           ...
         }]}
 
-  LOOKUP hosts WHERE attribute.architecture = 'amd64';
+  LOOKUP hosts MATCHING attribute.architecture = 'amd64';
   [{
       "name": "host1.example.com",
       "last_update": "2001-02-03 04:05:06 +0700",
   [{
       "name": "host1.example.com",
       "last_update": "2001-02-03 04:05:06 +0700",
index d5054854c3153a1298a238ad1bee2026a965cd51..74e28dd837f7e8eb7a819e1a0a4ed2ebda032ffb 100644 (file)
@@ -81,7 +81,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 
 %token SCANNER_ERROR
 
 
 %token SCANNER_ERROR
 
-%token AND OR IS NOT WHERE
+%token AND OR IS NOT MATCHING
 %token CMP_EQUAL CMP_NEQUAL CMP_REGEX CMP_NREGEX
 %token CMP_LT CMP_LE CMP_GE CMP_GT
 
 %token CMP_EQUAL CMP_NEQUAL CMP_REGEX CMP_NREGEX
 %token CMP_LT CMP_LE CMP_GE CMP_GT
 
@@ -221,12 +221,12 @@ list_statement:
        ;
 
 /*
        ;
 
 /*
- * LOOKUP <type> WHERE <expression>;
+ * LOOKUP <type> MATCHING <expression>;
  *
  * Returns detailed information about <type> matching expression.
  */
 lookup_statement:
  *
  * Returns detailed information about <type> matching expression.
  */
 lookup_statement:
-       LOOKUP IDENTIFIER WHERE expression
+       LOOKUP IDENTIFIER MATCHING expression
                {
                        /* TODO: support other types as well */
                        if (strcasecmp($2, "hosts")) {
                {
                        /* TODO: support other types as well */
                        if (strcasecmp($2, "hosts")) {
index a7b72b43794541985e722ca2f2c6ea3a61848e12..ef30682b45b837f8cb931f1e7257f7568ddd3f2b 100644 (file)
@@ -114,14 +114,14 @@ float             ({float1}|{float2}|{float3}|{float4}|{float5})
                        return LIST;
                else if (! strcasecmp(yytext, "LOOKUP"))
                        return LOOKUP;
                        return LIST;
                else if (! strcasecmp(yytext, "LOOKUP"))
                        return LOOKUP;
+               else if (! strcasecmp(yytext, "MATCHING"))
+                       return MATCHING;
                else if (! strcasecmp(yytext, "NOT"))
                        return NOT;
                else if (! strcasecmp(yytext, "NULL"))
                        return NULL_T;
                else if (! strcasecmp(yytext, "OR"))
                        return OR;
                else if (! strcasecmp(yytext, "NOT"))
                        return NOT;
                else if (! strcasecmp(yytext, "NULL"))
                        return NULL_T;
                else if (! strcasecmp(yytext, "OR"))
                        return OR;
-               else if (! strcasecmp(yytext, "WHERE"))
-                       return WHERE;
 
                yylval->str = strdup(yytext);
                return IDENTIFIER;
 
                yylval->str = strdup(yytext);
                return IDENTIFIER;
index ef12bf8f2dbf1a735ff284c7cfb8b084b19098c9..6d7f5e5d9af9228b2b20e40e66b4bb0d62b976bb 100755 (executable)
@@ -89,7 +89,7 @@ output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH 'does.not.exist'" )" \
 echo "$output" | grep -F 'not found'
 
 output="$( run_sysdb -H "$SOCKET_FILE" \
 echo "$output" | grep -F 'not found'
 
 output="$( run_sysdb -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE attribute.architecture = 'x42'" )"
+       -c "LOOKUP hosts MATCHING attribute.architecture = 'x42'" )"
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"'
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"'
@@ -98,7 +98,7 @@ echo "$output" | grep -F 'other.host.name' && exit 1
 echo "$output" | grep -F 'some.host.name' && exit 1
 
 output="$( run_sysdb -H "$SOCKET_FILE" \
 echo "$output" | grep -F 'some.host.name' && exit 1
 
 output="$( run_sysdb -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE attribute != 'architecture'" )"
+       -c "LOOKUP hosts MATCHING attribute != 'architecture'" )"
 echo "$output" \
        | grep -F '"some.host.name"' \
        | grep -F '"localhost"'
 echo "$output" \
        | grep -F '"some.host.name"' \
        | grep -F '"localhost"'
@@ -107,7 +107,7 @@ echo "$output" | grep -F 'host1.example.com' && exit 1
 echo "$output" | grep -F 'host2.example.com' && exit 1
 
 output="$( run_sysdb -H "$SOCKET_FILE" \
 echo "$output" | grep -F 'host2.example.com' && exit 1
 
 output="$( run_sysdb -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE service = 'sysdbd'" )"
+       -c "LOOKUP hosts MATCHING service = 'sysdbd'" )"
 echo "$output" | grep -F '"localhost"'
 echo "$output" | grep -F 'some.host.name' && exit 1
 echo "$output" | grep -F 'other.host.name' && exit 1
 echo "$output" | grep -F '"localhost"'
 echo "$output" | grep -F 'some.host.name' && exit 1
 echo "$output" | grep -F 'other.host.name' && exit 1
@@ -115,7 +115,7 @@ echo "$output" | grep -F 'host1.example.com' && exit 1
 echo "$output" | grep -F 'host2.example.com' && exit 1
 
 output="$( run_sysdb -H "$SOCKET_FILE" \
 echo "$output" | grep -F 'host2.example.com' && exit 1
 
 output="$( run_sysdb -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE host =~ 'example.com'" )"
+       -c "LOOKUP hosts MATCHING host =~ 'example.com'" )"
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"'
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"'
@@ -125,7 +125,7 @@ echo "$output" | grep -F 'localhost' && exit 1
 
 # When querying hosts that don't exist, expect a zero exit code.
 output="$( run_sysdb -H "$SOCKET_FILE" \
 
 # When querying hosts that don't exist, expect a zero exit code.
 output="$( run_sysdb -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE attribute.invalid = 'none'" )"
+       -c "LOOKUP hosts MATCHING attribute.invalid = 'none'" )"
 echo $output | grep -E '^\[\]$'
 
 stop_sysdbd
 echo $output | grep -E '^\[\]$'
 
 stop_sysdbd
index f1e656982cbb21de211fd850b64e456da68ee84f..3ca27ba19ffb47ec637575469b398c7d85d10961 100644 (file)
@@ -58,84 +58,84 @@ START_TEST(test_parse)
                { "LIST;",               -1,  1, CONNECTION_LIST   },
                { "LIST; INVALID",        5,  1, CONNECTION_LIST   },
 
                { "LIST;",               -1,  1, CONNECTION_LIST   },
                { "LIST; INVALID",        5,  1, CONNECTION_LIST   },
 
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "host = 'host'",       -1,  1, CONNECTION_LOOKUP },
                  "host = 'host'",       -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE NOT "
+               { "LOOKUP hosts MATCHING NOT "
                  "host = 'host'",       -1,  1, CONNECTION_LOOKUP },
                  "host = 'host'",       -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "host =~ 'p' AND "
                  "service =~ 'p'",      -1,  1, CONNECTION_LOOKUP },
                  "host =~ 'p' AND "
                  "service =~ 'p'",      -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE NOT "
+               { "LOOKUP hosts MATCHING NOT "
                  "host =~ 'p' AND "
                  "service =~ 'p'",      -1,  1, CONNECTION_LOOKUP },
                  "host =~ 'p' AND "
                  "service =~ 'p'",      -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "host =~ 'p' AND "
                  "service =~ 'p' OR "
                  "service =~ 'r'",      -1,  1, CONNECTION_LOOKUP },
                  "host =~ 'p' AND "
                  "service =~ 'p' OR "
                  "service =~ 'r'",      -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE NOT "
+               { "LOOKUP hosts MATCHING NOT "
                  "host =~ 'p' AND "
                  "service =~ 'p' OR "
                  "service =~ 'r'",      -1,  1, CONNECTION_LOOKUP },
 
                /* numeric constants */
                  "host =~ 'p' AND "
                  "service =~ 'p' OR "
                  "service =~ 'r'",      -1,  1, CONNECTION_LOOKUP },
 
                /* numeric constants */
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "1234",                -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo = "
                  "1234",                -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo != "
                  "+234",                -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo != "
                  "+234",                -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo < "
                  "-234",                -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo < "
                  "-234",                -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo > "
                  "12.4",                -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo > "
                  "12.4",                -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo <= "
                  "12.",                 -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo <= "
                  "12.",                 -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo >= "
                  ".4",                  -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo >= "
                  ".4",                  -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "+12e3",               -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo = "
                  "+12e3",               -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "+12e-3",              -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo = "
                  "+12e-3",              -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "-12e+3",              -1,  1, CONNECTION_LOOKUP },
 
                /* NULL */
                  "attribute.foo = "
                  "-12e+3",              -1,  1, CONNECTION_LOOKUP },
 
                /* NULL */
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo "
                  "IS NULL",             -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo "
                  "IS NULL",             -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo "
                  "IS NOT NULL",         -1,  1, CONNECTION_LOOKUP },
                  "attribute.foo "
                  "IS NOT NULL",         -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "NOT attribute.foo "
                  "IS NULL",             -1,  1, CONNECTION_LOOKUP },
                  "NOT attribute.foo "
                  "IS NULL",             -1,  1, CONNECTION_LOOKUP },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "host IS NULL",        -1, -1, 0 },
                  "host IS NULL",        -1, -1, 0 },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "service IS NULL",     -1, -1, 0 },
 
                /* invalid numeric constants */
                  "service IS NULL",     -1, -1, 0 },
 
                /* invalid numeric constants */
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "+-12e+3",             -1, -1, 0 },
                  "attribute.foo = "
                  "+-12e+3",             -1, -1, 0 },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "-12e-+3",             -1, -1, 0 },
                  "attribute.foo = "
                  "-12e-+3",             -1, -1, 0 },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "e+3",                 -1, -1, 0 },
                  "attribute.foo = "
                  "e+3",                 -1, -1, 0 },
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "3e",                  -1, -1, 0 },
                /* following SQL standard, we don't support hex numbers */
                  "attribute.foo = "
                  "3e",                  -1, -1, 0 },
                /* following SQL standard, we don't support hex numbers */
-               { "LOOKUP hosts WHERE "
+               { "LOOKUP hosts MATCHING "
                  "attribute.foo = "
                  "0x12",                -1, -1, 0 },
 
                  "attribute.foo = "
                  "0x12",                -1, -1, 0 },
 
@@ -150,7 +150,7 @@ START_TEST(test_parse)
                { "/* some incomplete",  -1, -1, 0 },
 
                { "LOOKUP hosts",        -1, -1, 0 },
                { "/* some incomplete",  -1, -1, 0 },
 
                { "LOOKUP hosts",        -1, -1, 0 },
-               { "LOOKUP foo WHERE "
+               { "LOOKUP foo MATCHING "
                  "host = 'host'",       -1, -1, 0 },
        };
 
                  "host = 'host'",       -1, -1, 0 },
        };