Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of an Ownership factory #3072

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ericvergnaud
Copy link
Contributor

Changes

Every asset has an owner and our implementation requires that the owner be retrieved using a specialized Ownership instance.
There is also a requirement that such Ownership be retrieved from the GlobalContext, which in complex scenarios may result in a proliferation of constructor parameters.
This PR implements an Ownership factory that makes it easy to retrieve the appropriate xxxOwnership from the GlobalContext, simply using the Record type being considered.

Linked issues

Progresses #1415

Functionality

None

Tests

  • added unit tests

@ericvergnaud ericvergnaud changed the title Implementation an Ownership factory Implementation of an Ownership factory Oct 24, 2024
Copy link

github-actions bot commented Oct 24, 2024

❌ 120/128 passed, 2 flaky, 8 failed, 8 skipped, 3h56m29s total

❌ test_migrate_view: AssertionError: assert 3 == 4 (3m29.337s)
... (skipped 27486 bytes)
FOUND] The table or view `hive_metastore`.`dummy_syjqz`.`groups` cannot be found. Verify the spelling and correctness of the schema and catalog.
If you did not qualify the name with a schema, verify the current_schema() output, or qualify the name with the correct schema and catalog.
To tolerate the error on drop use DROP VIEW IF EXISTS or DROP TABLE IF EXISTS. SQLSTATE: 42P01; line 1 pos 14
18:01 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.groups] crawling new set of snapshot data for groups
18:01 INFO [databricks.labs.ucx.workspace_access.groups] Listing workspace groups (resource_type=WorkspaceGroup) with id,displayName,meta,externalId,members,roles,entitlements ...
18:01 INFO [databricks.labs.ucx.workspace_access.groups] Found 3 WorkspaceGroup
18:01 INFO [databricks.labs.ucx.workspace_access.groups] Listing account groups with id,displayName,externalId...
18:01 INFO [databricks.labs.ucx.workspace_access.groups] Found 70 account groups
18:01 INFO [databricks.labs.ucx.workspace_access.groups] No group listing provided, all matching groups will be migrated
18:01 INFO [databricks.labs.ucx.workspace_access.groups] Couldn't find a matching account group for sdk-1YIp-ra78a579b7 group using name matching
18:01 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.groups] found 2 new records for groups
18:01 DEBUG [databricks.labs.ucx.hive_metastore.grants] Migrating acls on dummy_ciick.dummy_sguoo.dummy_taync using SQL query: GRANT ALL PRIVILEGES ON TABLE `dummy_ciick`.`dummy_sguoo`.`dummy_taync` TO `[email protected]`
18:01 DEBUG [databricks.labs.ucx.hive_metastore.grants] Migrating acls on dummy_ciick.dummy_sguoo.dummy_taync using SQL query: ALTER TABLE `dummy_ciick`.`dummy_sguoo`.`dummy_taync` OWNER TO `0a330eb5-dd51-4d97-b6e4-c474356b1d5d`
18:01 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] fetching migration_status inventory
18:02 WARNING [databricks.labs.ucx.hive_metastore.table_migration_status] Catalog ucx_y93bugxskzo3c2ky no longer exists. Skipping checking its migration status.
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.tables] fetching tables inventory
18:02 INFO [databricks.labs.ucx.hive_metastore.mapping] The intended target for hive_metastore.dummy_sguoo.dummy_taync, dummy_ciick.dummy_sguoo.dummy_taync, already exists.
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] ignoring any existing migration_status inventory; refresh is forced.
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] crawling new set of snapshot data for migration_status
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.tables] fetching tables inventory
18:02 INFO [databricks.labs.ucx.hive_metastore.table_migration_status] dummy_sguoo.dummy_taync is set as migrated
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] found 4 new records for migration_status
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] fetching migration_status inventory
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] fetching migration_status inventory
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] fetching migration_status inventory
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] fetching migration_status inventory
18:02 DEBUG [databricks.labs.ucx.hive_metastore.table_migrate] Migrating view hive_metastore.dummy_sguoo.dummy_t8qin to using SQL query: CREATE VIEW IF NOT EXISTS `dummy_ciick`.`dummy_sguoo`.`dummy_t8qin` (`id`, `value`) WITH SCHEMA COMPENSATION TBLPROPERTIES ('RemoveAfter'='2024110519', 'transient_lastDdlTime'='1730829577') AS SELECT * FROM `dummy_ciick`.`dummy_sguoo`.`dummy_taync`
18:02 DEBUG [databricks.labs.ucx.hive_metastore.table_migrate] Migrating view hive_metastore.dummy_sguoo.view3 to using SQL query: CREATE VIEW IF NOT EXISTS `dummy_ciick`.`dummy_sguoo`.`view3` (`col1`, `col2`) WITH SCHEMA COMPENSATION TBLPROPERTIES ('transient_lastDdlTime'='1730829580') AS SELECT * FROM `dummy_ciick`.`dummy_sguoo`.`dummy_taync`
18:02 WARNING [databricks.labs.ucx.hive_metastore.table_migrate] Failed to migrate view hive_metastore.dummy_sguoo.dummy_t8qin to dummy_ciick.dummy_sguoo.dummy_t8qin: [UC_COMMAND_NOT_SUPPORTED.WITH_RECOMMENDATION] The command(s): 3-layer (catalogName.schemaName.tableName) table name notation: dummy_ciick.dummy_sguoo.dummy_taync for view creation in HMS federation are not supported in Unity Catalog. Please use schemaName.tableName or tableName instead. SQLSTATE: 0AKUC
18:02 WARNING [databricks.labs.ucx.hive_metastore.table_migrate] Failed to migrate view hive_metastore.dummy_sguoo.view3 to dummy_ciick.dummy_sguoo.view3: [UC_COMMAND_NOT_SUPPORTED.WITH_RECOMMENDATION] The command(s): 3-layer (catalogName.schemaName.tableName) table name notation: dummy_ciick.dummy_sguoo.dummy_taync for view creation in HMS federation are not supported in Unity Catalog. Please use schemaName.tableName or tableName instead. SQLSTATE: 0AKUC
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] ignoring any existing migration_status inventory; refresh is forced.
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] crawling new set of snapshot data for migration_status
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.tables] fetching tables inventory
18:02 WARNING [databricks.labs.ucx.hive_metastore.table_migration_status] Catalog dummy_czeqt no longer exists. Skipping checking its migration status.
18:02 WARNING [databricks.labs.ucx.hive_metastore.table_migration_status] Catalog ucx_ofmrfsnskj3zcgqv no longer exists. Skipping checking its migration status.
18:02 INFO [databricks.labs.ucx.hive_metastore.table_migration_status] dummy_sguoo.dummy_taync is set as migrated
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] found 4 new records for migration_status
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] fetching migration_status inventory
18:02 INFO [databricks.labs.ucx.hive_metastore.table_migrate] View hive_metastore.dummy_sguoo.dummy_tztii cannot be migrated because hive_metastore.dummy_sguoo.dummy_t8qin is not migrated yet
18:02 INFO [databricks.labs.ucx.hive_metastore.table_migrate] View hive_metastore.dummy_sguoo.dummy_tztii is not supported for migration
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] ignoring any existing migration_status inventory; refresh is forced.
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] crawling new set of snapshot data for migration_status
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.tables] fetching tables inventory
18:02 INFO [databricks.labs.ucx.hive_metastore.table_migration_status] dummy_sguoo.dummy_taync is set as migrated
18:02 DEBUG [databricks.labs.ucx.framework.crawlers] [hive_metastore.dummy_syjqz.migration_status] found 4 new records for migration_status
[gw1] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
❌ test_move_views: databricks.sdk.errors.platform.BadRequest: [UC_COMMAND_NOT_SUPPORTED.WITH_RECOMMENDATION] The command(s): 3-layer (catalogName.schemaName.tableName) table name notation: dummy_cr7oi.dummy_sded4.dummy_t0ygh for view creation in HMS federation are not supported in Unity Catalog. Please use schemaName.tableName or tableName instead. SQLSTATE: 0AKUC (7.49s)
databricks.sdk.errors.platform.BadRequest: [UC_COMMAND_NOT_SUPPORTED.WITH_RECOMMENDATION] The command(s): 3-layer (catalogName.schemaName.tableName) table name notation: dummy_cr7oi.dummy_sded4.dummy_t0ygh for view creation in HMS federation are not supported in Unity Catalog. Please use schemaName.tableName or tableName instead. SQLSTATE: 0AKUC
[gw9] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
[gw9] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
❌ test_alias_tables: databricks.sdk.errors.platform.BadRequest: [UC_COMMAND_NOT_SUPPORTED.WITH_RECOMMENDATION] The command(s): 3-layer (catalogName.schemaName.tableName) table name notation: dummy_c8nof.dummy_svmkt.dummy_t1w3j for view creation in HMS federation are not supported in Unity Catalog. Please use schemaName.tableName or tableName instead. SQLSTATE: 0AKUC (17.126s)
databricks.sdk.errors.platform.BadRequest: [UC_COMMAND_NOT_SUPPORTED.WITH_RECOMMENDATION] The command(s): 3-layer (catalogName.schemaName.tableName) table name notation: dummy_c8nof.dummy_svmkt.dummy_t1w3j for view creation in HMS federation are not supported in Unity Catalog. Please use schemaName.tableName or tableName instead. SQLSTATE: 0AKUC
[gw9] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
[gw9] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
❌ test_table_migration_job_refreshes_migration_status[regular-migrate-tables]: AssertionError: No destination schema found for TableType.VIEW hive_metastore.migrate_tg8j1.dummy_tflv9 (8m13.55s)
... (skipped 7380 bytes)
of questions to configure Unity Catalog migration
18:10 INFO [databricks.labs.ucx.installer.hms_lineage] HMS Lineage feature creates one system table named system.hms_to_uc_migration.table_access and helps in your migration process from HMS to UC by allowing you to programmatically query HMS lineage data.
18:10 INFO [databricks.labs.ucx.install] Fetching installations...
18:10 WARNING [databricks.labs.ucx.install] Existing installation at /Users/0a330eb5-dd51-4d97-b6e4-c474356b1d5d/.4JrC is corrupted. Skipping...
18:10 INFO [databricks.labs.ucx.installer.policy] Creating UCX cluster policy.
18:10 DEBUG [tests.integration.conftest] Waiting for clusters to start...
18:10 DEBUG [tests.integration.conftest] Waiting for clusters to start...
18:10 INFO [databricks.labs.ucx.install] Installing UCX v0.48.1+1520241105181059
18:10 INFO [databricks.labs.ucx.install] Creating ucx schemas...
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=failing
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migration-progress-experimental
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-groups
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-groups-experimental
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=remove-workspace-local-backup-groups
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-tables-in-mounts-experimental
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-data-reconciliation
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=scan-tables-in-mounts-experimental
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-external-tables-ctas
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=assessment
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=validate-groups-permissions
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-tables
18:11 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-external-hiveserde-tables-in-place-experimental
18:11 INFO [databricks.labs.ucx.install] Creating dashboards...
18:11 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/views...
18:11 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment...
18:11 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration...
18:11 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/progress...
18:11 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/interactive...
18:11 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/estimates...
18:11 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/main...
18:11 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/CLOUD_ENV...
18:11 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration/groups...
18:11 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration/main...
18:11 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/progress/main...
18:11 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:11 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:11 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:11 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:11 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:11 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:11 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:11 INFO [databricks.labs.ucx.install] Installation completed successfully! Please refer to the https://DATABRICKS_HOST/#workspace/Users/0a330eb5-dd51-4d97-b6e4-c474356b1d5d/.4JrC/README for the next steps.
18:11 DEBUG [databricks.labs.ucx.installer.workflows] starting migrate-tables job: https://DATABRICKS_HOST#job/534593752012327
18:11 INFO [databricks.labs.ucx.installer.workflows] Started migrate-tables job: https://DATABRICKS_HOST#job/534593752012327/runs/625175803686124
18:11 DEBUG [databricks.labs.ucx.installer.workflows] Waiting for completion of migrate-tables job: https://DATABRICKS_HOST#job/534593752012327/runs/625175803686124
18:18 INFO [databricks.labs.ucx.installer.workflows] Completed migrate-tables job run 625175803686124 with state: RunResultState.SUCCESS
18:18 INFO [databricks.labs.ucx.installer.workflows] Completed migrate-tables job run 625175803686124 duration: 0:06:51.893000 (2024-11-05 18:11:13.091000+00:00 thru 2024-11-05 18:18:04.984000+00:00)
18:18 INFO [databricks.labs.ucx.install] Deleting UCX v0.48.1+1520241105181059 from https://DATABRICKS_HOST
18:18 INFO [databricks.labs.ucx.install] Deleting inventory database dummy_sd0wa
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=4201900667564, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=85420913865230, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=798008557349044, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=680016672174354, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=1044779170571562, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=382896404544065, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=334099415818248, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=148607034264796, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=777809567359073, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=455471160073419, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=555966151568919, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=534593752012327, as it is no longer needed
18:18 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=136575961310939, as it is no longer needed
18:18 INFO [databricks.labs.ucx.install] Deleting cluster policy
18:18 INFO [databricks.labs.ucx.install] Deleting secret scope
18:18 INFO [databricks.labs.ucx.install] UnInstalling UCX complete
[gw9] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
❌ test_table_migration_job_publishes_remaining_tables[regular]: AssertionError: assert 'hive_metasto...o.dummy_tixvk' == 'hive_metasto...o.dummy_tvptw' (7m44.698s)
... (skipped 6686 bytes)
es one system table named system.hms_to_uc_migration.table_access and helps in your migration process from HMS to UC by allowing you to programmatically query HMS lineage data.
18:14 INFO [databricks.labs.ucx.install] Fetching installations...
18:14 WARNING [databricks.labs.ucx.install] Existing installation at /Users/0a330eb5-dd51-4d97-b6e4-c474356b1d5d/.AwcV is corrupted. Skipping...
18:14 INFO [databricks.labs.ucx.installer.policy] Creating UCX cluster policy.
18:14 DEBUG [tests.integration.conftest] Waiting for clusters to start...
18:14 DEBUG [tests.integration.conftest] Waiting for clusters to start...
18:14 INFO [databricks.labs.ucx.install] Installing UCX v0.48.1+1520241105181429
18:14 INFO [databricks.labs.ucx.install] Creating ucx schemas...
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=validate-groups-permissions
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-groups-experimental
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-groups
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migration-progress-experimental
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-tables
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-data-reconciliation
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=assessment
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-external-hiveserde-tables-in-place-experimental
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=remove-workspace-local-backup-groups
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=failing
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-external-tables-ctas
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=scan-tables-in-mounts-experimental
18:14 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-tables-in-mounts-experimental
18:14 INFO [databricks.labs.ucx.install] Creating dashboards...
18:14 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/views...
18:14 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment...
18:14 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration...
18:14 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/progress...
18:14 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/interactive...
18:14 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/estimates...
18:14 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/main...
18:14 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/CLOUD_ENV...
18:14 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration/groups...
18:14 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration/main...
18:14 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/progress/main...
18:14 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:14 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:14 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:14 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:14 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:14 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:14 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:14 INFO [databricks.labs.ucx.install] Installation completed successfully! Please refer to the https://DATABRICKS_HOST/#workspace/Users/0a330eb5-dd51-4d97-b6e4-c474356b1d5d/.AwcV/README for the next steps.
18:14 DEBUG [databricks.labs.ucx.installer.workflows] starting migrate-tables job: https://DATABRICKS_HOST#job/470975613998293
18:14 INFO [databricks.labs.ucx.installer.workflows] Started migrate-tables job: https://DATABRICKS_HOST#job/470975613998293/runs/12807387177263
18:14 DEBUG [databricks.labs.ucx.installer.workflows] Waiting for completion of migrate-tables job: https://DATABRICKS_HOST#job/470975613998293/runs/12807387177263
18:21 INFO [databricks.labs.ucx.installer.workflows] Completed migrate-tables job run 12807387177263 with state: RunResultState.SUCCESS
18:21 INFO [databricks.labs.ucx.installer.workflows] Completed migrate-tables job run 12807387177263 duration: 0:06:31.298000 (2024-11-05 18:14:43.825000+00:00 thru 2024-11-05 18:21:15.123000+00:00)
18:21 DEBUG [databricks.labs.ucx.installer.workflows] Validating migrate-tables workflow: https://DATABRICKS_HOST#job/470975613998293
18:21 INFO [databricks.labs.ucx.install] Deleting UCX v0.48.1+1520241105181429 from https://DATABRICKS_HOST
18:21 INFO [databricks.labs.ucx.install] Deleting inventory database dummy_sgv9w
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=244111248614524, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=3711277482038, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=1113996625882680, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=303231316440651, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=470975613998293, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=844573330909832, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=446181385988238, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=132282794026901, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=271005428602293, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=808095256051870, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=471541796031564, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=39161428144568, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=973552910491045, as it is no longer needed
18:21 INFO [databricks.labs.ucx.install] Deleting cluster policy
18:21 INFO [databricks.labs.ucx.install] Deleting secret scope
18:21 INFO [databricks.labs.ucx.install] UnInstalling UCX complete
[gw0] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
❌ test_migration_job_ext_hms[regular]: AssertionError: dummy_tkilh not found in dummy_ceqpe.migrate_wt7yf (14m0.357s)
... (skipped 6678 bytes)
n process from HMS to UC by allowing you to programmatically query HMS lineage data.
18:14 INFO [databricks.labs.ucx.install] Fetching installations...
18:14 WARNING [databricks.labs.ucx.install] Existing installation at /Users/0a330eb5-dd51-4d97-b6e4-c474356b1d5d/.Umo7 is corrupted. Skipping...
18:14 INFO [databricks.labs.ucx.installer.policy] Setting up an external metastore
18:14 INFO [databricks.labs.ucx.installer.policy] Creating UCX cluster policy.
18:14 DEBUG [tests.integration.conftest] Waiting for clusters to start...
18:14 DEBUG [tests.integration.conftest] Waiting for clusters to start...
18:14 INFO [databricks.labs.ucx.install] Installing UCX v0.48.1+1520241105181457
18:14 INFO [databricks.labs.ucx.install] Creating ucx schemas...
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=validate-groups-permissions
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-tables-in-mounts-experimental
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-data-reconciliation
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=assessment
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migration-progress-experimental
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-external-hiveserde-tables-in-place-experimental
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=remove-workspace-local-backup-groups
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=scan-tables-in-mounts-experimental
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-groups
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-groups-experimental
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-external-tables-ctas
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=failing
18:15 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-tables
18:15 INFO [databricks.labs.ucx.install] Creating dashboards...
18:15 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/views...
18:15 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment...
18:15 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration...
18:15 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/progress...
18:15 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/interactive...
18:15 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/estimates...
18:15 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/main...
18:15 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/CLOUD_ENV...
18:15 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration/groups...
18:15 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration/main...
18:15 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/progress/main...
18:15 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:15 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:15 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:15 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:15 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:15 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:15 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:15 INFO [databricks.labs.ucx.install] Installation completed successfully! Please refer to the https://DATABRICKS_HOST/#workspace/Users/0a330eb5-dd51-4d97-b6e4-c474356b1d5d/.Umo7/README for the next steps.
18:15 DEBUG [databricks.labs.ucx.installer.workflows] starting migrate-tables job: https://DATABRICKS_HOST#job/1051907059272196
18:15 INFO [databricks.labs.ucx.installer.workflows] Started migrate-tables job: https://DATABRICKS_HOST#job/1051907059272196/runs/403989316733867
18:15 DEBUG [databricks.labs.ucx.installer.workflows] Waiting for completion of migrate-tables job: https://DATABRICKS_HOST#job/1051907059272196/runs/403989316733867
18:21 INFO [databricks.labs.ucx.installer.workflows] Completed migrate-tables job run 403989316733867 with state: RunResultState.SUCCESS
18:21 INFO [databricks.labs.ucx.installer.workflows] Completed migrate-tables job run 403989316733867 duration: 0:05:16.055000 (2024-11-05 18:15:57.671000+00:00 thru 2024-11-05 18:21:13.726000+00:00)
18:21 DEBUG [databricks.labs.ucx.installer.workflows] Validating migrate-tables workflow: https://DATABRICKS_HOST#job/1051907059272196
18:21 INFO [databricks.labs.ucx.install] Deleting UCX v0.48.1+1520241105181457 from https://DATABRICKS_HOST
18:21 INFO [databricks.labs.ucx.install] Deleting inventory database dummy_syedu
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=397866868405962, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=863998983750508, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=423543514634125, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=775990698689971, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=242793184864895, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=689985378278797, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=685512920082118, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=2216998278795, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=654010458492395, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=679026889317525, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=707166651107928, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=740042907904535, as it is no longer needed
18:21 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=1051907059272196, as it is no longer needed
18:21 INFO [databricks.labs.ucx.install] Deleting cluster policy
18:21 INFO [databricks.labs.ucx.install] Deleting secret scope
18:21 INFO [databricks.labs.ucx.install] UnInstalling UCX complete
[gw7] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
❌ test_move_tables: databricks.sdk.errors.platform.BadRequest: [UC_COMMAND_NOT_SUPPORTED.WITH_RECOMMENDATION] The command(s): 3-layer (catalogName.schemaName.tableName) table name notation: dummy_cjfaj.dummy_sulzs.dummy_tf74k for view creation in HMS federation are not supported in Unity Catalog. Please use schemaName.tableName or tableName instead. SQLSTATE: 0AKUC (15.915s)
databricks.sdk.errors.platform.BadRequest: [UC_COMMAND_NOT_SUPPORTED.WITH_RECOMMENDATION] The command(s): 3-layer (catalogName.schemaName.tableName) table name notation: dummy_cjfaj.dummy_sulzs.dummy_tf74k for view creation in HMS federation are not supported in Unity Catalog. Please use schemaName.tableName or tableName instead. SQLSTATE: 0AKUC
[gw7] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
[gw7] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python
❌ test_table_migration_for_managed_table[managed-migrate-tables]: AssertionError: dummy_tmqvn not found in dummy_cfxoh.managed_dwkma (7m26.806s)
... (skipped 6232 bytes)
of questions to configure Unity Catalog migration
18:16 INFO [databricks.labs.ucx.installer.hms_lineage] HMS Lineage feature creates one system table named system.hms_to_uc_migration.table_access and helps in your migration process from HMS to UC by allowing you to programmatically query HMS lineage data.
18:16 INFO [databricks.labs.ucx.install] Fetching installations...
18:16 WARNING [databricks.labs.ucx.install] Existing installation at /Users/0a330eb5-dd51-4d97-b6e4-c474356b1d5d/.NN6f is corrupted. Skipping...
18:16 INFO [databricks.labs.ucx.installer.policy] Creating UCX cluster policy.
18:16 DEBUG [tests.integration.conftest] Waiting for clusters to start...
18:16 DEBUG [tests.integration.conftest] Waiting for clusters to start...
18:16 INFO [databricks.labs.ucx.install] Installing UCX v0.48.1+1520241105181642
18:16 INFO [databricks.labs.ucx.install] Creating ucx schemas...
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=scan-tables-in-mounts-experimental
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-data-reconciliation
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=assessment
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-groups
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migration-progress-experimental
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=remove-workspace-local-backup-groups
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-tables-in-mounts-experimental
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-tables
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-external-hiveserde-tables-in-place-experimental
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=failing
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=validate-groups-permissions
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-groups-experimental
18:16 INFO [databricks.labs.ucx.installer.workflows] Creating new job configuration for step=migrate-external-tables-ctas
18:16 INFO [databricks.labs.ucx.install] Creating dashboards...
18:16 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/views...
18:16 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment...
18:16 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration...
18:16 DEBUG [databricks.labs.ucx.install] Reading step folder /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/progress...
18:16 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/interactive...
18:16 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/estimates...
18:16 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/main...
18:16 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/assessment/CLOUD_ENV...
18:16 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration/groups...
18:16 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/migration/main...
18:16 INFO [databricks.labs.ucx.install] Creating dashboard in /home/runner/work/ucx/ucx/src/databricks/labs/ucx/queries/progress/main...
18:16 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:16 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:16 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:16 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:16 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:16 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:16 INFO [databricks.labs.ucx.installer.mixins] Fetching warehouse_id from a config
18:16 INFO [databricks.labs.ucx.install] Installation completed successfully! Please refer to the https://DATABRICKS_HOST/#workspace/Users/0a330eb5-dd51-4d97-b6e4-c474356b1d5d/.NN6f/README for the next steps.
18:16 DEBUG [databricks.labs.ucx.installer.workflows] starting migrate-tables job: https://DATABRICKS_HOST#job/36070437211053
18:16 INFO [databricks.labs.ucx.installer.workflows] Started migrate-tables job: https://DATABRICKS_HOST#job/36070437211053/runs/990035811184535
18:16 DEBUG [databricks.labs.ucx.installer.workflows] Waiting for completion of migrate-tables job: https://DATABRICKS_HOST#job/36070437211053/runs/990035811184535
18:23 INFO [databricks.labs.ucx.installer.workflows] Completed migrate-tables job run 990035811184535 with state: RunResultState.SUCCESS
18:23 INFO [databricks.labs.ucx.installer.workflows] Completed migrate-tables job run 990035811184535 duration: 0:06:13.909000 (2024-11-05 18:16:56.598000+00:00 thru 2024-11-05 18:23:10.507000+00:00)
18:23 INFO [databricks.labs.ucx.install] Deleting UCX v0.48.1+1520241105181642 from https://DATABRICKS_HOST
18:23 INFO [databricks.labs.ucx.install] Deleting inventory database dummy_snlv2
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=792752838522930, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=655836009312917, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=145343546503044, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=521906147606949, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=548897123479633, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=1092900605884493, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=724710214477158, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=36070437211053, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=945459016739420, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=1032733039650073, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=736004025520688, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=886696139564465, as it is no longer needed
18:23 INFO [databricks.labs.ucx.installer.workflows] Removing job_id=163145594828295, as it is no longer needed
18:23 INFO [databricks.labs.ucx.install] Deleting cluster policy
18:23 INFO [databricks.labs.ucx.install] Deleting secret scope
18:23 INFO [databricks.labs.ucx.install] UnInstalling UCX complete
[gw8] linux -- Python 3.10.15 /home/runner/work/ucx/ucx/.venv/bin/python

