def create_table_column_stats_by_name(metastore_name, data): """Batch add/update table column stats""" # TODO: verify user is a service account with DBSession() as session: metastore = admin_logic.get_query_metastore_by_name(metastore_name, session=session) api_assert(metastore, "Invalid metastore") verify_metastore_permission(metastore.id, session=session) with DataTableFinder(metastore.id) as t_finder: for d in data: column = t_finder.get_table_column_by_name( schema_name=d["schema_name"], table_name=d["table_name"], column_name=d["column_name"], session=session, ) if column is not None: for s in d["stats"]: logic.upsert_table_column_stat( column_id=column.id, key=s["key"], value=s["value"], uid=current_user.id, session=session, ) return
def get_if_schema_and_table_exists(metastore_id, schema_name, table_name) -> Tuple[bool, bool]: """ Check if the table name / schema name exists in cache, then check the actual metastore if they don't exist Returns [schema_exists, table_exists] """ verify_metastore_permission(metastore_id) with DataTableFinder(metastore_id) as t_finder: table_exists_in_cache = t_finder.get_table_by_name( schema_name, table_name) if table_exists_in_cache: return [True, True] metastore_loader = get_metastore_loader(metastore_id) table_exists = metastore_loader.check_if_table_exists( schema_name, table_name) if table_exists: return [True, True] schema_exists_in_cache = t_finder.get_schema_by_name(schema_name) if schema_exists_in_cache: return [True, False] schema_exists = metastore_loader.check_if_schema_exists(schema_name) if schema_exists: return [True, False] return [False, False]
def upsert_table_boost_score_by_name(metastore_name, data): # TODO: verify user is a service account with DBSession() as session: metastore = admin_logic.get_query_metastore_by_name(metastore_name, session=session) api_assert(metastore, "Invalid metastore") verify_metastore_permission(metastore.id, session=session) with DataTableFinder(metastore.id) as t_finder: for d in data: table = t_finder.get_table_by_name( schema_name=d["schema_name"], table_name=d["table_name"], session=session, ) if table is not None: logic.update_table(id=table.id, score=d["boost_score"], session=session) return