Connection without specifying catalog name in connection string causes an error

未关闭
#305 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python, sql
领域
databases

调研方向

从 src/databricks/sqlalchemy/base.py 第 278 行附近开始,跟踪当连接字符串省略 catalog 时 get_table_names 如何处理 catalog。使用一个 schema 和显式 catalog 重现 SHOW VIEWS 失败,然后验证 metadata 检查可以针对该 catalog,而不会生成 None catalog。

由索引模型根据 Issue 内容生成。

描述

bug sqlalchemy

Hello,
I'm trying to create an engine connection which could manage multiple catalogs at once

connection_uri = "databricks://token:XXXXXX@DB_HOST?http_path=/sql/1.0/warehouses/DWH_ID"
engine = create_engine(connection_uri, future=True)
meta_inspector = inspect(self.engine)

Later when calling for example
tables = meta_inspector.get_table_names('test_schema')
I get the following error

backend-1  | sqlalchemy.exc.DatabaseError: (databricks.sql.exc.ServerOperationError) Fail to execute the command as the target schema `None.test_schema` is not in the current catalog. Please set the current catalog with 'USE CATALOG None' first.
backend-1  | [SQL: SHOW VIEWS FROM `None`.`test_schema`]

After further inspection I found the current method being called:
https://github.com/databricks/databricks-sql-python/blob/62eb1d407ab03fc2c57a6626bec2173dbdd8bbb3/src/databricks/sqlalchemy/base.py#L278

It could be fixed with adding on Line 278 the following:
_target_catalog = kwags.get("catalog") or self.catalog
and referencing the catalog name in the method get_table_names
tables = meta_inspector.get_table_names(schema='test_schema',catalog='test_catalog')

NOTE : I'm avoiding creating a different engine for every catalog due to slow response from Databricks
I'm hesitant in opening a PR for this as it's not well tested and I'm not sure if there is an alternative to what i'm trying to achieve , so any feedback would be great !

主要语言
Python
星标
233
派生
152
平均合并
21 小时 5 分钟
30 天内合并 PR
10

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

databricks/databricks-sql-python 的其他 Issue

查看 databricks/databricks-sql-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。