DATEPART Function fails if you use text('YEAR') instead of 'YEAR'
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 45/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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)
- Langage dominant
- Python
- Étoiles
- 233
- Forks
- 152
- Merge moyen
- 21 h 5 min
- PR mergées (30 j)
- 10
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de databricks/databricks-sql-python
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
Toutes les issues de databricks/databricks-sql-python
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
anthropics/skills#1811 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
datalayer/mcp-compose#42 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
UKGovernmentBEIS/inspect_evals#2523 ·