def get_all_datasource_names( cls, database: "Database", datasource_type: str) -> List[utils.DatasourceName]: schemas = database.get_all_schema_names( cache=database.schema_cache_enabled, cache_timeout=database.schema_cache_timeout, force=True, ) schema = schemas[0] if datasource_type == "table": return [ utils.DatasourceName(*datasource_name) for datasource_name in database.get_all_table_names_in_schema( schema=schema, force=True, cache=database.table_cache_enabled, cache_timeout=database.table_cache_timeout, ) ] if datasource_type == "view": return [ utils.DatasourceName(*datasource_name) for datasource_name in database.get_all_view_names_in_schema( schema=schema, force=True, cache=database.table_cache_enabled, cache_timeout=database.table_cache_timeout, ) ] raise Exception(f"Unsupported datasource_type: {datasource_type}")
def get_all_view_names_in_schema( self, schema: str, cache: bool = False, cache_timeout: int = None, force: bool = False, ) -> List[utils.DatasourceName]: """Parameters need to be passed as keyword arguments. For unused parameters, they are referenced in cache_util.memoized_func decorator. :param schema: schema name :param cache: whether cache is enabled for the function :param cache_timeout: timeout in seconds for the cache :param force: whether to force refresh the cache :return: list of views """ try: views = self.db_engine_spec.get_view_names( database=self, inspector=self.inspector, schema=schema) return [ utils.DatasourceName(table=view, schema=schema) for view in views ] except Exception as e: # pylint: disable=broad-except logger.exception(e)
def get_all_table_names_in_schema( self, schema: str, cache: bool = False, cache_timeout: int = None, force: bool = False, ): """Parameters need to be passed as keyword arguments. For unused parameters, they are referenced in cache_util.memoized_func decorator. :param schema: schema name :param cache: whether cache is enabled for the function :param cache_timeout: timeout in seconds for the cache :param force: whether to force refresh the cache :return: list of tables """ try: tables = self.db_engine_spec.get_table_names( inspector=self.inspector, schema=schema ) return [ utils.DatasourceName(table=table, schema=schema) for table in tables ] except Exception as e: logging.exception(e)
def get_all_datasource_names(cls, db, datasource_type: str) \ -> List[utils.DatasourceName]: datasource_df = db.get_df( 'SELECT table_schema, table_name FROM INFORMATION_SCHEMA.{}S ' "ORDER BY concat(table_schema, '.', table_name)".format( datasource_type.upper(), ), None) datasource_names: List[utils.DatasourceName] = [] for unused, row in datasource_df.iterrows(): datasource_names.append( utils.DatasourceName(schema=row['table_schema'], table=row['table_name'])) return datasource_names
def get_all_datasource_names( cls, database, datasource_type: str) -> List[utils.DatasourceName]: datasource_df = database.get_df( "SELECT table_schema, table_name FROM INFORMATION_SCHEMA.{}S " "ORDER BY concat(table_schema, '.', table_name)".format( datasource_type.upper()), None, ) datasource_names: List[utils.DatasourceName] = [] for _unused, row in datasource_df.iterrows(): datasource_names.append( utils.DatasourceName(schema=row["table_schema"], table=row["table_name"])) return datasource_names