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

Commit85586bc

Browse files
authored
Merge pull request#1 from PeterDKay/main
Releasing dialect changes from personal forked repo to sede-open
2 parents6f83144 +4c79a9f commit85586bc

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

‎src/databricks/sqlalchemy/dialect/__init__.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class DatabricksDialect(default.DefaultDialect):
8080
supports_multivalues_insert:bool=True
8181
supports_native_decimal:bool=True
8282
supports_sane_rowcount:bool=False
83+
supports_comments:bool=True
8384

8485
@classmethod
8586
defdbapi(cls):
@@ -174,6 +175,7 @@ def get_columns(self, connection, table_name, schema=None, **kwargs):
174175
"nullable":bool(col.NULLABLE),
175176
"default":col.COLUMN_DEF,
176177
"autoincrement":Falseifcol.IS_AUTO_INCREMENT=="NO"elseTrue,
178+
'comment':col.REMARKS,
177179
}
178180
columns.append(this_column)
179181

@@ -244,11 +246,14 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
244246

245247
defget_table_names(self,connection,schema=None,**kwargs):
246248
TABLE_NAME=1
249+
catalog="`"+self.catalog+"`"
250+
schema= ("`"+schema+"`")or ("`"+self.schema+"`")
251+
247252
withself.get_driver_connection(
248253
connection
249254
)._dbapi_connection.dbapi_connection.cursor()ascur:
250255
sql_str="SHOW TABLES FROM {}".format(
251-
".".join([self.catalog,schemaorself.schema])
256+
".".join([catalog,schema])
252257
)
253258
data=cur.execute(sql_str).fetchall()
254259
_tables= [i[TABLE_NAME]foriindata]

‎src/databricks/sqlalchemy/dialect/base.py‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
importre
2-
fromsqlalchemy.sqlimportcompiler
2+
fromsqlalchemy.sqlimportcompiler,sqltypes,ColumnElement
33

44

55
classDatabricksIdentifierPreparer(compiler.IdentifierPreparer):
@@ -15,3 +15,52 @@ def __init__(self, dialect):
1515
classDatabricksDDLCompiler(compiler.DDLCompiler):
1616
defpost_create_table(self,table):
1717
return" USING DELTA"
18+
19+
defvisit_set_column_comment(self,create,**kw):
20+
"""
21+
Example syntax for adding column comment:
22+
"ALTER TABLE schema.table_name CHANGE COLUMN COLUMN_NAME COMMENT 'Comment to be added to column';"
23+
24+
"""
25+
return"""ALTER TABLE {0} CHANGE COLUMN {1} COMMENT {2}""".format(
26+
self._format_table_from_column(
27+
create,use_schema=True
28+
),
29+
self.preparer.format_column(
30+
create.element,use_table=False
31+
),
32+
self.sql_compiler.render_literal_value(
33+
create.element.comment,sqltypes.String()
34+
),
35+
)
36+
37+
defvisit_drop_column_comment(self,drop,**kw):
38+
"""
39+
Example syntax for dropping column comment:
40+
"ALTER TABLE schema.table_name CHANGE COLUMN COLUMN_NAME COMMENT '';"
41+
42+
Note: There is no syntactical 'DROP' statement in this case, the comment must be replaced with an empty string
43+
"""
44+
return"ALTER TABLE {0} CHANGE COLUMN {1} COMMENT '';".format(
45+
self._format_table_from_column(
46+
drop,use_schema=True
47+
),
48+
self.preparer.format_column(
49+
drop.element,use_table=False
50+
)
51+
)
52+
53+
def_format_table_from_column(self,column_object,use_schema=False):
54+
"""
55+
Prepare a quoted table name from the column object (including schema if specified)
56+
"""
57+
schema_table_column=self.preparer.format_column(
58+
column_object.element,use_table=True,use_schema=True
59+
)
60+
61+
name=schema_table_column.split(".")[1]
62+
63+
ifuse_schema:
64+
name=schema_table_column.split(".")[0]+'.'+name
65+
66+
returnname

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp