|
1 | 1 | import pytest |
2 | 2 |
|
3 | | -from databricks.labs.ucx.hive_metastore.tables import Table, TablesCrawler |
| 3 | +from databricks.labs.ucx.hive_metastore.tables import Table, TablesCrawler, What |
4 | 4 |
|
5 | 5 | from ..framework.mocks import MockBackend |
6 | 6 |
|
@@ -136,52 +136,94 @@ def test_tables_returning_error_when_describing(): |
136 | 136 | assert len(results) == 1 |
137 | 137 |
|
138 | 138 |
|
139 | | -def test_is_dbfs_root(): |
140 | | - assert Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/somelocation/tablename").is_dbfs_root |
141 | | - assert Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/somelocation/tablename").is_dbfs_root |
142 | | - assert not Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/mnt/somelocation/tablename").is_dbfs_root |
143 | | - assert not Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/mnt/somelocation/tablename").is_dbfs_root |
144 | | - assert not Table( |
145 | | - "a", "b", "c", "MANAGED", "DELTA", location="dbfs:/databricks-datasets/somelocation/tablename" |
146 | | - ).is_dbfs_root |
147 | | - assert not Table( |
148 | | - "a", "b", "c", "MANAGED", "DELTA", location="/dbfs/databricks-datasets/somelocation/tablename" |
149 | | - ).is_dbfs_root |
150 | | - assert not Table("a", "b", "c", "MANAGED", "DELTA", location="s3:/somelocation/tablename").is_dbfs_root |
151 | | - assert not Table("a", "b", "c", "MANAGED", "DELTA", location="adls:/somelocation/tablename").is_dbfs_root |
152 | | - |
153 | | - |
154 | | -def test_is_db_dataset(): |
155 | | - assert not Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/somelocation/tablename").is_databricks_dataset |
156 | | - assert not Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/somelocation/tablename").is_databricks_dataset |
157 | | - assert not Table( |
158 | | - "a", "b", "c", "MANAGED", "DELTA", location="dbfs:/mnt/somelocation/tablename" |
159 | | - ).is_databricks_dataset |
160 | | - assert not Table( |
161 | | - "a", "b", "c", "MANAGED", "DELTA", location="/dbfs/mnt/somelocation/tablename" |
162 | | - ).is_databricks_dataset |
163 | | - assert Table( |
164 | | - "a", "b", "c", "MANAGED", "DELTA", location="dbfs:/databricks-datasets/somelocation/tablename" |
165 | | - ).is_databricks_dataset |
166 | | - assert Table( |
167 | | - "a", "b", "c", "MANAGED", "DELTA", location="/dbfs/databricks-datasets/somelocation/tablename" |
168 | | - ).is_databricks_dataset |
169 | | - assert not Table("a", "b", "c", "MANAGED", "DELTA", location="s3:/somelocation/tablename").is_databricks_dataset |
170 | | - assert not Table("a", "b", "c", "MANAGED", "DELTA", location="adls:/somelocation/tablename").is_databricks_dataset |
171 | | - |
172 | | - |
173 | | -def test_is_supported_for_sync(): |
174 | | - assert Table( |
175 | | - "a", "b", "c", "EXTERNAL", "DELTA", location="dbfs:/somelocation/tablename" |
176 | | - ).is_format_supported_for_sync |
177 | | - assert Table("a", "b", "c", "EXTERNAL", "CSV", location="dbfs:/somelocation/tablename").is_format_supported_for_sync |
178 | | - assert Table( |
179 | | - "a", "b", "c", "EXTERNAL", "TEXT", location="dbfs:/somelocation/tablename" |
180 | | - ).is_format_supported_for_sync |
181 | | - assert Table("a", "b", "c", "EXTERNAL", "ORC", location="dbfs:/somelocation/tablename").is_format_supported_for_sync |
182 | | - assert Table( |
183 | | - "a", "b", "c", "EXTERNAL", "JSON", location="dbfs:/somelocation/tablename" |
184 | | - ).is_format_supported_for_sync |
185 | | - assert not ( |
186 | | - Table("a", "b", "c", "EXTERNAL", "AVRO", location="dbfs:/somelocation/tablename").is_format_supported_for_sync |
187 | | - ) |
| 139 | +@pytest.mark.parametrize( |
| 140 | + 'table,dbfs_root,what', |
| 141 | + [ |
| 142 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/somelocation/tablename"), True, What.DBFS_ROOT_DELTA), |
| 143 | + ( |
| 144 | + Table("a", "b", "c", "MANAGED", "PARQUET", location="dbfs:/somelocation/tablename"), |
| 145 | + True, |
| 146 | + What.DBFS_ROOT_NON_DELTA, |
| 147 | + ), |
| 148 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/somelocation/tablename"), True, What.DBFS_ROOT_DELTA), |
| 149 | + ( |
| 150 | + Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/mnt/somelocation/tablename"), |
| 151 | + False, |
| 152 | + What.EXTERNAL_SYNC, |
| 153 | + ), |
| 154 | + ( |
| 155 | + Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/mnt/somelocation/tablename"), |
| 156 | + False, |
| 157 | + What.EXTERNAL_SYNC, |
| 158 | + ), |
| 159 | + ( |
| 160 | + Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/databricks-datasets/somelocation/tablename"), |
| 161 | + False, |
| 162 | + What.DB_DATASET, |
| 163 | + ), |
| 164 | + ( |
| 165 | + Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/databricks-datasets/somelocation/tablename"), |
| 166 | + False, |
| 167 | + What.DB_DATASET, |
| 168 | + ), |
| 169 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="s3:/somelocation/tablename"), False, What.EXTERNAL_SYNC), |
| 170 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="adls:/somelocation/tablename"), False, What.EXTERNAL_SYNC), |
| 171 | + ], |
| 172 | +) |
| 173 | +def test_is_dbfs_root(table, dbfs_root, what): |
| 174 | + assert table.is_dbfs_root == dbfs_root |
| 175 | + assert table.what == what |
| 176 | + |
| 177 | + |
| 178 | +@pytest.mark.parametrize( |
| 179 | + 'table,db_dataset', |
| 180 | + [ |
| 181 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/somelocation/tablename"), False), |
| 182 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/somelocation/tablename"), False), |
| 183 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/mnt/somelocation/tablename"), False), |
| 184 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/mnt/somelocation/tablename"), False), |
| 185 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/databricks-datasets/somelocation/tablename"), True), |
| 186 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="/dbfs/databricks-datasets/somelocation/tablename"), True), |
| 187 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="s3:/somelocation/tablename"), False), |
| 188 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="adls:/somelocation/tablename"), False), |
| 189 | + ], |
| 190 | +) |
| 191 | +def test_is_db_dataset(table, db_dataset): |
| 192 | + assert table.is_databricks_dataset == db_dataset |
| 193 | + assert (table.what == What.DB_DATASET) == db_dataset |
| 194 | + |
| 195 | + |
| 196 | +@pytest.mark.parametrize( |
| 197 | + 'table,supported', |
| 198 | + [ |
| 199 | + (Table("a", "b", "c", "EXTERNAL", "DELTA", location="dbfs:/somelocation/tablename"), True), |
| 200 | + (Table("a", "b", "c", "EXTERNAL", "CSV", location="dbfs:/somelocation/tablename"), True), |
| 201 | + (Table("a", "b", "c", "EXTERNAL", "TEXT", location="dbfs:/somelocation/tablename"), True), |
| 202 | + (Table("a", "b", "c", "EXTERNAL", "ORC", location="dbfs:/somelocation/tablename"), True), |
| 203 | + (Table("a", "b", "c", "EXTERNAL", "JSON", location="dbfs:/somelocation/tablename"), True), |
| 204 | + (Table("a", "b", "c", "EXTERNAL", "AVRO", location="dbfs:/somelocation/tablename"), False), |
| 205 | + ], |
| 206 | +) |
| 207 | +def test_is_supported_for_sync(table, supported): |
| 208 | + assert table.is_format_supported_for_sync == supported |
| 209 | + |
| 210 | + |
| 211 | +@pytest.mark.parametrize( |
| 212 | + 'table,what', |
| 213 | + [ |
| 214 | + (Table("a", "b", "c", "EXTERNAL", "DELTA", location="s3://external_location/table"), What.EXTERNAL_SYNC), |
| 215 | + ( |
| 216 | + Table("a", "b", "c", "EXTERNAL", "UNSUPPORTED_FORMAT", location="s3://external_location/table"), |
| 217 | + What.EXTERNAL_NO_SYNC, |
| 218 | + ), |
| 219 | + (Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/somelocation/tablename"), What.DBFS_ROOT_DELTA), |
| 220 | + (Table("a", "b", "c", "MANAGED", "PARQUET", location="dbfs:/somelocation/tablename"), What.DBFS_ROOT_NON_DELTA), |
| 221 | + (Table("a", "b", "c", "VIEW", "VIEW", view_text="select * from some_table"), What.VIEW), |
| 222 | + ( |
| 223 | + Table("a", "b", "c", "MANAGED", "DELTA", location="dbfs:/databricks-datasets/somelocation/tablename"), |
| 224 | + What.DB_DATASET, |
| 225 | + ), |
| 226 | + ], |
| 227 | +) |
| 228 | +def test_table_what(table, what): |
| 229 | + assert table.what == what |
0 commit comments