Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: Can't cast NULL TIMESTAMP with dialect="bigquery" #10752

Closed
1 task done
LennartKloppenburg opened this issue Jan 30, 2025 · 4 comments
Closed
1 task done

question: Can't cast NULL TIMESTAMP with dialect="bigquery" #10752

LennartKloppenburg opened this issue Jan 30, 2025 · 4 comments
Labels
bigquery The BigQuery backend question Questions about the library timestamps Issues related to the timestamp API

Comments

@LennartKloppenburg
Copy link

LennartKloppenburg commented Jan 30, 2025

What happened?

>>> ibis.to_sql(ibis.literal(None).cast("timestamp"), dialect='bigquery')
SQLString('SELECT\n  CAST(NULL AS DATETIME) AS `Cast_None_timestamp`')
>>> ibis.to_sql(ibis.null().cast("timestamp"), dialect='bigquery')
SQLString('SELECT\n  CAST(NULL AS DATETIME) AS `Cast_None_timestamp`')

I would expect the following statements to output a CAST(NULL AS TIMESTAMP). I found issues related to BigQuery's TIMESTAMP and DATETIME columns but I really need a CAST(NULL AS TIMESTAMP) because I'm using it in a .union(...) where the types need to match.

What version of ibis are you using?

10.0.0.dev459

What backend(s) are you using, if any?

BigQuery

Code of Conduct

  • I agree to follow this project's Code of Conduct
@cpcloud
Copy link
Member

cpcloud commented Feb 1, 2025

Thanks for the issue!

  1. timestamp is a timestamp without a timezone, which corresponds to BigQuery's DATETIME type.
  2. timestamp("UTC") is a timestamp with the UTC timezone, which corresponds to BigQuery's TIMESTAMP type.

Does that help?

@cpcloud cpcloud added question Questions about the library and removed bug Incorrect behavior inside of ibis labels Feb 1, 2025
@cpcloud cpcloud modified the milestone: 10.0 Feb 1, 2025
@cpcloud cpcloud changed the title bug: Can't cast NULL TIMESTAMP with dialect="bigquery" question: Can't cast NULL TIMESTAMP with dialect="bigquery" Feb 1, 2025
@cpcloud cpcloud added bigquery The BigQuery backend timestamps Issues related to the timestamp API labels Feb 1, 2025
@cpcloud
Copy link
Member

cpcloud commented Feb 1, 2025

Here are some examples of what you're trying to do:

In [1]: import ibis

In [2]: ibis.to_sql(ibis.literal(None).cast("timestamp"), dialect='bigquery')
Out[2]:
SELECT
  CAST(NULL AS DATETIME) AS `Cast_None_timestamp`

In [3]: ibis.to_sql(ibis.literal(None).cast("timestamp('UTC')"), dialect='bigquery')
Out[3]:
SELECT
  CAST(NULL AS TIMESTAMP) AS `Cast_None_timestamp_'UTC'`

In [4]: ibis.to_sql(ibis.null().cast("timestamp"), dialect='bigquery')
Out[4]:
SELECT
  CAST(NULL AS DATETIME) AS `Cast_None_timestamp`

In [5]: ibis.to_sql(ibis.null().cast("timestamp('UTC')"), dialect='bigquery')
Out[5]:
SELECT
  CAST(NULL AS TIMESTAMP) AS `Cast_None_timestamp_'UTC'`

@cpcloud
Copy link
Member

cpcloud commented Feb 1, 2025

Closing this out for now!

@cpcloud cpcloud closed this as completed Feb 1, 2025
@github-project-automation github-project-automation bot moved this from backlog to done in Ibis planning and roadmap Feb 1, 2025
@LennartKloppenburg
Copy link
Author

@cpcloud Cheers Phillip! That did it :) Thanks for coming back to me so quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bigquery The BigQuery backend question Questions about the library timestamps Issues related to the timestamp API
Projects
Status: done
Development

No branches or pull requests

2 participants