DATEPART Function fails if you use text('YEAR') instead of 'YEAR'
還沒有人認領這個 Issue。
評估
研究方向
Reproduce the DATEPART(text('YEAR'), table_date.c['date_field']) example against the Databricks dialect and inspect the dialect's compilation path for DATEPART. Compare it with DATEPART('YEAR', ...) to identify how text('YEAR') is rendered; done means the text form compiles and executes without treating YEAR as an invalid quoted identifier.
由索引模型根據 Issue 內容生成。
描述
Overview
When I attempt to use a datepart function with text('YEAR'), the compile code for the databricks dialect throws and error (see sample code below as it is trying to treat the text part as a quoted identifier common to databricks `.
Environment Information
OS = Windows 2022 Server
Python Version = 3.10.2
Python Package Versions
- sqlalchemy=1.4.48
- databricks-sql-connector=2.5.2
Code Sample
from configparser import ConfigParser
from pathlib import Path
from sqlalchemy import create_engine, Identity
from sqlalchemy.orm import Session
from sqlalchemy.engine import URL
from sqlalchemy.schema import Table, Column, MetaData, CreateTable
from sqlalchemy.sql.sqltypes import BIGINT, VARCHAR, DATE
from sqlalchemy.sql.expression import func, and_, or_, text, distinct, insert, union_all
config_path = Path.home() / '.databrickscfg'
config = ConfigParser()
config.read(config_path)
token = config['DEFAULT']['token']
url_info = {
'drivername': 'databricks',
'username': 'token',
'password': token,
'host': config['DEFAULT']['host'].replace('https://', '').replace('/', ''),
'port': 43,
'database': 'curv'
}
catalog = config['DEFAULT']['catalog']
http_path = "/sql/1.0/warehouses/3c0fbf823204df89"
url = URL.create(
**{key: value for key, value in url_info.items()},
query={'http_path': http_path, 'catalog': catalog}
)
engine = create_engine(url=url,
pool_pre_ping=1)
session = Session(engine)
table_date = Table(
'test_date',
MetaData(),
Column('date_field', DATE, nullable=False)
)
table_date.create(bind=engine)
table_date.insert().values(date_field='2019-02-12')
query = session.query(func.DATEPART(text('YEAR'), table_date.c['date_field']).label('date_field'))
session.execute(query)
- 主要語言
- Python
- 星號
- 233
- 分支
- 152
- 平均合併
- 21 小時 5 分鐘
- 30 天內合併 PR
- 10
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
databricks/databricks-sql-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
-
難度 2/5 1-3 小時 新手友好度 76/100
-
難度 2/5 1-3 小時 新手友好度 78/100
-
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 84/100
查看 databricks/databricks-sql-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 75/100
anthropics/skills#1811 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
speaches-ai/speaches#678 ·
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
datalayer/mcp-compose#42 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
conda-forge/spacy-feedstock#177 ·
-
難度 2/5 1-3 小時 新手友好度 70/100
UKGovernmentBEIS/inspect_evals#2523 ·