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] Translate mssql to tsql in read_sql scan #2330

Merged
merged 1 commit into from
May 31, 2024
Merged

Conversation

colin-ho
Copy link
Contributor

@colin-ho colin-ho commented May 31, 2024

When running read_sql against SQL server using a SQL Alchemy connection, for example:

connection_url = sqlalchemy.engine.URL.create(
    "mssql+pyodbc",
    username=user,
    password=password,
    host=host,
    port=1433,
    database=database,
    query={
        "driver": "ODBC Driver 18 for SQL Server",
    },
)
def create_conn():
    return sqlalchemy.create_engine(connection_url).connect()

df = daft.read_sql("SELECT * FROM test_data", create_conn)

The query errors with Unsupported dialect: mssql, please refer to the documentation for supported dialects.

This is because SQLGlot, the library that read_sql uses for query construction, does not recognize mssql as a dialect, it instead recognizes tsql, which is the name of the SQL dialect for Microsoft SQL Server: https://learn.microsoft.com/en-us/sql/t-sql/language-reference?view=sql-server-ver16

This PR adds a translation step during sql query construction to fix this issue.

NOTE:

  • This PR was tested locally against a Docker instance of Azure SQL Edge.

@github-actions github-actions bot added the bug Something isn't working label May 31, 2024
@colin-ho colin-ho merged commit 0ba9a19 into main May 31, 2024
44 checks passed
@colin-ho colin-ho deleted the colin/read_sql_fix branch May 31, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants