Skip to content

Pandas makes bad DESCRIBE query when using SQLAlchemy #184

Not planned

Description

@freud14-tm

When using the SQLAlchemy engine with Pandas, it seems that Pandas makes a bad DESCRIBE query. Here is the code:

import os

import pandas as pd

from sqlalchemy import create_engine


server_hostname = os.getenv("DATABRICKS_SERVER_HOSTNAME")
http_path = os.getenv("DATABRICKS_HTTP_PATH")
access_token = os.getenv("DATABRICKS_TOKEN")
engine = create_engine(
    f"databricks://token:{access_token}@{server_hostname}?http_path={http_path}&catalog=hive_metastore&schema=default",
)
with engine.connect() as connection:
    print(pd.read_sql("SELECT * FROM test", connection))

Here are the two query resulting from that code:
image

It does not do that when using SQL connector instead:

import os

import pandas as pd

from databricks import sql


with sql.connect(
    server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
    http_path=os.getenv("DATABRICKS_HTTP_PATH"),
    access_token=os.getenv("DATABRICKS_TOKEN"),
) as connection:
    print(pd.read_sql("SELECT * FROM test", connection))

Here are version numbers:

In [1]: import sqlalchemy

In [2]: sqlalchemy.__version__
Out[2]: '1.4.49'

In [3]: from databricks import sql

In [4]: sql.__version__
Out[4]: '2.8.0'

Activity

  1. freud14-tm commented on Aug 1, 2023

    @freud14-tm
    Author

    Also, it would be nice if catalog and schema were optional.

  2. susodapop commented on Aug 1, 2023

    @susodapop
    Contributor

    What version of pandas do you have installed?

  3. freud14-tm commented on Aug 1, 2023

    @freud14-tm
    Author

    Was on 1.5.3 but just tried on 2.0.3 and get the same thing.

  4. self-assigned this
    on Aug 3, 2023
  5. saadali-e commented on Jan 17, 2024

    @saadali-e

    @susodapop I have the same issue - has this been resolved in the newer versions?

  6. added
    bug
    on Apr 17, 2024
  7. cathleeny commented on Dec 3, 2026

    @cathleeny
    Collaborator

    This one isn't a bug in the connector. pandas.read_sql first checks whether the string is a table name, which sends a DESCRIBE; the query still runs and returns data afterwards. Use pd.read_sql_query(sql, conn) to skip that check.

    Reference: https://pandas.pydata.org/docs/reference/api/pandas.read_sql.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugsqlalchemy

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions