|
11 | 11 | from sqlmesh.core.engine_adapter.shared import DataObject
|
12 | 12 | import sqlmesh.core.dialect as d
|
13 | 13 | from sqlmesh.core.model import SqlModel, load_sql_based_model
|
14 |
| -from sqlmesh.core.plan import Plan |
| 14 | +from sqlmesh.core.plan import Plan, BuiltInPlanEvaluator |
15 | 15 | from sqlmesh.core.table_diff import TableDiff
|
| 16 | +from sqlmesh.utils import CorrelationId |
16 | 17 | from tests.core.engine_adapter.integration import TestContext
|
17 | 18 | from pytest import FixtureRequest
|
18 | 19 | from tests.core.engine_adapter.integration import (
|
@@ -447,3 +448,33 @@ def test_materialized_view_evaluation(ctx: TestContext, engine_adapter: BigQuery
|
447 | 448 |
|
448 | 449 | df = engine_adapter.fetchdf(f"SELECT * FROM {mview_name.sql(dialect=ctx.dialect)}")
|
449 | 450 | assert df["col"][0] == 2
|
| 451 | + |
| 452 | + |
| 453 | +def test_correlation_id_in_job_labels(ctx: TestContext): |
| 454 | + model_name = ctx.table("test") |
| 455 | + |
| 456 | + sqlmesh = ctx.create_context() |
| 457 | + sqlmesh.upsert_model( |
| 458 | + load_sql_based_model(d.parse(f"MODEL (name {model_name}, kind FULL); SELECT 1 AS col")) |
| 459 | + ) |
| 460 | + |
| 461 | + # Create a plan evaluator and a plan to evaluate |
| 462 | + plan_evaluator = BuiltInPlanEvaluator( |
| 463 | + sqlmesh.state_sync, |
| 464 | + sqlmesh.snapshot_evaluator, |
| 465 | + sqlmesh.create_scheduler, |
| 466 | + sqlmesh.default_catalog, |
| 467 | + ) |
| 468 | + plan: Plan = sqlmesh.plan_builder("prod", skip_tests=True).build() |
| 469 | + |
| 470 | + # Evaluate the plan and retrieve the plan evaluator's adapter |
| 471 | + plan_evaluator.evaluate(plan.to_evaluatable()) |
| 472 | + adapter = t.cast(BigQueryEngineAdapter, plan_evaluator.snapshot_evaluator.adapter) |
| 473 | + |
| 474 | + # Case 1: Ensure that the correlation id is set in the underlying adapter |
| 475 | + assert adapter.correlation_id is not None |
| 476 | + |
| 477 | + # Case 2: Ensure that the correlation id is set in the job labels |
| 478 | + labels = adapter._job_params.get("labels") |
| 479 | + correlation_id = CorrelationId.from_plan_id(plan.plan_id) |
| 480 | + assert labels == {correlation_id.job_type.value.lower(): correlation_id.job_id} |
0 commit comments