From: Sebastian Harl Date: Sun, 27 Jul 2014 16:42:23 +0000 (+0200) Subject: Query language: Changed 'LOOKUP .. WHERE' to 'LOOKUP .. MATCHING'. X-Git-Tag: sysdb-0.3.0~29 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=b9bc76b71c4e4e1174ba1a8af3e13d53840b7e16 Query language: Changed 'LOOKUP .. WHERE' to 'LOOKUP .. MATCHING'. 'WHERE' was too SQL-like while it has somewhat different semantics. Using a different keyword will hopefully avoid any confusion. --- diff --git a/doc/sysdbql.7.txt b/doc/sysdbql.7.txt index c4f52a9..447950d 100644 --- a/doc/sysdbql.7.txt +++ b/doc/sysdbql.7.txt @@ -11,7 +11,7 @@ SYNOPSIS LIST; - QUERY hosts WHERE attribute.architecture = 'amd64'; + LOOKUP hosts MATCHING attribute.architecture = 'amd64'; 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. -*LOOKUP* hosts *WHERE* '':: +*LOOKUP* hosts *MATCHING* '':: 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. -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: '' '' '':: 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", diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index d505485..74e28dd 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -81,7 +81,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %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 @@ -221,12 +221,12 @@ list_statement: ; /* - * LOOKUP WHERE ; + * LOOKUP MATCHING ; * * Returns detailed information about matching expression. */ lookup_statement: - LOOKUP IDENTIFIER WHERE expression + LOOKUP IDENTIFIER MATCHING expression { /* TODO: support other types as well */ if (strcasecmp($2, "hosts")) { diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l index a7b72b4..ef30682 100644 --- a/src/frontend/scanner.l +++ b/src/frontend/scanner.l @@ -114,14 +114,14 @@ float ({float1}|{float2}|{float3}|{float4}|{float5}) 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, "WHERE")) - return WHERE; yylval->str = strdup(yytext); return IDENTIFIER; diff --git a/t/integration/simple_query.sh b/t/integration/simple_query.sh index ef12bf8..6d7f5e5 100755 --- a/t/integration/simple_query.sh +++ b/t/integration/simple_query.sh @@ -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" \ - -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"' @@ -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" \ - -c "LOOKUP hosts WHERE attribute != 'architecture'" )" + -c "LOOKUP hosts MATCHING attribute != 'architecture'" )" 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" \ - -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 @@ -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" \ - -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"' @@ -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" \ - -c "LOOKUP hosts WHERE attribute.invalid = 'none'" )" + -c "LOOKUP hosts MATCHING attribute.invalid = 'none'" )" echo $output | grep -E '^\[\]$' stop_sysdbd diff --git a/t/unit/frontend/parser_test.c b/t/unit/frontend/parser_test.c index f1e6569..3ca27ba 100644 --- a/t/unit/frontend/parser_test.c +++ b/t/unit/frontend/parser_test.c @@ -58,84 +58,84 @@ START_TEST(test_parse) { "LIST;", -1, 1, CONNECTION_LIST }, { "LIST; INVALID", 5, 1, CONNECTION_LIST }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "host = 'host'", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE NOT " + { "LOOKUP hosts MATCHING NOT " "host = 'host'", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "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 }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "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 */ - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo = " "1234", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo != " "+234", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo < " "-234", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo > " "12.4", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo <= " "12.", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo >= " ".4", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo = " "+12e3", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo = " "+12e-3", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo = " "-12e+3", -1, 1, CONNECTION_LOOKUP }, /* NULL */ - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo " "IS NULL", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo " "IS NOT NULL", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "NOT attribute.foo " "IS NULL", -1, 1, CONNECTION_LOOKUP }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "host IS NULL", -1, -1, 0 }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "service IS NULL", -1, -1, 0 }, /* invalid numeric constants */ - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo = " "+-12e+3", -1, -1, 0 }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo = " "-12e-+3", -1, -1, 0 }, - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "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 */ - { "LOOKUP hosts WHERE " + { "LOOKUP hosts MATCHING " "attribute.foo = " "0x12", -1, -1, 0 }, @@ -150,7 +150,7 @@ START_TEST(test_parse) { "/* some incomplete", -1, -1, 0 }, { "LOOKUP hosts", -1, -1, 0 }, - { "LOOKUP foo WHERE " + { "LOOKUP foo MATCHING " "host = 'host'", -1, -1, 0 }, };