@@ -154,12 +154,10 @@ def initialize(self, connection):
154154 sqlalchemy_version_string = matches [0 ][0 ]
155155 telemetry_query = "SELECT crdb_internal.increment_feature_counter(:val)"
156156 connection .execute (
157- text (telemetry_query ),
158- dict (val = f'sqlalchemy-cockroachdb { dialect_version } ' )
157+ text (telemetry_query ), dict (val = f"sqlalchemy-cockroachdb { dialect_version } " )
159158 )
160159 connection .execute (
161- text (telemetry_query ),
162- dict (val = f'sqlalchemy { sqlalchemy_version_string } ' )
160+ text (telemetry_query ), dict (val = f"sqlalchemy { sqlalchemy_version_string } " )
163161 )
164162
165163 def _get_server_version_info (self , conn ):
@@ -191,39 +189,40 @@ def has_table(self, conn, table, schema=None):
191189 # The upstream implementations of the reflection functions below depend on
192190 # correlated subqueries which are not yet supported.
193191 def get_columns (self , conn , table_name , schema = None , ** kw ):
192+ _include_hidden = kw .get ("include_hidden" , False )
194193 if not self ._is_v2plus :
195194 # v1.1.
196195 # Bad: the table name is not properly escaped.
197196 # Oh well. Hoping 1.1 won't be around for long.
198197 rows = conn .execute (
199- text (
200- f'SHOW COLUMNS FROM "{ schema or self .default_schema_name } "."{ table_name } "'
201- )
198+ text (f'SHOW COLUMNS FROM "{ schema or self .default_schema_name } "."{ table_name } "' )
202199 )
203200 elif not self ._is_v191plus :
204201 # v2.x does not have is_generated or generation_expression
202+ sql = (
203+ "SELECT column_name, data_type, is_nullable::bool, column_default, "
204+ "numeric_precision, numeric_scale, character_maximum_length, "
205+ "NULL AS is_generated, NULL AS generation_expression, is_hidden::bool "
206+ "FROM information_schema.columns "
207+ "WHERE table_schema = :table_schema AND table_name = :table_name "
208+ )
209+ sql += "" if _include_hidden else "AND NOT is_hidden::bool"
205210 rows = conn .execute (
206- text (
207- "SELECT column_name, data_type, is_nullable::bool, column_default, "
208- "numeric_precision, numeric_scale, character_maximum_length, "
209- "NULL AS is_generated, NULL AS generation_expression "
210- "FROM information_schema.columns "
211- "WHERE table_schema = :table_schema AND table_name = :table_name "
212- " AND NOT is_hidden::bool"
213- ),
211+ text (sql ),
214212 {"table_schema" : schema or self .default_schema_name , "table_name" : table_name },
215213 )
216214 else :
217215 # v19.1 or later. Information schema columns are all usable.
216+ sql = (
217+ "SELECT column_name, data_type, is_nullable::bool, column_default, "
218+ "numeric_precision, numeric_scale, character_maximum_length, "
219+ "is_generated::bool, generation_expression, is_hidden::bool "
220+ "FROM information_schema.columns "
221+ "WHERE table_schema = :table_schema AND table_name = :table_name "
222+ )
223+ sql += "" if _include_hidden else "AND NOT is_hidden::bool"
218224 rows = conn .execute (
219- text (
220- "SELECT column_name, data_type, is_nullable::bool, column_default, "
221- "numeric_precision, numeric_scale, character_maximum_length, "
222- "is_generated::bool, generation_expression "
223- "FROM information_schema.columns "
224- "WHERE table_schema = :table_schema AND table_name = :table_name "
225- " AND NOT is_hidden::bool"
226- ),
225+ text (sql ),
227226 {"table_schema" : schema or self .default_schema_name , "table_name" : table_name },
228227 )
229228
@@ -292,6 +291,7 @@ def get_columns(self, conn, table_name, schema=None, **kw):
292291 nullable = nullable ,
293292 default = default ,
294293 autoincrement = autoincrement ,
294+ is_hidden = row .is_hidden ,
295295 )
296296 if computed is not None :
297297 column_info ["computed" ] = computed
@@ -355,9 +355,7 @@ def get_foreign_keys_v1(self, conn, table_name, schema=None, **kw):
355355 FK_REGEX = re .compile (r"(?P<referred_table>.+)?\.\[(?P<referred_columns>.+)?]" )
356356
357357 for row in conn .execute (
358- text (
359- f'SHOW CONSTRAINTS FROM "{ schema or self .default_schema_name } "."{ table_name } "'
360- )
358+ text (f'SHOW CONSTRAINTS FROM "{ schema or self .default_schema_name } "."{ table_name } "' )
361359 ):
362360 if row .Type .startswith ("FOREIGN KEY" ):
363361 m = re .search (FK_REGEX , row .Details )
@@ -511,9 +509,7 @@ def get_pk_constraint(self, conn, table_name, schema=None, **kw):
511509
512510 def get_unique_constraints (self , conn , table_name , schema = None , ** kw ):
513511 if self ._is_v21plus :
514- return super ().get_unique_constraints (
515- conn , table_name , schema , ** kw
516- )
512+ return super ().get_unique_constraints (conn , table_name , schema , ** kw )
517513
518514 # v2.0 does not know about enough SQL to understand the query done by
519515 # the upstream dialect. So run a dumbed down version instead.
@@ -531,9 +527,7 @@ def get_unique_constraints(self, conn, table_name, schema=None, **kw):
531527
532528 def get_check_constraints (self , conn , table_name , schema = None , ** kw ):
533529 if self ._is_v21plus :
534- return super ().get_check_constraints (
535- conn , table_name , schema , ** kw
536- )
530+ return super ().get_check_constraints (conn , table_name , schema , ** kw )
537531 # TODO(bdarnell): The postgres dialect implementation depends on
538532 # pg_table_is_visible, which is supported in cockroachdb 1.1
539533 # but not in 1.0. Figure out a versioning strategy.
0 commit comments