pgspider / influxdb_fdw

InfluxDB Foreign Data Wrapper for PostgreSQL.
Other
58 stars 14 forks source link

GROUP BY push down #2

Closed mochizk closed 5 years ago

mochizk commented 5 years ago

This pull request includes:

These functions can be used for using InfluxDB last() function and GROUP BY time(duration). But these functions do not have implementation in PostgreSQL and can be used if these are pushed down.

Usage example:

EXPLAIN (VERBOSE)
SELECT influx_time(time,interval '5s',interval '0s'),tag1,last(time, value1) FROM "t4" WHERE time >= '1970-01-01 00:00:00+00' and time <= '1970-01-01 0:00:05+00' 
GROUP BY influx_time(time,interval '5s', interval '0s'), tag1;
                                                                                   QUERY PLAN                                                                                    
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Foreign Scan  (cost=1.00..1.00 rows=1 width=48)
   Output: (influx_time("time", '@ 5 secs'::interval, '@ 0'::interval)), tag1, (last("time", value1))
   InfluxDB query: SELECT last("value1") FROM "t4" WHERE ((time >= '1970-01-01 00:00:00')) AND ((time <= '1970-01-01 00:00:05')) GROUP BY (time(0d0h0m5s0u, 0d0h0m0s0u)), "tag1"