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

bug: BigQuery dialect parsing error when cast as date using format #1753

Closed
aballiet opened this issue Jun 10, 2023 · 1 comment
Closed

bug: BigQuery dialect parsing error when cast as date using format #1753

aballiet opened this issue Jun 10, 2023 · 1 comment

Comments

@aballiet
Copy link

sqlglot fails at parsing BigQuery SQL query containing cast with date format.

Example :

Fully reproducible code snippet

query = """
with clean as (
  select
    _row
    , cast(start_date as date format 'MM/DD/YYYY') as start_date
    , cast(end_date as date format 'MM/DD/YYYY') as end_date
  from `my_project`.`my_schema`.`my_table`
)

select *
from clean
"""

from sqlglot import parse_one

parse_one(query, read="bigquery")

-> Generates the error :

{
    "name": "ParseError",
    "message": "Expecting ). Line 5, Col: 36.\n  \nwith clean as
    ....
}

Expected output :

(SELECT expressions: 
  (STAR ), from: 
  (FROM this: 
    (TABLE this: 
      (IDENTIFIER this: clean, quoted: False))), with: 
  (WITH expressions: 
    (CTE this: 
      (SELECT expressions: 
        (COLUMN this: 
          (IDENTIFIER this: _row, quoted: False)), 
        (ALIAS this: 
          (CAST this: 
            (COLUMN this: 
              (IDENTIFIER this: start_date, quoted: False)), to: 
            (DATATYPE this: Type.DATE, nested: False, prefix: False)), alias: 
          (IDENTIFIER this: start_date, quoted: False)), 
        (ALIAS this: 
          (CAST this: 
            (COLUMN this: 
              (IDENTIFIER this: end_date, quoted: False)), to: 
            (DATATYPE this: Type.DATE, nested: False, prefix: False)), alias: 
          (IDENTIFIER this: end_date, quoted: False)), from: 
        (FROM this: 
          (TABLE this: 
            (IDENTIFIER this: my_table, quoted: True), db: 
            (IDENTIFIER this: my_schema, quoted: True), catalog: 
            (IDENTIFIER this: my_project, quoted: True)))), alias: 
      (TABLEALIAS this: 
        (IDENTIFIER this: clean, quoted: False)))))
@tobymao
Copy link
Owner

tobymao commented Jun 10, 2023

teradata already has this but i think it's wrong, it should be exp.StringToTime. we need to have time_format inside of the parser

adrianisk pushed a commit to adrianisk/sqlglot that referenced this issue Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants