Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Update data refresh to use media tables (#2818)

Staci Mullinscf5778a38383
diff --git a/catalog/DAGs.md b/catalog/DAGs.md
index fae2dcb72..2405915d0 100644
--- a/catalog/DAGs.md
+++ b/catalog/DAGs.md
@@ -202,24 +202,14 @@ airflow dags trigger --conf
### Data Refresh DAG Factory
This file generates our data refresh DAGs using a factory function. For the
-given media type these DAGs will first refresh the popularity data, then
-initiate a data refresh on the data refresh server and await the success or
-failure of that task.
-
-Popularity data for each media type is collated in a materialized view. Before
-initiating a data refresh, the DAG will first refresh the view in order to
-update popularity data for records that have been ingested since the last
-refresh. On the first run of the month, the DAG will also refresh the underlying
-tables, including the percentile values and any new popularity metrics. The DAG
-can also be run with the `force_refresh_metrics` option to run this refresh
-after the first of the month.
-
-Once this step is complete, the data refresh can be initiated. A data refresh
-occurs on the Ingestion server in the openverse project. This is a task which
-imports data from the upstream Catalog database into the API, copies contents to
-a new Elasticsearch index, and finally makes the index "live". This process is
-necessary to make new content added to the Catalog by our provider DAGs
-available to the API. You can read more in the
+given media type these DAGs will initiate a data refresh on the ingestion server
+and await the success or failure of that task.
+
+A data refresh occurs on the Ingestion server in the Openverse project. This is
+a task which imports data from the upstream Catalog database into the API,
+copies contents to a new Elasticsearch index, and finally makes the index
+"live". This process is necessary to make new content added to the Catalog by
+our provider DAGs available to the API. You can read more in the
[README](https://github.com/WordPress/openverse/blob/main/ingestion_server/README.md)
Importantly, the data refresh TaskGroup is also configured to handle concurrency
requirements of the Ingestion server. Finally, once the origin indexes have been
@@ -535,24 +525,14 @@ This script can be run either to ingest the full dataset or as a dated DAG.
### Data Refresh DAG Factory
This file generates our data refresh DAGs using a factory function. For the
-given media type these DAGs will first refresh the popularity data, then
-initiate a data refresh on the data refresh server and await the success or
-failure of that task.
-
-Popularity data for each media type is collated in a materialized view. Before
-initiating a data refresh, the DAG will first refresh the view in order to
-update popularity data for records that have been ingested since the last
-refresh. On the first run of the month, the DAG will also refresh the underlying
-tables, including the percentile values and any new popularity metrics. The DAG
-can also be run with the `force_refresh_metrics` option to run this refresh
-after the first of the month.
-
-Once this step is complete, the data refresh can be initiated. A data refresh
-occurs on the Ingestion server in the openverse project. This is a task which
-imports data from the upstream Catalog database into the API, copies contents to
-a new Elasticsearch index, and finally makes the index "live". This process is
-necessary to make new content added to the Catalog by our provider DAGs
-available to the API. You can read more in the
+given media type these DAGs will initiate a data refresh on the ingestion server
+and await the success or failure of that task.
+
+A data refresh occurs on the Ingestion server in the Openverse project. This is
+a task which imports data from the upstream Catalog database into the API,
+copies contents to a new Elasticsearch index, and finally makes the index
+"live". This process is necessary to make new content added to the Catalog by
+our provider DAGs available to the API. You can read more in the
[README](https://github.com/WordPress/openverse/blob/main/ingestion_server/README.md)
Importantly, the data refresh TaskGroup is also configured to handle concurrency
requirements of the Ingestion server. Finally, once the origin indexes have been
diff --git a/catalog/dags/data_refresh/dag_factory.py b/catalog/dags/data_refresh/dag_factory.py
index d03bb70df..c7e16fb81 100644
--- a/catalog/dags/data_refresh/dag_factory.py
+++ b/catalog/dags/data_refresh/dag_factory.py
@@ -1,20 +1,10 @@
"""
# Data Refresh DAG Factory
This file generates our data refresh DAGs using a factory function.
-For the given media type these DAGs will first refresh the popularity data,
-then initiate a data refresh on the data refresh server and await the
-success or failure of that task.
+For the given media type these DAGs will initiate a data refresh on the
+ingestion server and await the success or failure of that task.
-Popularity data for each media type is collated in a materialized view. Before
-initiating a data refresh, the DAG will first refresh the view in order to
-update popularity data for records that have been ingested since the last refresh.
-On the first run of the month, the DAG will also refresh the underlying tables,
-including the percentile values and any new popularity metrics. The DAG can also
-be run with the `force_refresh_metrics` option to run this refresh after the first
-of the month.
-
-Once this step is complete, the data refresh can be initiated. A data refresh
-occurs on the Ingestion server in the openverse project. This is a task
+A data refresh occurs on the Ingestion server in the Openverse project. This is a task
which imports data from the upstream Catalog database into the API, copies contents
to a new Elasticsearch index, and finally makes the index "live". This process is
necessary to make new content added to the Catalog by our provider DAGs available
@@ -36,19 +26,8 @@ import logging
from collections.abc import Sequence
from airflow import DAG
-from airflow.models.dagrun import DagRun
-from airflow.operators.python import BranchPythonOperator, PythonOperator
+from airflow.operators.python import PythonOperator
from airflow.operators.trigger_dagrun import TriggerDagRunOperator
-from airflow.settings import SASession
-from airflow.utils.session import provide_session
-from airflow.utils.state import State
-from popularity.refresh_popularity_metrics_task_factory import (
- GROUP_ID as REFRESH_POPULARITY_METRICS_GROUP_ID,
-)
-from popularity.refresh_popularity_metrics_task_factory import (
- UPDATE_MEDIA_POPULARITY_METRICS_TASK_ID,
- create_refresh_popularity_metrics_task_group,
-)
from common.constants import (
DAG_DEFAULT_ARGS,
@@ -58,26 +37,11 @@ from common.constants import (
from common.sql import PGExecuteQueryOperator
from data_refresh.data_refresh_task_factory import create_data_refresh_task_group
from data_refresh.data_refresh_types import DATA_REFRESH_CONFIGS, DataRefresh
-from data_refresh.recreate_view_data_task_factory import DROP_DB_VIEW_TASK_ID
-from data_refresh.recreate_view_data_task_factory import (
- GROUP_ID as RECREATE_MATVIEW_GROUP_ID,
-)
-from data_refresh.recreate_view_data_task_factory import create_recreate_view_data_task
-from data_refresh.reporting import report_record_difference, report_status
+from data_refresh.reporting import report_record_difference
logger = logging.getLogger(__name__)
-# The first task in the recreate_matview TaskGroup
-RECREATE_MATERIALIZED_VIEW_TASK_ID = (
- f"{RECREATE_MATVIEW_GROUP_ID}.{DROP_DB_VIEW_TASK_ID}"
-)
-# The first task in the refresh_popularity_metrics TaskGroup
-REFRESH_POPULARITY_METRICS_TASK_ID = (
- f"{REFRESH_POPULARITY_METRICS_GROUP_ID}"
- f".{UPDATE_MEDIA_POPULARITY_METRICS_TASK_ID}"
-)
-
def _single_value(cursor):
try:
@@ -87,85 +51,11 @@ def _single_value(cursor):
raise ValueError("Unable to extract expected row data from cursor") from e
-@provide_session
-def _month_check(dag_id: str, session: SASession = None) -> str:
- """
- Check whether there has been a previous DagRun this month.
-
- If so, return the task_id for the matview refresh task; else, return the
- task_id for refresh popularity metrics task.
-
- Required Arguments:
-
- dag_id: id of the currently running Dag
- """
- # Get the current DagRun
- DR = DagRun
- current_dagrun = (
- session.query(DR).filter(DR.dag_id == dag_id, DR.state == State.RUNNING)
- ).first()
-
- # If `force_refresh_metrics` has been passed in the dagrun config, then
- # immediately return the task_id to refresh popularity metrics without
- # doing the month check.
- force_refresh_metrics = current_dagrun.conf.get("force_refresh_metrics")
- if force_refresh_metrics is not None:
- logger.info(f"`force_refresh_metrics` is set to {force_refresh_metrics}.")
- return (
- REFRESH_POPULARITY_METRICS_TASK_ID
- if force_refresh_metrics
- else RECREATE_MATERIALIZED_VIEW_TASK_ID
- )
-
- # Get the most recent successful dagrun for this Dag
- latest_dagrun = (
- session.query(DR)
- .filter(DR.dag_id == dag_id, DR.state == State.SUCCESS)
- .order_by(DR.start_date.desc())
- ).first()
-
- # No previous successful dagrun, refresh all popularity data.
- if latest_dagrun is None:
- return REFRESH_POPULARITY_METRICS_TASK_ID
-
- # Check if the last dagrun was in the same month as the current run
- current_date = current_dagrun.start_date
- last_dagrun_date = latest_dagrun.start_date
- is_last_dagrun_in_current_month = (
- current_date.month == last_dagrun_date.month
- and current_date.year == last_dagrun_date.year
- )
-
- return (
- REFRESH_POPULARITY_METRICS_TASK_ID
- if not is_last_dagrun_in_current_month
- else RECREATE_MATERIALIZED_VIEW_TASK_ID
- )
-
-
-def _month_check_with_reporting(dag_id: str, media_type: str) -> str:
- """
- Wrap the monthly check function.
-
- This reports which step is starting and which step is next to slack.
- """
- next_task_id = _month_check(dag_id)
- next_step = {
- REFRESH_POPULARITY_METRICS_TASK_ID: "update popularity metrics",
- RECREATE_MATERIALIZED_VIEW_TASK_ID: "recreate matview",
- }.get(next_task_id, "unable to determine next step")
- message = f":horse_racing: Starting data refresh | _Next: {next_step}_"
- report_status(media_type, message, dag_id)
-
- return next_task_id
-
-
def create_data_refresh_dag(data_refresh: DataRefresh, external_dag_ids: Sequence[str]):
"""
Instantiate a DAG for a data refresh.
- This DAG will run the popularity calculation and subsequent data refresh for the
- given `media_type`.
+ This DAG will run the data refresh for the given `media_type`.
Required Arguments:
@@ -206,16 +96,6 @@ def create_data_refresh_dag(data_refresh: DataRefresh, external_dag_ids: Sequenc
AND n.nspname = 'public';
"""
- # Check if this is the first DagRun of the month for this DAG.
- month_check = BranchPythonOperator(
- task_id="month_check",
- python_callable=_month_check_with_reporting,
- op_kwargs={
- "dag_id": data_refresh.dag_id,
- "media_type": data_refresh.media_type,
- },
- )
-
# Get the current number of records in the target API table
before_record_count = PGExecuteQueryOperator(
task_id="get_before_record_count",
@@ -225,19 +105,7 @@ def create_data_refresh_dag(data_refresh: DataRefresh, external_dag_ids: Sequenc
return_last=True,
)
- # Refresh underlying popularity tables. This is required infrequently in order
- # to update new popularity metrics and constants, so this branch is only taken
- # if it is the first run of the month (or when forced).
- refresh_popularity_metrics = create_refresh_popularity_metrics_task_group(
- data_refresh
- )
-
- # Drop and recreate the materialized view. This occurs on all DagRuns and
- # updates popularity data for newly ingested records. Formerly, we would refresh
- # the materialized view, but that process would consistently time out.
- recreate_matview = create_recreate_view_data_task(data_refresh)
-
- # Trigger the actual data refresh on the remote data refresh server, and wait
+ # Trigger the data refresh on the remote ingestion server, and wait
# for it to complete.
data_refresh_group = create_data_refresh_task_group(
data_refresh, external_dag_ids
@@ -288,9 +156,7 @@ def create_data_refresh_dag(data_refresh: DataRefresh, external_dag_ids: Sequenc
)
# Set up task dependencies
- month_check >> [refresh_popularity_metrics, recreate_matview]
before_record_count >> data_refresh_group
- refresh_popularity_metrics >> recreate_matview >> data_refresh_group
data_refresh_group >> after_record_count >> report_counts
data_refresh_group >> trigger_filtered_index_creation
diff --git a/catalog/tests/dags/data_refresh/test_dag_factory.py b/catalog/tests/dags/data_refresh/test_dag_factory.py
deleted file mode 100644
index 6a299fa78..000000000
--- a/catalog/tests/dags/data_refresh/test_dag_factory.py
+++ /dev/null
@@ -1,145 +0,0 @@
-from unittest import mock
-
-import pytest
-from airflow.models import DagRun
-from airflow.models.dag import DAG
-from airflow.utils.session import create_session
-from airflow.utils.state import State
-from airflow.utils.timezone import datetime
-from airflow.utils.types import DagRunType
-
-from data_refresh import dag_factory
-from data_refresh.dag_factory import (
- RECREATE_MATERIALIZED_VIEW_TASK_ID,
- REFRESH_POPULARITY_METRICS_TASK_ID,
-)
-
-
-TEST_DAG_ID = "data_refresh_dag_factory_test_dag"
-TEST_DAG = DAG(TEST_DAG_ID, default_args={"owner": "airflow"})
-
-
[email protected](autouse=True)
-def clean_db():
- with create_session() as session:
- session.query(DagRun).filter(DagRun.dag_id == TEST_DAG_ID).delete()
-
-
-def _create_dagrun(start_date, dag_state, conf={}):
- return TEST_DAG.create_dagrun(
- start_date=start_date,
- execution_date=start_date,
- data_interval=(start_date, start_date),
- state=dag_state,
- run_type=DagRunType.MANUAL,
- conf=conf,
- )
-
-
- "force_refresh_metrics, last_dagrun_date, today_date, expected_task_id",
- [
- # Last dagrun was in the same month
- (
- None,
- datetime(2022, 3, 1, 0, 0, 0),
- datetime(2022, 3, 2, 0, 0, 0),
- RECREATE_MATERIALIZED_VIEW_TASK_ID,
- ),
- # Last dagrun was in the same month, different year
- (
- None,
- datetime(2021, 3, 1, 0, 0, 0),
- datetime(2022, 3, 2, 0, 0, 0),
- REFRESH_POPULARITY_METRICS_TASK_ID,
- ),
- # Last dagrun was in a previous month
- (
- None,
- datetime(2022, 2, 1, 0, 0, 0),
- datetime(2022, 3, 2, 0, 0, 0),
- REFRESH_POPULARITY_METRICS_TASK_ID,
- ),
- # `force_refresh_metrics` is turned on
- # Last dagrun was in the same month
- (
- True,
- datetime(2022, 3, 1, 0, 0, 0),
- datetime(2022, 3, 2, 0, 0, 0),
- REFRESH_POPULARITY_METRICS_TASK_ID,
- ),
- # Last dagrun was in a previous month
- (
- True,
- datetime(2022, 2, 1, 0, 0, 0),
- datetime(2022, 3, 2, 0, 0, 0),
- REFRESH_POPULARITY_METRICS_TASK_ID,
- ),
- # `force_refresh_metrics` is explicitly false
- # Last dagrun was in the same month
- (
- False,
- datetime(2022, 3, 1, 0, 0, 0),
- datetime(2022, 3, 2, 0, 0, 0),
- RECREATE_MATERIALIZED_VIEW_TASK_ID,
- ),
- # Last dagrun was in a previous month
- (
- False,
- datetime(2022, 2, 1, 0, 0, 0),
- datetime(2022, 3, 2, 0, 0, 0),
- RECREATE_MATERIALIZED_VIEW_TASK_ID,
- ),
- ],
-)
-def test_month_check_returns_correct_task_id(
- force_refresh_metrics, last_dagrun_date, today_date, expected_task_id
-):
- # Create latest dagrun
- _create_dagrun(last_dagrun_date, State.SUCCESS)
- # Create current dagrun
- _create_dagrun(
- today_date, State.RUNNING, {"force_refresh_metrics": force_refresh_metrics}
- )
-
- next_task_id = dag_factory._month_check(TEST_DAG.dag_id)
- assert next_task_id == expected_task_id
-
-
-def test_month_check_ignores_failed_dagruns():
- # Create running dagrun
- _create_dagrun(datetime(2022, 3, 2, 0, 0, 0), State.RUNNING)
-
- # Create previous dagrun in same month, but with failed state
- _create_dagrun(datetime(2022, 3, 1, 0, 0, 0), State.FAILED)
-
- # Create successful dagrun in previous month
- _create_dagrun(datetime(2022, 2, 1, 0, 0, 0), State.SUCCESS)
-
- # Even though there was a previous run this month, it failed. The last
- # successful run was last month, so we should refresh metrics.
- next_task_id = dag_factory._month_check(TEST_DAG.dag_id)
- assert next_task_id == REFRESH_POPULARITY_METRICS_TASK_ID
-
-
- "task_id, expected_message",
- [
- (REFRESH_POPULARITY_METRICS_TASK_ID, "update popularity metrics"),
- (RECREATE_MATERIALIZED_VIEW_TASK_ID, "recreate matview"),
- ("Some other task ID", "unable to determine next step"),
- ],
-)
-def test_month_check_with_reporting(task_id, expected_message):
- with (
- mock.patch("data_refresh.dag_factory._month_check") as mock_monthly_check,
- mock.patch("data_refresh.dag_factory.report_status") as mock_report_status,
- ):
- mock_monthly_check.return_value = task_id
- actual_task_id = dag_factory._month_check_with_reporting(
- dag_id="fake_dag", media_type="image"
- )
- message = mock_report_status.call_args.args[1]
- # Task ID returned from wrapper should be the same
- assert actual_task_id == task_id
- assert expected_message in message
diff --git a/ingestion_server/ingestion_server/ingest.py b/ingestion_server/ingestion_server/ingest.py
index b4b2ffc30..f491f5ace 100644
--- a/ingestion_server/ingestion_server/ingest.py
+++ b/ingestion_server/ingestion_server/ingest.py
@@ -55,24 +55,24 @@ RELATIVE_UPSTREAM_DB_PORT = config(
#: the port of the upstream DB from the POV of the downstream DB
-def _get_shared_cols(downstream, upstream, table: str):
+def _get_shared_cols(downstream, upstream, upstream_table: str, downstream_table: str):
"""
Get the common columns between two tables with the same name in different DBs.
Given two database connections and a table name, return the list of columns
- that the two tables have in common. The upstream table has the "_view"
- suffix attached to it.
+ that the two tables have in common.
:param downstream: an open connection to the downstream PostgreSQL database
:param upstream: an open connection to the upstream PostgreSQL database
- :param table: the name of the downstream table
+ :param upstream_table: the name of the table in the upstream db
+ :param downstream_table: the name of the table in the downstream db
:return: a list of the column names that are common to both databases
"""
with downstream.cursor() as cur1, upstream.cursor() as cur2:
get_tables = SQL("SELECT * FROM {table} LIMIT 0;")
- cur1.execute(get_tables.format(table=Identifier(table)))
+ cur1.execute(get_tables.format(table=Identifier(downstream_table)))
conn1_cols = {desc[0] for desc in cur1.description}
- cur2.execute(get_tables.format(table=Identifier(f"{table}_view")))
+ cur2.execute(get_tables.format(table=Identifier(upstream_table)))
conn2_cols = {desc[0] for desc in cur2.description}
shared = list(conn1_cols.intersection(conn2_cols))
@@ -251,7 +251,8 @@ def _update_progress(progress, new_value):
def refresh_api_table(
- table: str,
+ upstream_table: str,
+ downstream_table: str,
progress: multiprocessing.Value = None,
approach: ApproachType = "advanced",
):
@@ -268,14 +269,15 @@ def refresh_api_table(
This is the main function of this module.
- :param table: The upstream table to copy.
+ :param upstream_table: The upstream table to copy.
+ :param downstream_table: The name of the copied table in the downstream db.
:param progress: multiprocessing.Value float for sharing task progress
:param approach: whether to use advanced logic specific to media ingestion
"""
# Step 1: Get the list of overlapping columns
slack.status(
- table,
+ upstream_table,
"Starting ingestion server data refresh | _Next: copying data from upstream_",
)
downstream_db = database_connect()
@@ -287,7 +289,9 @@ def refresh_api_table(
host=UPSTREAM_DB_HOST,
connect_timeout=5,
)
- shared_cols = _get_shared_cols(downstream_db, upstream_db, table)
+ shared_cols = _get_shared_cols(
+ downstream_db, upstream_db, upstream_table, downstream_table
+ )
upstream_db.close()
with downstream_db, downstream_db.cursor() as downstream_cur:
@@ -307,7 +311,7 @@ def refresh_api_table(
UPSTREAM_DB_NAME,
UPSTREAM_DB_USER,
UPSTREAM_DB_PASSWORD,
- f"{table}_view",
+ upstream_table,
)
downstream_cur.execute(init_fdw)
@@ -320,23 +324,33 @@ def refresh_api_table(
limit_default = 0
limit = config("DATA_REFRESH_LIMIT", cast=int, default=limit_default)
copy_data = get_copy_data_query(
- table, shared_cols, approach=approach, limit=limit
+ upstream_table,
+ downstream_table,
+ shared_cols,
+ approach=approach,
+ limit=limit,
)
log.info(f"Running copy-data query: \n{copy_data.as_string(downstream_cur)}")
downstream_cur.execute(copy_data)
- next_step = "image data cleaning" if table == "image" else "Elasticsearch reindex"
- slack.status(table, f"Data copy complete | _Next: {next_step}_")
+ next_step = (
+ "image data cleaning"
+ if downstream_table == "image"
+ else "Elasticsearch reindex"
+ )
+ slack.status(upstream_table, f"Data copy complete | _Next: {next_step}_")
- if table == "image":
+ if downstream_table == "image":
# Step 5: Clean the data
log.info("Cleaning data...")
- clean_image_data(table)
+ clean_image_data(downstream_table)
log.info("Cleaning completed!")
- slack.status(table, "Data cleaning complete | _Next: Elasticsearch reindex_")
+ slack.status(
+ downstream_table, "Data cleaning complete | _Next: Elasticsearch reindex_"
+ )
downstream_db.close()
- log.info(f"Finished refreshing table '{table}'.")
+ log.info(f"Finished refreshing table '{downstream_table}'.")
_update_progress(progress, 100.0)
diff --git a/ingestion_server/ingestion_server/queries.py b/ingestion_server/ingestion_server/queries.py
index 54f14f846..aecc25406 100644
--- a/ingestion_server/ingestion_server/queries.py
+++ b/ingestion_server/ingestion_server/queries.py
@@ -92,7 +92,8 @@ def get_fdw_query(
def get_copy_data_query(
- table: str,
+ upstream_table: str,
+ downstream_table: str,
columns: list[str],
approach: ApproachType,
limit: int | None = 100_000,
@@ -109,7 +110,8 @@ def get_copy_data_query(
by `identifier` to simulate a random sample and only the first 100k records
will be pulled from the upstream database.
- :param table: the name of the downstream table being replaced
+ :param upstream_table: the name of the upstream table being copied
+ :param downstream_table: the name of the downstream table being replaced
:param columns: the names of the columns to copy from upstream
:param approach: whether to use advanced logic specific to media ingestion
:param limit: number of rows to copy when
@@ -119,7 +121,8 @@ def get_copy_data_query(
table_creation = d(
"""
DROP TABLE IF EXISTS {temp_table};
- CREATE TABLE {temp_table} (LIKE {table} INCLUDING DEFAULTS INCLUDING CONSTRAINTS);
+ CREATE TABLE {temp_table} (LIKE {downstream_table} INCLUDING DEFAULTS
+ INCLUDING CONSTRAINTS);
"""
)
@@ -180,7 +183,7 @@ def get_copy_data_query(
# If a limit is requested, add the condition onto the select at the very end
if limit:
# The audioset view does not have identifiers associated with it
- if table != "audioset":
+ if upstream_table != "audioset_view":
select_insert += d(
"""
ORDER BY identifier"""
@@ -201,10 +204,10 @@ def get_copy_data_query(
]
return SQL("".join(steps)).format(
- table=Identifier(table),
- temp_table=Identifier(f"temp_import_{table}"),
- upstream_table=Identifier("upstream_schema", f"{table}_view"),
- deleted_table=Identifier(f"api_deleted{table}"),
+ downstream_table=Identifier(downstream_table),
+ temp_table=Identifier(f"temp_import_{downstream_table}"),
+ upstream_table=Identifier("upstream_schema", upstream_table),
+ deleted_table=Identifier(f"api_deleted{downstream_table}"),
columns=SQL(",").join([Identifier(col) for col in columns]),
limit=PgLiteral(limit),
)
diff --git a/ingestion_server/ingestion_server/tasks.py b/ingestion_server/ingestion_server/tasks.py
index 10e7cd53b..f75396fec 100644
--- a/ingestion_server/ingestion_server/tasks.py
+++ b/ingestion_server/ingestion_server/tasks.py
@@ -238,9 +238,10 @@ def perform_task(
# These functions must have a signature of ``Callable[[], None]``.
def ingest_upstream(): # includes ``reindex``
- refresh_api_table(model, progress)
+ refresh_api_table(model, model, progress)
+ # For audio, also refresh the audioset view
if model == "audio":
- refresh_api_table("audioset", progress, approach="basic")
+ refresh_api_table("audioset_view", "audioset", progress, approach="basic")
indexer.reindex(model, f"temp_import_{model}", **kwargs)
def promote(): # includes point alias
diff --git a/ingestion_server/test/unit_tests/test_queries.py b/ingestion_server/test/unit_tests/test_queries.py
index 606a68749..768c5037c 100644
--- a/ingestion_server/test/unit_tests/test_queries.py
+++ b/ingestion_server/test/unit_tests/test_queries.py
@@ -13,10 +13,10 @@ def _join_seq(seq):
@pytest.mark.parametrize(
- "table, order_by_expected",
+ "upstream_table, downstream_table, order_by_expected",
[
- ("sample_table", True),
- ("audioset", False),
+ ("sample_table", "sample_table", True),
+ ("audioset_view", "audioset", False),
],
)
@pytest.mark.parametrize(
@@ -28,8 +28,12 @@ def _join_seq(seq):
("advanced", "100000", True),
],
)
-def test_get_copy_data_query(table, approach, limit, limit_expected, order_by_expected):
- actual = queries.get_copy_data_query(table, ["col1", "col2"], approach, limit)
+def test_get_copy_data_query(
+ upstream_table, downstream_table, approach, limit, limit_expected, order_by_expected
+):
+ actual = queries.get_copy_data_query(
+ upstream_table, downstream_table, ["col1", "col2"], approach, limit
+ )
as_string = _join_seq(actual.seq).replace("\\n", "\n").strip()
assert ("LIMIT 100000" in as_string) == limit_expected
assert ("ORDER BY identifier" in as_string) == (