Skip to content

Commit 4a1f299

Browse files
committed
index with data support
1 parent 389dcaa commit 4a1f299

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

sqlalchemy_iris/base.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,30 @@ def get_column_specification(self, column, **kwargs):
579579
def post_create_table(self, table):
580580
return " WITH %CLASSPARAMETER ALLOWIDENTITYINSERT = 1"
581581

582+
def visit_create_index(
583+
self, create, include_schema=False, include_table_schema=True, **kw
584+
):
585+
text = super().visit_create_index(create, include_schema, include_table_schema, **kw)
586+
587+
index = create.element
588+
preparer = self.preparer
589+
590+
# handle other included columns
591+
includeclause = index.dialect_options["iris"]["include"]
592+
if includeclause:
593+
inclusions = [
594+
index.table.c[col]
595+
if isinstance(col, util.string_types)
596+
else col
597+
for col in includeclause
598+
]
599+
600+
text += " WITH DATA (%s)" % ", ".join(
601+
[preparer.quote(c.name) for c in inclusions]
602+
)
603+
604+
return text
605+
582606

583607
class IRISTypeCompiler(compiler.GenericTypeCompiler):
584608
def visit_boolean(self, type_, **kw):
@@ -667,6 +691,10 @@ class IRISDialect(default.DefaultDialect):
667691
type_compiler = IRISTypeCompiler
668692
execution_ctx_cls = IRISExecutionContext
669693

694+
construct_arguments = [
695+
(schema.Index, {"include": None}),
696+
]
697+
670698
def __init__(self, **kwargs):
671699
default.DefaultDialect.__init__(self, **kwargs)
672700

@@ -808,6 +836,8 @@ def has_table(self, connection, table_name, schema=None, **kw):
808836
def get_indexes(self, connection, table_name, schema=None, unique=False, **kw):
809837
schema_name = self.get_schema(schema)
810838
indexes = ischema.indexes
839+
tables = ischema.tables
840+
index_def = ischema.index_definition
811841

812842
s = (
813843
sql.select(
@@ -816,6 +846,20 @@ def get_indexes(self, connection, table_name, schema=None, unique=False, **kw):
816846
indexes.c.primary_key,
817847
indexes.c.non_unique,
818848
indexes.c.asc_or_desc,
849+
index_def.c.Data,
850+
)
851+
.select_from(indexes)
852+
.outerjoin(
853+
index_def,
854+
sql.and_(
855+
index_def.c.SqlName == indexes.c.index_name,
856+
index_def.c.parent ==
857+
sql.select(tables.c.classname)
858+
.where(
859+
indexes.c.table_name == tables.c.table_name,
860+
indexes.c.table_schema == tables.c.table_schema,
861+
).scalar_subquery()
862+
),
819863
)
820864
.where(
821865
sql.and_(
@@ -838,6 +882,7 @@ def get_indexes(self, connection, table_name, schema=None, unique=False, **kw):
838882
_,
839883
nuniq,
840884
_,
885+
include,
841886
) = row
842887

843888
indexrec = indexes[idxname]
@@ -849,6 +894,12 @@ def get_indexes(self, connection, table_name, schema=None, unique=False, **kw):
849894
indexrec["column_names"].append(
850895
self.normalize_name(colname)
851896
)
897+
include = include.split(',') if include else []
898+
indexrec["include_columns"] = include
899+
if include:
900+
indexrec["dialect_options"] = {
901+
"iris_include": include
902+
}
852903

853904
indexes = list(indexes.values())
854905
return indexes
@@ -1007,7 +1058,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
10071058
schema_name = self.get_schema(schema)
10081059
tables = ischema.tables
10091060
columns = ischema.columns
1010-
property = ischema.property
1061+
property = ischema.property_definition
10111062

10121063
whereclause = sql.and_(
10131064
columns.c.table_name == str(table_name),

sqlalchemy_iris/information_schema.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def process_result_value(self, value, dialect):
7272
Column("DESCIPTION", String, key="desciption"),
7373
schema="INFORMATION_SCHEMA",
7474
)
75-
property = Table(
75+
property_definition = Table(
7676
"PropertyDefinition",
7777
ischema,
7878
Column("parent", String),
@@ -101,6 +101,15 @@ def process_result_value(self, value, dialect):
101101
schema="INFORMATION_SCHEMA",
102102
)
103103

104+
index_definition = Table(
105+
"IndexDefinition",
106+
ischema,
107+
Column("parent", String),
108+
Column("SqlName", String),
109+
Column("Data", String),
110+
schema="%Dictionary",
111+
)
112+
104113
key_constraints = Table(
105114
"KEY_COLUMN_USAGE",
106115
ischema,

0 commit comments

Comments
 (0)