Skip to content

translate_sql() fails when the target for translation starts with a dot #1529

@MichaelChirico

Description

@MichaelChirico

I want to add a translation for .POSIXct() --> TIMESTAMP_FROM_UNIX_SECONDS():

https://cloud.google.com/dataflow/docs/reference/sql/timestamp_functions#timestamp_from_unix_seconds

However, the leading . appears to be throwing everything off. I added a simple placeholder translation in this branch:

https://github.com/MichaelChirico/dbplyr/tree/leading-dot

.POSIXct = sql_prefix("foo", 1)

With that, I get a failed translation:

library(dbplyr)
con=simulate_dbi()
translate_sql(.POSIXct(0), con=con)
# <SQL> .POSIXct(0.0)

(should be foo())

I looked into this a bit and I got lost in the details of the implementation. sql_variant() seems to be doing just fine, as base_scalar does contain the correct object still:

evalq(exists(".POSIXct", base_scalar), asNamespace("dbplyr"))
# [1] TRUE

However, this step apparently fails to find the correct translation:

dbplyr/R/translate-sql.R

Lines 148 to 149 in 860bd6a

mask <- sql_data_mask(x, variant, con = con, window = window)
escape(eval_tidy(x, mask), con = con)

I am not familiar enough with the details of tidy eval to know if there's an easy fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions