Defining a custom Constant for Bigquery removes function call #8213
Answered
by
jcrist
saschahofmann
asked this question in
Q&A
-
I am defining a custom constant that should compile to Bigquery's from ibis.expr.operations import Constant
import ibis.expr.datatypes as dt
from ibis import bigquery
from ibis.backends.bigquery.compiler import BigQueryExprTranslator
compiles = BigQueryExprTranslator.compiles
class Today(Constant):
dtype = dt.date
def today():
return Today().to_expr()
@compiles(Today)
def _today(t, expr):
return "CURRENT_DATE()"
bigquery.compile(today())
# returns 'SELECT\n CURRENT_DATE AS `Today`'
# I expect 'SELECT\n CURRENT_DATE() AS `Today`' |
Beta Was this translation helpful? Give feedback.
Answered by
jcrist
Mar 15, 2024
Replies: 1 comment 5 replies
-
@cpcloud Sorry for tagging you so shamelessly but I cannot figure this one out. It seems to be related to SQLGlot? |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I suspect this is due to
sqlglot
- in ibis 7.0 we started using sqlglot as part of the bigquery compilation chain. Does it make a difference though? From looking at the bigquery docs AFAICT bothCURRENT_DATE
andCURRENT_DATE()
should be identical: https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#current_date.Since getting the current date is a general enough operation it makes sense to support it directly in ibis itself. I've pushed a PR up here: #8664.