|
| 1 | +from databricks.labs.ucx.assessment.jobs import JobInfo |
| 2 | +from databricks.labs.ucx.framework.utils import escape_sql_identifier |
| 3 | +from databricks.labs.ucx.source_code.base import DirectFsAccess, LineageAtom |
| 4 | +from databricks.labs.ucx.source_code.jobs import JobProblem |
| 5 | + |
| 6 | + |
| 7 | +def test_job_progress_encoder_failures(runtime_ctx, az_cli_ctx) -> None: |
| 8 | + az_cli_ctx.progress_tracking_installation.run() |
| 9 | + runtime_ctx = runtime_ctx.replace( |
| 10 | + parent_run_id=1, |
| 11 | + sql_backend=az_cli_ctx.sql_backend, |
| 12 | + ucx_catalog=az_cli_ctx.ucx_catalog, |
| 13 | + ) |
| 14 | + |
| 15 | + job = runtime_ctx.make_job() |
| 16 | + assert job.job_id, "Expected job with id" |
| 17 | + assert job.settings and job.settings.tasks, "Expected job with tasks" |
| 18 | + |
| 19 | + job_problems = [ |
| 20 | + JobProblem( |
| 21 | + job_id=job.job_id, |
| 22 | + job_name=job.settings.name, |
| 23 | + task_key=job.settings.tasks[0].task_key, |
| 24 | + path="parent/child.py", |
| 25 | + code="sql-parse-error", |
| 26 | + message="Could not parse SQL", |
| 27 | + start_line=12, |
| 28 | + start_col=0, |
| 29 | + end_line=12, |
| 30 | + end_col=20, |
| 31 | + ) |
| 32 | + ] |
| 33 | + runtime_ctx.sql_backend.save_table( |
| 34 | + f'{runtime_ctx.inventory_database}.workflow_problems', |
| 35 | + job_problems, |
| 36 | + JobProblem, |
| 37 | + mode='overwrite', |
| 38 | + ) |
| 39 | + |
| 40 | + dashboard = runtime_ctx.make_dashboard() |
| 41 | + |
| 42 | + direct_fs_access_for_path = DirectFsAccess( |
| 43 | + source_id="/path/to/write_dfsa.py", |
| 44 | + source_lineage=[ |
| 45 | + LineageAtom(object_type="WORKFLOW", object_id=str(job.job_id), other={"name": job.settings.name}), |
| 46 | + LineageAtom(object_type="TASK", object_id=job.settings.tasks[0].task_key), |
| 47 | + ], |
| 48 | + path="dfsa:/path/to/data/", |
| 49 | + is_read=False, |
| 50 | + is_write=True, |
| 51 | + ) |
| 52 | + runtime_ctx.directfs_access_crawler_for_paths.dump_all([direct_fs_access_for_path]) |
| 53 | + |
| 54 | + direct_fs_access_for_query = DirectFsAccess( |
| 55 | + source_id="/path/to/write_dfsa.py", |
| 56 | + source_lineage=[ |
| 57 | + LineageAtom( |
| 58 | + object_type="DASHBOARD", |
| 59 | + object_id=dashboard.id, |
| 60 | + other={"parent": dashboard.parent, "name": dashboard.name}, |
| 61 | + ), |
| 62 | + LineageAtom(object_type="QUERY", object_id=f"{dashboard.id}/query", other={"name": "test"}), |
| 63 | + ], |
| 64 | + path="dfsa:/path/to/data/", |
| 65 | + is_read=False, |
| 66 | + is_write=True, |
| 67 | + ) |
| 68 | + runtime_ctx.directfs_access_crawler_for_queries.dump_all([direct_fs_access_for_query]) |
| 69 | + |
| 70 | + job_info = JobInfo( |
| 71 | + str(job.job_id), |
| 72 | + success=1, |
| 73 | + failures="[]", |
| 74 | + job_name=job.settings.name, |
| 75 | + creator=job.creator_user_name, |
| 76 | + ) |
| 77 | + runtime_ctx.jobs_progress.append_inventory_snapshot([job_info]) |
| 78 | + |
| 79 | + history_table_name = escape_sql_identifier(runtime_ctx.tables_progress.full_name) |
| 80 | + records = list(runtime_ctx.sql_backend.fetch(f"SELECT * FROM {history_table_name}")) |
| 81 | + |
| 82 | + assert len(records) == 1, "Expected one historical entry" |
| 83 | + assert records[0].failures == [ |
| 84 | + f"sql-parse-error: {job.settings.tasks[0].task_key} task: parent/child.py: Could not parse SQL", |
| 85 | + f"direct-filesystem-access: {job.settings.tasks[0].task_key} task: /path/to/write_dfsa.py: The use of direct filesystem references is deprecated: dfsa:/path/to/data/", |
| 86 | + ] |
0 commit comments