Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Wrong sql when adding a time interval to a date. #71

Open
jcmincke opened this issue Jun 14, 2021 · 0 comments
Open

Wrong sql when adding a time interval to a date. #71

jcmincke opened this issue Jun 14, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@jcmincke
Copy link


import ibis
import ibis_bigquery
from google.cloud import bigquery
import pandas as pd
import datetime as dt

my_table = 'my_table'

pdf = pd.DataFrame({'date': [dt.date(2020, 1, 1), dt.date(2021, 5, 15), dt.date(2021, 7, 9)]})

# Load client
client = bigquery.Client(project=my_project)

# Load data to BQ
client.delete_table(my_dataset + "." + my_table, not_found_ok=True)
job = client.load_table_from_dataframe(pdf, my_dataset + "." + my_table)

ibis.options.interactive = False

conn = ibis_bigquery.connect(
    project_id=my_project,
    dataset_id=my_dataset)

t = conn.table(my_table)

delta = dt.timedelta(days=6)

e1 = t.mutate(z=t.date + ibis.literal(delta))

print(ibis.bigquery.compile(e1))

"""
SELECT *, DATE_ADD(`date`, INTERVAL 6 days, 0:00:00 DAY) AS `z` FROM ...
"""

e1.execute()

And the exception is:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/ibis/expr/types.py", line 223, in execute
    return execute(
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/ibis/client.py", line 382, in execute
    return backend.execute(
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/ibis/client.py", line 222, in execute
    result = self._execute_query(query, **kwargs)
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/ibis/client.py", line 229, in _execute_query
    return query.execute()
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/ibis_bigquery/client.py", line 196, in execute
    with self.client._execute(
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/ibis_bigquery/client.py", line 482, in _execute
    query.result()  # blocks until finished
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/google/cloud/bigquery/job/query.py", line 1266, in result
    super(QueryJob, self).result(retry=retry, timeout=timeout)
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/google/cloud/bigquery/job/base.py", line 679, in result
    return super(_AsyncJob, self).result(timeout=timeout, **kwargs)
  File "/Users/V3/windev/carrefour/gcp/venv/lib/python3.9/site-packages/google/api_core/future/polling.py", line 134, in result
    raise self._exception
google.api_core.exceptions.BadRequest: 400 Syntax error: Expected ")" but got ":" at [1:46]
(job ID: adf6f6be-fbf2-485f-ad6c-e651ab84d978)
                  -----Query Job SQL Follows-----                   
    |    .    |    .    |    .    |    .    |    .    |    .    |
   1:SELECT *, DATE_ADD(`date`, INTERVAL 6 days, 0:00:00 DAY) AS `z`
   2:FROM ....
   3:LIMIT 10000
    |    .    |    .    |    .    |    .    |    .    |    .    |

@tswast tswast added the bug Something isn't working label Jun 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants