Skip to content
Flux is a lightweight scripting language for querying databases (like InfluxDB) and working with data. It's part of InfluxDB 1.7 and 2.0, but can be run independently of those.
Go FLUX Rust Ragel C Shell
Branch: master
Clone or download

Latest commit

nathanielc fix(values): fix bug in object equal method (#2859)
The previous implementation ignored differences in the field names of objects
Latest commit a89cd9b May 22, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci ci: goreleaser cross compilation (#2658) Mar 20, 2020
.github chore(github): remove the github workflows (#2145) Nov 13, 2019
arrow wip: values and semantic packages compile, working on interpreter and… Dec 20, 2019
ast fix: let rust parser parse with file name (#2464) Mar 11, 2020
benchmarks/flux chore: Update 'from' to match spec Aug 30, 2018
builtin refactor(runtime): move runtime components of the flux package to a r… Feb 24, 2020
cmd/flux Merge branch 'master' into chore/merge-master-to-algo-w Apr 23, 2020
codes refactor: make inherit the default error code and remove ok (#1463) Jul 9, 2019
colm feat: added initial prototype of a table-based flux (#2744) Apr 24, 2020
compiler fix(compiler): apply substitution fully when compiling lambda (#2770) Apr 22, 2020
complete refactor(lang): remove dependency on runtime (#2596) Mar 6, 2020
csv fix(csv): handled malformed data as well as eof (#2413) Jan 21, 2020
dependencies fix: inject the url validator into NewDefaultClient (#2845) May 15, 2020
docs feat(stdlib/v1): add fieldKeys and measurementFieldKeys to v1 package ( May 7, 2020
etc chore: rust checkfmt (#2189) Dec 3, 2019
examples test: fix failing tests and make CI green (#2483) Feb 7, 2020
execute fix(stdlib): fix race condition in the filter function (#2838) May 12, 2020
influxql feat(control): support attaching arbitrary query metadata from the ex… Feb 25, 2019
internal fix(stdlib): fix concurrent map write in filter transformation (#2802) May 4, 2020
interpreter Merge branch 'master' into feat/use-algo-w Apr 27, 2020
iocounter feat(query): Change Encode interface to return bytes written Jun 27, 2018
lang refactor: constraints now have an expected type (#2850) May 19, 2020
libflux fix(libflux): add builtin formatting (#2858) May 22, 2020
line feat(control): support attaching arbitrary query metadata from the ex… Feb 25, 2019
memory fix(memory): reorder variables in the allocator for atomic operations ( Oct 24, 2019
mock refactor: mock compiler needs to implement the compiler interface (#2601 Mar 9, 2020
parser fix(libflux): tweak Rust JSON serialization and add tests (#2686) Mar 25, 2020
plan feat: add a context to plantest.RuleTestCase (#2799) May 1, 2020
promql refactor(promql): move the promql helper functions to internal/promql Sep 12, 2019
querytest refactor(lang): remove dependency on runtime (#2596) Mar 6, 2020
repl Merge branch 'master' into feat/use-algo-w Apr 27, 2020
runtime refactor: constraints now have an expected type (#2850) May 19, 2020
semantic fix(compiler): apply substitution fully when compiling lambda (#2770) Apr 22, 2020
stdlib test(stdlib): add flux end-to-end test for bare agg push down (#2852) May 19, 2020
tools feat: add support for pkg-config (#2555) Feb 27, 2020
values fix(values): fix bug in object equal method (#2859) May 22, 2020
.codecov.yml chore(codecov): add thresholds on codecov pass/fail Jul 10, 2019
.dockerignore feat: create a docker environment for flux release (#2514) Feb 12, 2020
.gitignore feat: added a dynamically linked valgrind test (#2681) Mar 26, 2020
.goreleaser.yml ci: goreleaser cross compilation (#2658) Mar 20, 2020
CONTRIBUTING.md docs(stdlib/contrib): add docs on how to contribute third party packa… Apr 23, 2020
Dockerfile_build ci: merge the cross compiler tools into the normal build file (#2653) Mar 19, 2020
LICENSE LICENSE (#133) Oct 30, 2018
Makefile chore: update publish workflow to ensure clean publish (#2836) May 15, 2020
README.md fix(libflux): force the go libflux wrapper to rebuild using go genera… Mar 13, 2020
TODO.txt wip: values and semantic packages compile, working on interpreter and… Dec 20, 2019
bounds.go add the notion of bounds to plan nodes (#142) Oct 26, 2018
bounds_test.go chore: fix current megacheck errors Nov 2, 2018
compile.go refactor(runtime): move runtime components of the flux package to a r… Feb 24, 2020
compiler.go refactor(lang): remove dependency on runtime (#2596) Mar 6, 2020
dependencies.go fix: inject the url validator into NewDefaultClient (#2845) May 15, 2020
dialect.go feat: categorize more flux errors with codes (#2267) Dec 10, 2019
errors.go feat: modify error usage in places to use the new enriched errors (#1458 Jul 8, 2019
format.go refactor: Initial migration Sep 5, 2018
go.mod feat(sql): add Snowflake support (#2707) Apr 30, 2020
go.sum feat(sql): add Snowflake support (#2707) Apr 30, 2020
gotool.sh chore(tools): break tools out into a separate module (#2140) Nov 19, 2019
group_mode.go feat(stdlib): organizes builtin code into Flux packages Jan 11, 2019
operation.go feat: categorize more flux errors with codes (#2267) Dec 10, 2019
pkg-config.sh feat: add support for pkg-config (#2555) Feb 27, 2020
query.go refactor(stdlib): add max and total allocations metrics to benchmarks ( Sep 23, 2019
release.sh fix: remove 'tags' line from local tags (#2383) Jan 14, 2020
resource_management.go refactor: wrap errors with flux.Error instead of github.com/pkg/errors ( Aug 20, 2019
result.go wip: values and semantic packages compile, working on interpreter and… Dec 20, 2019
result_iterator.go fix: Allow flux unit tests to pass (#1103) Apr 12, 2019
result_iterator_test.go refactor: wrap errors with flux.Error instead of github.com/pkg/errors ( Aug 20, 2019
result_test.go fix: schema mutators and miscellaneous todos Jan 21, 2020
runtime.go refactor: refactor eval methods to avoid roundtrips (#2638) Mar 23, 2020
rustfmt.toml chore: rust checkfmt (#2189) Dec 3, 2019
spec.go feat: categorize more flux errors with codes (#2267) Dec 10, 2019
spec_test.go feat(stdlib): add influxdb source (#2568) Feb 28, 2020
time.go feat(values): turn duration value into a vector (#2018) Oct 18, 2019
time_test.go tests: add tests for time marshaling and unmarshaling Nov 6, 2018
tracing.go fix: expose tracing flag (#2281) Jan 6, 2020
xcc.sh fix: remove the set -x in the xcc script (#2659) Mar 20, 2020

README.md

Flux - Influx data language

CircleCI

Flux is a lightweight scripting language for querying databases (like InfluxDB) and working with data. It's part of InfluxDB 1.7 and 2.0, but can be run independently of those. This repo represents the language definition and an implementation of the language core.

Specification

A complete specification can be found in SPEC.md. The specification contains many examples to start learning Flux.

Requirements

Building Flux requires the following:

  • Go 1.12 or greater with module support enabled
  • Latest stable version of Rust and Cargo (recommended: rustup
  • Clang

Getting Started

Flux is currently available in InfluxDB 1.7 and 2.0 or through the REPL that can be compiled from this repository.

To build flux, first install the pkg-config utility, and ensure the GNU pkg-config utility is also installed.

# On Debian/Ubuntu
$ sudo apt-get install -y clang pkg-config
# On Mac OS X with Homebrew
$ brew install pkg-config
# Install the pkg-config wrapper utility
$ go get github.com/influxdata/pkg-config
# Ensure the GOBIN directory is on your PATH
$ export PATH=${GOPATH}/bin:${PATH}

To ensure that pkg-config is configured correctly, you can use which -a.

$ which -a pkg-config
/home/user/go/bin/pkg-config
/usr/bin/pkg-config

To compile the REPL, use the following command:

$ go build ./cmd/flux
$ ./flux repl

If you do not want to add the wrapper pkg-config to your PATH, you can also set PKG_CONFIG and Go will use it.

$ export PKG_CONFIG=/home/user/go/bin/pkg-config
$ go build ./cmd/flux
$ ./flux repl

If you modify any Rust code, you will need to force Go to rebuild the library.

$ go generate ./libflux/go/libflux

If you create or change any flux functions, you will need to rebuild the stdlib and inform Go that it must rebuild libflux:

$ go generate ./stdlib ./libflux/go/libflux

Your new Flux's code should be formatted to coexist nicely with the existing codebase with go fmt. For example, if you add code to stdlib/universe:

$ go fmt ./stdlib/universe/

Don't forget to add your tests and make sure they work. Here is an example showing how to run the tests for the stdlib/universe package:

$ go test ./stdlib/universe/

From within the REPL, you can run any Flux expression. Additionally, you can also load a file directly into the REPL by typing @ followed by the filename.

> @my_file_to_load.flux

Basic Syntax

Here are a few examples of the language to get an idea of the syntax.

// This line is a comment

// Support for traditional math operators
1 + 1

// Several data types are built-in
true                     // a boolean true value
1                        // an int
1.0                      // a float
"this is a string"       // a string literal
1h5m                     // a duration of time representing 1 hour and 5 minutes
2018-10-10               // a time starting at midnight for the default timezone on Oct 10th 2018
2018-10-10T10:05:00      // a time at 10:05 AM for the default timezone on Oct 10th 2018
[1,1,2]                  // an array of integers
{foo: "str", bar: false} // an object with two keys and their values

// Values can be assigned to identifers
x = 5.0
x + 3.0 // 8.0

// Import libraries
import "math"

// Call functions always using keyword arguments
math.pow(x: 5.0, y: 3.0) // 5^3 = 125

// Functions are defined by assigning them to identifers
add = (a, b) => a + b

// Call add using keyword arguments
add(a: 5, b: 3) // 8

// Functions are polymorphic
add(a: 5.5, b: 2.5) // 8.0

// And strongly typed
add(a: 5, b: 2.5) // type error

// Access data from a database and store it as an identifier
// This is only possible within the influxdb repl (at the moment).
import "influxdata/influxdb"
data = influxdb.from(bucket:"telegraf/autogen")

// When running inside of influxdb, the import isn't needed.
data = from(bucket:"telegraf/autogen")

// Chain more transformation functions to further specify the desired data
cpu = data 
    // only get the last 5m of data
    |> range(start: -5m)
    // only get the "usage_user" data from the _measurement "cpu"
    |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_user")

// Return the data to the client
cpu |> yield()

// Group an aggregate along different dimensions
cpu
    // organize data into groups by host and region
    |> group(columns:["host","region"])
    // compute the mean of each group
    |> mean()
    // yield this result to the client
    |> yield()

// Window an aggregate over time
cpu
    // organize data into groups of 1 minute
    // compute the mean of each group
    |> aggregateWindow(every: 1m, fn: mean)
    // yield this result to the client
    |> yield()

// Gather different data
mem = data 
    // only get the last 5m of data
    |> range(start: -5m)
    // only get the "used_percent" data from the _measurement "mem"
    |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent")


// Join data to create wider tables and map a function over the result
join(tables: {cpu:cpu, mem:mem}, on:["_time", "host"])
    // compute the ratio of cpu usage to mem used_percent
    |> map(fn:(r) => {_time: r._time, _value: r._value_cpu / r._value_mem)
    // again yield this result to the client
    |> yield()

The above examples give only a taste of what is possible with Flux. See the complete documentation for more complete examples and instructions for how to use Flux with InfluxDB 2.0.

Contributing

Flux welcomes contributions to the language and the runtime.

If you are interested in contributing, please read out contributing readme for information about how to contribute.

You can’t perform that action at this time.