Query: query using SQL-like NetQ Query Language
================================================

Commands
========
    - netq config add experimental
    - netq query

Usage
=====

NetQL is a generic structured query language modeled on SQL. The general
command syntax is:
    netq query 'SELECT <fields> FROM <tables> WHERE <conditions>
                           GROUP BY <fields> ORDER BY <fields>'

where, <field> is a key or non-key fields in one of the <tables> which netq
is aware of and maintains in its database, and <conditions> are qualifiers
to the data being queried.

Tables and Fields
=================
A simple example of a field is "hostname" is a field that is present in
every table. Examples of tables are Route, BgpSession etc.

You can get a list of all the tables known to netq via the command:
    netq query tables

And you can get a list of all the fields in a table via the command:
    netq query fields <tablename>

An example query from a single table is:
    netq query 'SELECT hostname, protocol, prefix FROM Route'

The output displays the values of the three fields specified in tabular
output.

Conditions
==========
Conditions select what data is presented. An example of a condition is
'hostname="tor-1"'. Note the use of '"' in specifying values matching.
You can also use != to indicate non-matching entries. AND is the only condition
supported today.

An example conditional query is :
   netq query 'SELECT hostname, protocol, prefix FROM Route WHERE protocol="ospf"'

GROUP BY
========
When you want to not just the value of a field, but see the aggregated
output such as a count or sum, you must specify what field the data is to be
aggregated on. For example, instead of merely listing the routes, if you want
to see the count of routes per host that are populated via OSPF, the query
is:
   netq query 'SELECT hostname, COUNT(prefix) FROM Route \
            WHERE protocol="ospf" GROUP BY hostname'
