|
| 1 | +import logging |
| 2 | +import os |
| 3 | + |
| 4 | +from databricks.labs.ucx.framework.crawlers import StatementExecutionBackend |
| 5 | +from databricks.labs.ucx.hive_metastore.data_objects import ExternalLocationCrawler |
| 6 | +from databricks.labs.ucx.hive_metastore.list_mounts import Mount |
| 7 | +from databricks.labs.ucx.hive_metastore.tables import Table |
| 8 | + |
| 9 | +logger = logging.getLogger(__name__) |
| 10 | + |
| 11 | + |
| 12 | +def test_table_inventory(ws, make_warehouse, make_schema): |
| 13 | + warehouse_id = os.environ["TEST_DEFAULT_WAREHOUSE_ID"] |
| 14 | + |
| 15 | + logger.info("setting up fixtures") |
| 16 | + sbe = StatementExecutionBackend(ws, warehouse_id) |
| 17 | + tables = [ |
| 18 | + Table("hive_metastore", "foo", "bar", "MANAGED", "delta", location="s3://test_location/test1/table1"), |
| 19 | + Table("hive_metastore", "foo", "bar", "EXTERNAL", "delta", location="s3://test_location/test2/table2"), |
| 20 | + Table("hive_metastore", "foo", "bar", "EXTERNAL", "delta", location="dbfs:/mnt/foo/test3/table3"), |
| 21 | + ] |
| 22 | + schema = make_schema() |
| 23 | + sbe.save_table(f"{schema}.tables", tables) |
| 24 | + sbe.save_table(f"{schema}.mounts", [Mount("/mnt/foo", "s3://bar")]) |
| 25 | + |
| 26 | + crawler = ExternalLocationCrawler(ws, sbe, schema.split(".")[1]) |
| 27 | + results = crawler.snapshot() |
| 28 | + assert len(results) == 2 |
| 29 | + assert results[1].location == "s3://bar/test3/" |
0 commit comments