def create_table_stats_by_name(metastore_name, data): """Batch add/update table 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: table = t_finder.get_table_by_name( schema_name=d["schema_name"], table_name=d["table_name"], session=session, ) if table is not None: for s in d["stats"]: logic.upsert_table_stat( table_id=table.id, key=s["key"], value=s["value"], uid=current_user.id, session=session, ) return
def create_demo_table_stats(table_id, uid, session=None): m_logic.upsert_table_stat( table_id=table_id, key="queries_count", value=37, uid=uid, session=session, ) m_logic.upsert_table_stat( table_id=table_id, key="successful_queries_count", value=37, uid=uid, session=session, ) m_logic.upsert_table_stat( table_id=table_id, key="users_count", value=18, uid=uid, session=session, ) m_logic.upsert_table_stat( table_id=table_id, key="join_queries_count", value=11, uid=uid, session=session, )
def create_table_stats(data): """Batch add/update table stats""" # TODO: verify user is a service account with DBSession() as session: for d in data: verify_data_table_permission(d["table_id"], session=session) for s in d["stats"]: logic.upsert_table_stat( table_id=d["table_id"], key=s["key"], value=s["value"], uid=current_user.id, session=session, ) return