[英]Apache Airflow - Connection issue to MS SQL Server using pymssql + SQLAlchemy
[英]Create Clustered Columnstore index(MS SQL Server) using SqlAlchemy?
您可以通过侦听表after_create
事件并注入一些自定义 SQL 来解决此问题:
engine = sqlalchemy.create_engine(...)
metadata = MetaData(engine)
table = students = Table(
'students', metadata,
Column('id', Integer),
Column('name', String(100)), #Must be fixed length!
Column('lastname', String(100)),
)
event.listen(
table,
"after_create",
DDL("CREATE CLUSTERED COLUMNSTORE INDEX ix_%(table)s_columnstore ON %(fullname)s")
)
table.create()
sqlalchemy 允许您注入自定义 SQL 处理程序,因此这应该可以工作:
# Create a custom mssql_columnstore argument for Indexes:
Index.argument_for("mssql", "columnstore", None)
# Custom SQL generator for columnstore indexes
@compiles(CreateIndex, "mssql")
def compile_create_index(create, compiler, **kw):
preparer = compiler.preparer
mssql_opts = create.element.dialect_options["mssql"]
columnstore = mssql_opts.get("columnstore", None)
if(not columnstore):
stmt = compiler.visit_create_index(create, **kw)
return stmt
name = preparer.format_index(create.element)
table_name = preparer.format_table(create.element.table)
stmt = f"CREATE CLUSTERED COLUMNSTORE INDEX {name} ON {table_name}"
return stmt
engine = makeEngine()
metadata = MetaData(engine)
table = students = Table(
'students', metadata,
Column('id', Integer),
Column('name', String(100)),
Column('lastname', String(100)),
# Use the columnstore index flag here:
Index('idx_id', mssql_columnstore = True),
)
table.create()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.