influxdata / flux

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.
https://influxdata.com
MIT License
767 stars 153 forks source link

Introduce Schema introspection function #27

Open nathanielc opened 6 years ago

nathanielc commented 6 years ago

It will be valuable for operations to be able to inspect the table schema on the fly.

We propose adding a standard object type for doing so. The schema object will be as follows:

type schema = {
    colums: []column // list of all columns
    grouped:  []string // list of only the group labels
}
type column = {
   label : string, // column label
   type: string, // name for the column type
   grouped: bool, // whether the column is part of the group key
}

Flux functions can then make use of the schema record for defining dynamic behaviors on the schema

Take for example the group function that wants a list of column labels.

A user could write this to add a column to the list of grouped columns without needing to know the existing group columns

group(by: (schema) => schema.grouped + ["host"])
jsternberg commented 6 years ago

There's a typo in the schema. It should be columns.

I also think that groupKeys or keys are better names than grouped and that the column boolean attribute should be isKey. Those are just preferences though.

aanthony1243 commented 6 years ago

Since the group key segments can be obtained from the column data, maybe we can have the top-level groupKey parameter be a concatenated string? that way two schemas can be quickly compared for equality by the groupKey

edit: didn't see your example with group . But it would be useful to have a quick test to see if two tables have the same group columns.

aanthony1243 commented 6 years ago

new question: in #28 we propose passing schema.columns to a filter() function. This would require overloading the existing filter() function, or else having a filterList() function or similar.