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

Support boolean casting and other trino operation for Trino SQL execution #1658

Closed
wmaiouiru opened this issue May 18, 2023 · 1 comment
Closed

Comments

@wmaiouiru
Copy link

I am trying to use sqlglot for unit testing complex queries with test case data.
However, Casting to 'Type.BOOLEAN' not implemented.

from sqlglot.executor import execute

tables = {
    "dates": [
        {"duration": "P4Y11M17D"},
        {"duration": "P6M1D"},
        {"duration": "P8M"},
    ],
}
sql_query = """
    SELECT sac.duration,
    CASE WHEN CAST(POSITION('D' IN duration) AS BOOLEAN) THEN 
        CAST(REGEXP_REPLACE(SUBSTR(duration, POSITION('D' IN duration) -2 , 2), '[^0-9]', '') AS INTEGER)
    ELSE
        0
    END as duration_day
    FROM dates sac
"""

schema = {
    "dates": {
        "duration": "VARCHAR",
    }
}


result = execute(sql_query, schema=schema, tables=tables, read='trino')
print(result)

Curious if this could be easily supported... any guides on how to support this?

@tobymao
Copy link
Owner

tobymao commented May 18, 2023

i wouldn't use sqlglot for unit testing complex queries, it's in a "toy" state. you should probably use duckdb or pyspark

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