cortoproject / corto

A hierarchical object store for connecting realtime machine data with web applications, historians & more
https://www.corto.io
MIT License
87 stars 14 forks source link

Revise history query API to make it more user friendly and in line with TreeQL #633

Closed SanderMertens closed 6 years ago

SanderMertens commented 6 years ago

The corto_select API for selecting historical data contains separate functions for selecting different frame kinds, resulting in functions like fromNow, fromTime, forDuration, toTime. This is not user friendly, in particular for generic applications that would need to pre-evaluate a query before knowing which functions to call.

Currently the functions accept strongly typed arguments (corto_time) which in practice is not user friendly either because it requires a user to create a separate variable before the query can be run. Additionally, it is not easy to specify a date or duration with the current functions, because you can't use easy-to-read strings like Nov 10 2017 18:35 or 12h.

Instead, the corto_select functions should be modified to something that is easier to read, easier to write and easier to use for dynamic applications. An example API could look like this: (copied from #631)

// Select from a date (translated to timestamp) and duration
corto_select("*").from("/foo").begin("Nov 10 2017 18:35").duration("12h").slimit(100).iter(&it);

// Select from now with a duration
corto_select("*").from("/foo").begin("now").duration("1d").iter(&it);

// Select between two timestamps
corto_select("*").from("/foo").begin("14453458").end("14453558").slimit(100).iter(&it);

In a TreeQL query, this could be written down like:

select * from /foo start "now" duration "1d"

The interface towards mounts would not change. This only affects the user-facing API.