Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Table Create With Identity Column Fails To Create Identity Column #175

Closed
Assignees
susodapop
@narquette

Description

@narquette

Issue:

When I attempt to create a sqlalchemy table with an indentity seed the compiled code doesn't have the required information needed to setup an identity column in the database.

Sample Code:

assume that you already have databricks configured for command line usage ("databricks config")

fromconfigparserimportConfigParserfrompathlibimportPathfromsqlalchemyimportcreate_engine,Identityfromsqlalchemy.ormimportSessionfromsqlalchemy.engineimportURLfromsqlalchemy.schemaimportTable,Column,MetaData,CreateTablefromsqlalchemy.sql.sqltypesimportBIGINT,VARCHARconfig_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']['token'].replace('http://','').replace('/',''),'port':43,'database':'curv'}catalog=config['DEFAULT']['catalog']http_path="/sql/1.0/warehouses/3c0fbf823204df89"url=URL.create(**{key:valueforkey,valueinurl_info.items()},query={'http_path':http_path,'catalog':catalog})engine=create_engine(url=url)session=Session(engine)table=Table('test',MetaData(),Column('id',BIGINT,primary_key=True,nullable=False,server_default=Identity(start=1)),Column('comments',VARCHAR(255),nullable=True))fromconfigparserimportConfigParserfrompathlibimportPathfromsqlalchemyimportcreate_engine,Identityfromsqlalchemy.ormimportSessionfromsqlalchemy.engineimportURLfromsqlalchemy.schemaimportTable,Column,MetaData,CreateTablefromsqlalchemy.sql.sqltypesimportBIGINT,VARCHARconfig_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']['token'].replace('http://','').replace('/',''),'port':43,'database':'<database_name>'}catalog=config['DEFAULT']['catalog']http_path="<path_to_cluster>"url=URL.create(**{key:valueforkey,valueinurl_info.items()},query={'http_path':http_path,'catalog':catalog})engine=create_engine(url=url)session=Session(engine)table=Table('test',MetaData(),Column('id',BIGINT,primary_key=True,nullable=False,server_default=Identity(start=1)),Column('comments',VARCHAR(255),nullable=True))# with needed column informationprint(CreateTable(table))# without needed column informationprint(CreateTable(table).compile(bind=engine))

what printed CreateTable looks like (correct)

# with needed column informationprint(CreateTable(table))# outputCREATE TABLE test (id BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), comments VARCHAR(255), PRIMARY KEY (id))

what printed compiled CreateTable looks like (incorrect)

# without needed column informationprint(CreateTable(table).compile(bind=engine))CREATE TABLE test (id BIGINT NOT NULL, comments STRING, PRIMARY KEY (id)) USING DELTA

Machine Info

OS: Window Server 2022 VM

Software Info:

Python - 3.10.2

Python Packages:

databricks-sql-connector : 2.5.2
sqlalchemy : 1.4.48

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp