bigrquery icon indicating copy to clipboard operation
bigrquery copied to clipboard

add dplyr translation support for TIMESTAMP_TRUNC

Open era127 opened this issue 2 years ago • 3 comments

The dplyr translation does not currently support the floor_date() function. Should it be mapped to the TIMESTAMP_TRUNC sql statement? The POSIXt objects are mapped to TIMESTAMP and not DATETIME so I think TIMESTAMP_TRUNC is best.

This is derived from dbplyr's translation for Postgres.

      floor_date = function(x, unit = "seconds") {
        unit <- arg_match(unit,
          c("second", "minute", "hour", "day", "week", "month", "quarter", "year")
        )
        sql_expr(TIMESTAMP_TRUNC(!!unit, !!x))
      },

I'm not sure how it would handle the translation of the timezone argument to TIMESTAMP_TRUNC because floor_date() does not support a timezone argument.

era127 avatar Jun 25 '23 02:06 era127

Good idea!

hadley avatar Nov 02 '23 22:11 hadley

Docs here: https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#timestamp_trunc

hadley avatar Nov 07 '23 22:11 hadley

Will wait on https://github.com/tidyverse/dbplyr/pull/1357 and tackle a swathe of date functions all at once.

hadley avatar Nov 15 '23 18:11 hadley