[ 
https://issues.apache.org/jira/browse/CALCITE-3345?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16930847#comment-16930847
 ] 

Julian Hyde commented on CALCITE-3345:
--------------------------------------

We could follow the same approach as for other function sets: add an enum 
constant 'TIMESCALE_DB' to enum SqlLibrary, and add a library function. For 
comparison, see 
[00ad79b6|https://github.com/apache/calcite/commit/00ad79b6bc95b68e02129b31be8a3a656517f8a8]
 which fixes CALCITE-3263 and adds {{MD5}} and {{SHA1}} to MYSQL and POSTGRESQL 
libraries.

I had a quick look at timescaleDB and there is some un-SQL-like stuff in there 
that we would not wish to emulate, such as [this 
behavior|https://docs.timescale.com/latest/api#time_bucket_gapfill] for 
{{time_bucket_gapfill}}:
{quote}Starting with version 1.3.0 start and finish are optional arguments and 
will be inferred from the WHERE clause if not supplied as arguments.{quote}
I have no objection to bringing in scalar functions into a timescaleDB 
compatibility library, but if we start screwing around with SQL/relational 
semantics it's going to be a long discussion. :)

> Implement time_bucket function
> ------------------------------
>
>                 Key: CALCITE-3345
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3345
>             Project: Calcite
>          Issue Type: New Feature
>            Reporter: Julian Feinauer
>            Priority: Major
>
> See here for information on the `time_bucket` function: 
> https://docs.timescale.com/latest/api#time_bucket
> This is a more powerful version of the standard PostgreSQL date_trunc 
> function. It allows for arbitrary time intervals instead of the second, 
> minute, hour, etc. provided by date_trunc. The return value is the bucket's 
> start time.
> This would especially help with time averaging but keeps everything SQL 
> compliant. E.g. queries like 
> Example query from (https://www.timescale.com/):
> {code:sql}
> SELECT  time_bucket('10  seconds',  time)  AS  ten_second,
>     machine_id,  avg(temperature)  AS  "avgT",
>     min(temperature)  AS  "minT",  max(temperature)  AS  "maxT",
>     last(temperature,  time)  AS  "lastT"
> FROM  measurements
> WHERE  machine_id  =  'C931baF7'
>     AND  time  >  now()  -  interval  '150s'
> GROUP  BY  ten_second
> ORDER  BY  ten_second  DESC;
> {code}



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to