Flaky tests:

  • 🤪 test_running_real_assessment_job (11m11.106s)
  • 🤪 test_running_real_assessment_job_ext_hms (16m37.555s)

Running from acceptance #7214

# Conflicts:
#	src/databricks/labs/ucx/contexts/application.py
#	src/databricks/labs/ucx/hive_metastore/table_migration_status.py
#	src/databricks/labs/ucx/hive_metastore/tables.py
## Changes
`LegacyQueryOwnership` takes a `str` as record type which obfuscates the
meaning of that str and creates risk of collision in the ownership
factory
This PR fixes that by introducing a `LegacyQueryPath` data class as a
wrapper around the `str`

### Linked issues
None

### Functionality
None

### Tests
- [x] ran unit tests

Co-authored-by: Eric Vergnaud <[email protected]>
@nfx nfx temporarily deployed to account-admin October 25, 2024 14:06 — with GitHub Actions Inactive
Copy link
Collaborator

@nfx nfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make dependencies explicit, not implicit

@cached_property
def ownership_factory(self) -> Callable[[type], Ownership]:
# ensure registration of Ownerships
names_with_ownership = [name for name in dir(GlobalContext) if "ownership" in name]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please explicitly init components - we're doing that for permissions migration already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 174 to 180
_factories: dict[type, Ownership] = {}

