def update_table_boost_score(data): """Batch update table boost scores""" # TODO: verify user is a service account with DBSession() as session: for d in data: verify_data_table_permission(d["table_id"], session=session) logic.update_table(id=d["table_id"], score=d["boost_score"], session=session) return
def update_table(table_id, description=None, golden=None): """Update a table""" with DBSession() as session: verify_data_table_permission(table_id, session=session) if description: logic.update_table_information(table_id, description=description, session=session) if golden is not None: api_assert(current_user.is_admin, "Golden table can only be updated by Admin") logic.update_table(table_id, golden=golden, session=session) return logic.get_table_by_id(table_id, session=session)
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
def exec_demo_set_up(): with DBSession() as session: environment = environment_logic.create_environment( name="demo_environment", description="Demo environment", image="", public=True, commit=False, session=session, ) local_db_conn = "sqlite:///demo/demo_data.db" metastore_id = QueryMetastore.create( { "name": "demo_metastore", "metastore_params": {"connection_string": local_db_conn,}, "loader": "SqlAlchemyMetastoreLoader", "acl_control": {}, }, commit=False, session=session, ).id engine_id = QueryEngine.create( { "name": "sqlite", "description": "SQLite Engine", "language": "sqlite", "executor": "sqlalchemy", "executor_params": {"connection_string": local_db_conn,}, "environment_id": environment.id, "metastore_id": metastore_id, }, commit=False, session=session, ).id logic.add_query_engine_to_environment( environment.id, engine_id, commit=False, session=session ) task_schedule_id = TaskSchedule.create( { "name": "update_metastore_{}".format(metastore_id), "task": "tasks.update_metastore.update_metastore", "cron": "0 0 * * *", "args": [metastore_id], "task_type": "prod", "enabled": True, }, # commit=False, session=session, ).id schedule_logic.run_and_log_scheduled_task( scheduled_task_id=task_schedule_id, wait_to_finish=True, session=session ) golden_table = metastore_logic.get_table_by_name( schema_name="main", name="world_happiness_2019", metastore_id=metastore_id, session=session, ) if golden_table: metastore_logic.update_table( id=golden_table.id, golden=True, session=session ) metastore_logic.update_table_information( data_table_id=golden_table.id, description="The World Happiness Report is a landmark survey of the state of global happiness. The first report was published in 2012, the second in 2013, the third in 2015, and the fourth in the 2016 Update. The World Happiness 2017, which ranks 155 countries by their happiness levels, was released at the United Nations at an event celebrating International Day of Happiness on March 20th. The report continues to gain global recognition as governments, organizations and civil society increasingly use happiness indicators to inform their policy-making decisions. Leading experts across fields – economics, psychology, survey analysis, national statistics, health, public policy and more – describe how measurements of well-being can be used effectively to assess the progress of nations. The reports review the state of happiness in the world today and show how the new science of happiness explains personal and national variations in happiness.", session=session, ) demo_logic.create_demo_table_stats( table_id=golden_table.id, uid=current_user.id, session=session ) score_column = metastore_logic.get_column_by_name( name="Score", table_id=golden_table.id, session=session ) demo_logic.create_demo_table_column_stats( column_id=score_column.id, uid=current_user.id, session=session ) schedule_logic.run_and_log_scheduled_task( scheduled_task_id=task_schedule_id, session=session ) demo_logic.create_demo_lineage(metastore_id, current_user.id, session=session) data_doc_id = demo_logic.create_demo_data_doc( environment_id=environment.id, engine_id=engine_id, uid=current_user.id, session=session, ) if data_doc_id: session.commit() return { "environment": environment.name, "data_doc_id": data_doc_id, }