|
Queries |
Top Previous Next |
|
SQL (Structured Query Language) is a powerful language for extracting and processing data. Tibbo AggreGate Server natively supports SQL, making it easy to access its internal data, as well as data collected from hardware devices. The specific SQL dialect supported by AggreGate Server is called AggreGate Query Language. AggreGate Query Language is highly integrated into AggreGate Server. Since all AggreGate Server internal data is maintained as Data Tables, it's easy to use SQL queries to modify the properties (settings, variables) of various system objects. Data Tables contain actual data, as well as data validation rules, detailed information each field, etc.
Purpose Of The Query Language AggreGate Query Language has two primary uses:
The first task is performed using a normal data selection ("SELECT") query, creating a Data Table viewable through a AggreGate Server User Interface (such as AggreGate Client). For example, you can write a query that shows the traffic for all Device Servers in the system in a single convenient sortable table:
Queries can also present editable results, allowing users to enter data, for example to configure several instances of the same device. So you can use a query to access the settings of all Device Servers in the system and edit them in a single table:
Queries can be also used in different AggreGate Server facilities. For example, you can set up an alert that will be raised if a query result satisfies some condition (see Hardware Devices in Trouble example in Alerts chapter for details). Query results may be converted into a printable report when they're browsed (e.g. using the Generate Report feature of Data Table Editor in AggreGate Client). Widgets may also be used to present data previously aggregated and filtered by a query. How AggreGate Query Language Compares to Normal SQL There are two primary differences between "normal" SQL used by most modern Database Engines (like MySQL or Oracle) and AggreGate Query Language. FIRST DIFFERENCE: Tables vs. contexts Normal SQL uses tables as the primary data source. Every SELECT statement refers to one or more tables from which data is selected. These references appear in the FROM clause. AggreGate Query Language works with data stored within AggreGate Server contexts. This data may be accessed by getting context variables (properties) or calling context functions. The value of every context variable is represented by a Data Table, a data structure that has fields, records and cells. These Data Tables are used by the Query Language engine as the tables from which data is selected. The same method may be used to refer to tables containing the output values of context functions. When a SELECT statement refers to such a table (containing output values of a function), the reference should also include the input parameters for that function. When the query is executed, the function is called with these parameters. That function then generates a data table containing its output, which in turn will be used by the query. In the Query Language Syntax article, these references to context variables or functions are called contextReference. Every contextReference may have an alias (tableAlias) that is used to refer to it from other parts of the query. Just like normal SQL, AggreGate Query Language supports nested SELECT statements, where the FROM section of a SELECT statement contains another SELECT statement. SECOND DIFFERENCE: FIELD references in 'FROM' CLAUSE The second difference concerns referring to the fields of tables mentioned in the FROM clause. In normal SQL, a reference to a table field includes two parts: tableAlias.fieldName. The first part is table's name, an alias given to it in the FROM clause or an alias given to the nested SELECT query. The second part is the field's name. In AggreGate, a reference to a table field consists of three parts. It looks like this: tableAlias.fieldAlias. tableAlias is the alias assigned to the table generated from context's data (see First Difference, above). fieldAlias is in the form entityName$fieldName. entityName is the name of a context variable or function (such as childInfo, which is the "user information" variable of the user context). fieldName is a specific field of that variable or function output (such as firstname, the user's first name, for the userInfo context).
Query Execution Flow This section describes the step-by-step process of how a query text is used to generate query results.
As stated in the previous chapter, the difference between AggreGate query and a normal SQL query is that it is executed on "virtual" tables generated from context data rather than on "plain" tables. Query Syntax Overview The only operation supported in AggreGate Query Language is the data selection operation which is performed with the SELECT keyword. SELECT retrieves data from a specified table, or from multiple related tables, that are created ad hoc when the Context References in the query are processed. Each query has several clauses:
AggreGate Query Language supports most features of SQL standard selection queries. It has support for nested SELECT queries, SQL aggregation functions used to perform calculations on various data values (COUNT, MIN, MAX, SUM, AVG, etc), and built-in functions (numerical, string, date/time and system). For a detailed description of AggreGate Query Language syntax, click here. Administering Queries
Several queries are built into AggreGate Server and appear under default administrator's user account:
These queries are described in the Query Examples chapter. For more information on SQL language check the following links: http://en.wikipedia.org/wiki/SQL |