@classmethod
def for_record_type(cls, record_type: type) -> Ownership[Record]:
return cast(Ownership[Record], cls._factories[record_type])

def __init__(self, administrator_locator: AdministratorLocator, record_type: type) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this control flow confuses pylint and it will fail to detect hidden future bugs.wouldn't it be more clear if we add is_applicable abstract method

def is_applicable(self, record: Any) -> bool:
  return isinstance(record, Table)

this will:

  1. avoid changing every constructor at the cost of adding new method
  2. allow for one ownership to work with more than one record class
  3. allow for an explicit injectable facade:
class AnyOwnership(Ownership[Any]):
  def __init__(self, ownerships: list[Ownership]): ...

  def owner_of(self, record: Any) -> str:
    for o for self._ownerships: if o.is_applicable(record): return o.owner_of(record)
    return self._administrator_locator....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@asnare asnare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some comments.

One thing I wonder: if there a context where the ownership instance that we need is not static in nature and tied to the type?

If not, I think we could replace things with a dictionary of type: ownership_instance in the application context. (Right now we wouldn't even need to deal with specialisation.)

I don't know about the context or any discussions that lead to this PR, so this is just based on the context provided here alone. (To be clear, I do understand the desire to avoid the proliferation of properties we have on the application context.)

Comment on lines +187 to +188
@abstractmethod
def is_applicable_to(self, record: Any) -> bool: ...
Copy link
Contributor

@asnare asnare Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a design perspective, I think I'd prefer this to take the type of the record as an argument rather than an instance thereof. The reason for this is that it would then encourage the caller to get the encoder and re-use it for a collection, which is the usual use-case. As it stands the current API encourages the lookup for each record within a loop over a collection, and the lookups are reasonably expensive due to the iteration required.

I'm on the fence about whether it should be a class method or not, although leaning towards a class method being more accurate. (For singletons, which these are, I agree that the distinction is more academic than practical.)

Assuming the current API, I think a default implementation is possible (and preferable) here:

  1. A cached property, initialised via typing.get_args(self), to get the generic type of the instance.
  2. Use isinstance() as in the current implementations against the cached property.

(If we switch to accepting the type rather than an instance then the details obviously change.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this comment indicating that we want to allow instances to support multiple types.

That said, I don't fully follow the reasoning: type-based lookups can also support multiple instance types (A | B) and encourage a single lookup rather than the (current) situation that encourages callers to implicitly linear probe the registry within a loop. I think I'm missing something here, and hope that @nfx can help me understand what he has in mind.

@@ -169,8 +171,21 @@ def get_workspace_administrator(self) -> str:
class Ownership(ABC, Generic[Record]):
"""Determine an owner for a given type of object."""

_ownerships: set[Ownership] = set()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the type annotation here is quite correct: it needs to be ClassVar[…]? (Without this I believe it is considered by the type tooling to be an instance property.)

Comment on lines +176 to +181
@classmethod
def for_record(cls, record: Any) -> Ownership[Record]:
for ownership in cls._ownerships:
if ownership.is_applicable_to(record):
return ownership
raise ValueError(f"Ownership not implemented or not registered for {type(record).__name__}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere I've commented on this API, and whether it should take the type of the record instead of an instance.

I'd really like this method to have a docstring. The current design allows for some ambiguous corner cases like multiple registered instances supporting a given record. (This remains even if we switch to type-based lookups.)

Comment on lines +580 to +592
@cached_property
def ownership_factory(self) -> Callable[[Record], Ownership]:
# ensure registration of Ownerships
_ = [
self.directfs_access_ownership,
self.grant_ownership,
self.legacy_query_ownership,
self.table_migration_ownership,
self.table_ownership,
self.udf_ownership,
self.workspace_path_ownership,
]
return Ownership.for_record
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As things stand during tests we re-create the application context for each test that needs one, and this is going to lead to the registry accumulating instances for each test that hits this property.

For this reason (and others) in the past we've preferred to avoid global singletons (which the class-hosted registry is), and move the cache to be owned and managed outside of it so that the lifecycle of the cache is tied to the application context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants