Announcing Flux (formerly IFQL) v0.0.4

3 minutes

We recently released v0.0.4 of IFQL – Influx Query Language [now called Flux]. With the holidays at the end of the year, we were a little slow getting this release out. Going forward, we expect to release every two weeks. This release has some exciting developments, focused almost entirely in new features for the Flux language itself. Here is a quick list of highlights:

  • Support for defining/calling functions within Flux
  • Several new built-in functions: map, shift, integral, derivative and difference
  • Support for multiple values, with the covariance function being the first function to use multiple values

Adding support for functions into the language enables users to create small reusable components in their queries, building up libraries over time of useful snippets. Functions are also used when logic needs to be applied to the records of the data. Functions replace the previous expressions with a clear well-scoped function to evaluate. We hope you find them to be a clear and powerful tool. A Flux function follows this syntax:

(parameter list) => <function body>

Example function which adds two values:

// define the function add
add = (a,b) => a + b
// call the add function
add(a:1, b:5) // 6

Here is an example of functions in action:

// serviceData gets the field from the requests measurement for a given service.
serviceData = (service,field) =>
    from(db:"myapp")
        // Use an anonymous function as the filter predicate, where "r" is the record.
        .filter(fn: (r) => r._measurement == "requests" and r._service == service and r._field == field)
// We want the last hour of data
start = -1h
// Get the requests for the "cart" service
reqs = serviceData(service:"cart", field:"requests").range(start:start)
// Get the errors for the "cart" service
errs = serviceData(service:"cart", field:"errors").range(start:start)
// Compute the correlation between the reqs and errs for the "cart" service
pearsonr(x:reqs, y:errs, on:["region"])

The above script will compute the pearson correlation coefficient between errors and requests of the cart service for the past hour. Interestingly the pearsonr function is defined using native Flux functions and is built into the language. Here is a look at the definition of pearsonr as it appears in the source.

// Covariance computes the covariance between x and y.
covariance = (x,y,on,pearsonr=false) =>
    join(
        tables:{x:x, y:y},
        on:on,
        fn: (t) => ({x:t.x._value, y:t.y._value}),
    )
    .covariance(pearsonr:pearsonr)


// Pearsonr computes the Pearson R correlation coefficient of x and y.
pearsonr = (x,y,on) => covariance(x:x, y:y, on:on, pearsonr:true)

The pearsonr function is really just the covariance function with the pearsonr argument set to true. The covariance function in turn is a join operation which joins the x and y tables before passing the data to the covariance method which computes the actual covariance between the multiple values on the joined table. Over time, more functions will be added to the language, and we hope that these built-in functions can be a good source of examples for new users.

We are excited about the power that functions and multiple value support will bring to Flux. Have any feedback or want to see support for a certain function? Open an issue or pull request on the Flux repo. For a full list of changes in v0.0.4, see the CHANGELOG.

Related Blog Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top