Document toolboxDocument toolbox

Build a query using LINQ

Overview

Instead of using the Devo interface, queries can also be directly written using LINQ language.

LINQ is the query language used by Devo to query data tables. LINQ syntax is very flexible as it allows to make a query expression very close to the data discovery process by:

  1. selecting the source data table (using from)

  2. filtering data (using where)

  3. creating new columns (using select and optionally as...)

  4. grouping the data by a time value (using group every and every)

  5. applying aggregation operations over the grouped data (using select... as...)

    from <table name> group every <server period> by <column1>, <column2> every <browser period> select <aggregation operation 1>(<column>) as <NewColumnName1>, <aggregation operation 2>(<column>) as <NewColumnName2>,

For example, the following is a LINQ query where we want to retrieve only those events with status code 404 grouped every 10 minutes, displaying the method and clientIpAddress columns. Additionally, we have created the myCount column to count the records in each interval. For more examples using different operations, see the LINQ query examples section.

from demo.ecommerce.data where statusCode = 404 group every 10m by method, clientIpAddress every 10m select count() as myCount

Sometimes you may have to create a column. The syntax would be:

select <create column operation 1> as <NewColumnName1>, create <column operation 2> as <NewColumnName2>,

There are two different ways of accessing the query editor, where you can write your LINQ query:

In Data Search → Explore Your Data → Free Text Query. Learn more about this option here.

After accessing a data table, you can build and edit the query by selecting the Query code editor icon in the query toolbar and clicking Run.

Filter data using LINQ

These are the necessary clauses you need to add to your LINQ query in order to perform a filtering operation:

For example, the following query performs a filter to get only those events where the number of bytes sent is greater than 800:

And this one returns the events where the client IP address is not null and the bytes transferred are less than 1000:

Group data using LINQ

These are the necessary clauses you need to add to your LINQ query in order to group data:

Adding two different grouping periods might look like an unnecessary complexity, but it brings many advantages, such as the optimization of the query response. The server period is smaller than the client period, so the information is sent from the server in smaller chunks. This allows you to apply other grouping periods from the browser without having to query the server again. An every 0 is also allowed in the case you don’t want any grouping period.

For example, the following query groups data by IP address and status code every 3 hours (client period). The server period has been set to 30 minutes to optimize performance.

Learn more about client and server periods here.

Aggregate data using LINQ

These are the necessary clauses you need to add to your LINQ query in order to perform an aggregation operation. You must always group the data before aggregating data. 

For example, this query returns the average of bytes transferred every 5 minutes for each status code.

And this one returns the first non-null client IP address every 3 hours for each method.

Create new columns using LINQ

These are the necessary clauses you need to add to your LINQ query in order to perform a create column operation. You must always include the select operator followed by the operation name and column.

Optionally, you can add an as operator if you want to choose the name of the new column. In case you don't add an as operator, the name of the new column will be the operation(column).

For example, the following query creates two columns showing the corresponding latitude and longitude values of the IPs in the ClientIpAddress column of the table.

And this one displays the definitions of the status codes in a new column.