list cant be passed as the parameter

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

还没有人认领这个 Issue。

评估

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

调研方向

从 docs/parameters.md 开始,针对 Databricks SQL Connector 4.0.0 运行提供的 Python 复现代码,重点关注列表值参数示例以及报告的类型推断错误。跟踪文档所引用的参数处理入口点,然后使用回归测试验证预期行为;当文档中记录的列表参数用例表现一致,或文档明确说明其限制时,即视为完成。

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

描述

enhancement

Versions:
Python: 3.12
Databricks SQL Connector: 4.0.0
polars: 1.16.0

I am trying to pass list parametes as it was mentined in docs:
https://github.com/databricks/databricks-sql-python/blob/main/docs/parameters.md

Steps to reproduce:

  1. Create and populate table:
    ` CREATE TABLE epam.base.tmp_params_table (
    product_code VARCHAR(15),
    qty int,
    BU VARCHAR(15)
    );

INSERT INTO epam.base.tmp_params_table (product_code, qty, BU)
VALUES
('prod_cd_1', 5, 'BU_1'),
('prod_cd_2', 4, 'BU_1'),
('prod_cd_3', 3, 'BU_1'),
('prod_cd_4', 3, 'BU_2'),
('prod_cd_5', 1, 'BU_2');`

  1. Run queries using connector:
    `import polars as pl
    from configs.databricks_config import databricks_settings
    from databricks import sql
    from databricks.sql.parameters import StringParameter, IntegerParameter

query_params_list = [
[
"SELECT product_code, qty, BU from epam.base.tmp_params_table where product_code in (:product_code) and BU= :BU",
{"product_code": ["prod_cd_1", "prod_cd_2", "prod_cd_4"], "BU": ["BU_1"]},
],
[
"SELECT product_code, qty, BU from epam.base.tmp_params_table where product_code in (:product_code) and BU= :BU",
[
StringParameter(name="product_code", value="prod_cd_1, prod_cd_2, prod_cd_4"),
StringParameter(name="BU", value="BU_1"),
],
],
[
"SELECT product_code, qty, BU from epam.base.tmp_params_table where qty in %(:qty)s",
{"qty": [1, 2, 3]},
],
["SELECT product_code, qty, BU from :tab_name", {"tab_name": "epam.base.tmp_params_table"}],
]

with sql.connect(
server_hostname=databricks_settings.host,
http_path=databricks_settings.http_path,
access_token=databricks_settings.api_token,
) as connection:
with connection.cursor() as cursor:
for num, record in enumerate(query_params_list):
query, params = record
try:
cursor.execute(query, params)
table = cursor.fetchall_arrow()
res_df = pl.from_arrow(table)
print(num, res_df.shape, params)
except Exception as error:
print(num, error, params)`

and I see this error:
databricks.sql.exc.NotSupportedError: Could not infer parameter type from value: ['prod_cd_1', 'prod_cd_2', 'prod_cd_4'] - <class 'list'> Please specify the type explicitly.

主要语言
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 摘要。