cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

port undefined error in SQLDatabase.from_databricks (langchain.sql_database)

Octavian1
Contributor

The following assignment:

from langchain.sql_database import SQLDatabase

dbase = SQLDatabase.from_databricks(
catalog=catalog,
schema=db,
host=host,
api_token=token,
)

fails with 

ValueError: invalid literal for int() with base 10: ''
because of
cls._assert_port(port),
in /lib/python3.10/site-packages/sqlalchemy/engine/url.py:211, in URL.create(cls, drivername, username, password, host, port, database, query)
as shown in the error trace.
 
Couldn't find any information regarding this (for instance, in the example given in: https://docs.gcp.databricks.com/en/large-language-models/langchain.html)
 
The token and host are OK. Also the catalog and schema have correct values.
 
Using langchain==0.1.5.

 

4 REPLIES 4

Kaniz_Fatma
Community Manager
Community Manager

Hi @Octavian1Ensure that the port parameter youโ€™re passing to SQLDatabase.from_databricks is a valid integer. If itโ€™s empty or contains non-numeric characters, that could be the root cause.

  • In a Stack Overflow post, someone faced a similar issue while connecting SQLAlchemy (SQLDatabaseChain from langchain) to SingleStoreDB. They provided a workaround using a custom connection URL. 
  • Hereโ€™s an example snippet:
    from sqlalchemy import create_engine
    engine = create_engine(CONNECTION_URL)
    db = SQLDatabase(engine)
    
    You might need to adapt this approach to your specific use case1.
  • Ensure that your langchain version (0.1.5) is compatible with your environment and dependencies. Sometimes, upgrading to a newer version might resolve issues.
  • If you encounter any other issues, feel free to ask!

Hi @Kaniz_Fatma 

You may be right regarding SQLAlchemy, the trace hints at something related:

> /lib/python3.10/site-packages/langchain_community/utilities/sql_database.py", line 133, in from_uri

> """Construct a SQLAlchemy engine from URI."""

But I don't get why in the SQLDatabase.from_databricks documentation there is no mention of any port parameter, neither in the example notebooks?

Thanks,

Octavian

vburam
New Contributor II

I am also facing the same issue. not able to connect even after using sqlalchemy

vburam
New Contributor II

SQL alchemy url: databricks+https://<token>@abc.cloud.databricks.com:443/sql/1.0/warehouses/9265c8e0?catalog=customer&schema=chatbot

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group