influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.17k stars 3.51k forks source link

`TableFunctionImpl` to enable queries from the last_cache #25095

Open hiltontj opened 5 days ago

hiltontj commented 5 days ago

This depends on #25093. Once the internal last cache has been set up and implements Datafusion's TableProvider, we can create the User-Defined Table Function (UDTF) implementation using Datafusion's TableFunctionImpl trait.

The API for this function should look like so:

last_cache(table_name, [cache_name])

So, its usage would look like so

SELECT * FROM last_cache('cpu')
SELECT time, usage FROM last_cache('cpu', 'cpu_usage_cache')

The last cache can be combined with predicates to operate on keys used in the last cache:

SELECT * FROM last_cache('mem') WHERE host = 'us-east'

Getting this to work may require some upstream changes to influxdb3_core to extend the IOxSessionContext with the UDTF.