1
+ import logging
1
2
import sys
2
3
3
4
from databricks .labs .lsql .backends import MockBackend
@@ -41,11 +42,11 @@ def test_table_size_crawler(mocker):
41
42
assert TableSize ("hive_metastore" , "db1" , "table2" , 200 ) in results
42
43
43
44
44
- def test_table_size_unknown_error (mocker ):
45
+ def test_table_size_unknown_error (mocker , caplog ):
45
46
errors = {}
46
47
rows = {
47
48
"table_size" : [],
48
- "hive_metastore. inventory_database. tables" : [
49
+ "` hive_metastore`.` inventory_database`.` tables` " : [
49
50
("hive_metastore" , "db1" , "table1" , "MANAGED" , "DELTA" , "dbfs:/location/table" , None ),
50
51
],
51
52
"SHOW DATABASES" : [("db1" ,)],
@@ -56,16 +57,17 @@ def test_table_size_unknown_error(mocker):
56
57
tsc = TableSizeCrawler (backend , "inventory_database" )
57
58
tsc ._spark ._jsparkSession .table ().queryExecution ().analyzed ().stats ().sizeInBytes .side_effect = Exception (...)
58
59
59
- results = tsc .snapshot ()
60
+ with caplog .at_level (logging .WARNING ):
61
+ results = tsc .snapshot ()
60
62
61
63
assert len (results ) == 0
62
64
63
65
64
- def test_table_size_table_or_view_not_found (mocker ):
66
+ def test_table_size_table_or_view_not_found (mocker , caplog ):
65
67
errors = {}
66
68
rows = {
67
69
"table_size" : [],
68
- "hive_metastore. inventory_database. tables" : [
70
+ "` hive_metastore`.` inventory_database`.` tables` " : [
69
71
("hive_metastore" , "db1" , "table1" , "MANAGED" , "DELTA" , "dbfs:/location/table" , None ),
70
72
],
71
73
"SHOW DATABASES" : [("db1" ,)],
@@ -80,16 +82,18 @@ def test_table_size_table_or_view_not_found(mocker):
80
82
"[TABLE_OR_VIEW_NOT_FOUND]"
81
83
)
82
84
83
- results = tsc .snapshot ()
85
+ with caplog .at_level (logging .WARNING ):
86
+ results = tsc .snapshot ()
84
87
85
88
assert len (results ) == 0
89
+ assert "Failed to evaluate hive_metastore.db1.table1 table size. Table not found" in caplog .text
86
90
87
91
88
- def test_table_size_delta_table_not_found (mocker ):
92
+ def test_table_size_delta_table_not_found (mocker , caplog ):
89
93
errors = {}
90
94
rows = {
91
95
"table_size" : [],
92
- "hive_metastore. inventory_database. tables" : [
96
+ "` hive_metastore`.` inventory_database`.` tables` " : [
93
97
("hive_metastore" , "db1" , "table1" , "MANAGED" , "DELTA" , "dbfs:/location/table" , None ),
94
98
],
95
99
"SHOW DATABASES" : [("db1" ,)],
@@ -104,16 +108,18 @@ def test_table_size_delta_table_not_found(mocker):
104
108
"[DELTA_TABLE_NOT_FOUND]"
105
109
)
106
110
107
- results = tsc .snapshot ()
111
+ with caplog .at_level (logging .WARNING ):
112
+ results = tsc .snapshot ()
108
113
109
114
assert len (results ) == 0
115
+ assert "Failed to evaluate hive_metastore.db1.table1 table size. Table not found" in caplog .text
110
116
111
117
112
- def test_table_size_when_table_corrupted (mocker ):
118
+ def test_table_size_when_table_corrupted (mocker , caplog ):
113
119
errors = {}
114
120
rows = {
115
121
"table_size" : [],
116
- "hive_metastore. inventory_database. tables" : [
122
+ "` hive_metastore`.` inventory_database`.` tables` " : [
117
123
("hive_metastore" , "db1" , "table1" , "MANAGED" , "DELTA" , "dbfs:/location/table" , None ),
118
124
],
119
125
"SHOW DATABASES" : [("db1" ,)],
@@ -127,16 +133,18 @@ def test_table_size_when_table_corrupted(mocker):
127
133
"[DELTA_MISSING_TRANSACTION_LOG]"
128
134
)
129
135
130
- results = tsc .snapshot ()
136
+ with caplog .at_level (logging .WARNING ):
137
+ results = tsc .snapshot ()
131
138
132
139
assert len (results ) == 0
140
+ assert "Delta table hive_metastore.db1.table1 is corrupted: missing transaction log" in caplog .text
133
141
134
142
135
- def test_table_size_when_delta_invalid_format_error (mocker ):
143
+ def test_table_size_when_delta_invalid_format_error (mocker , caplog ):
136
144
errors = {}
137
145
rows = {
138
146
"table_size" : [],
139
- "hive_metastore. inventory_database. tables" : [
147
+ "` hive_metastore`.` inventory_database`.` tables` " : [
140
148
("hive_metastore" , "db1" , "table1" , "MANAGED" , "DELTA" , "dbfs:/location/table" , None ),
141
149
],
142
150
"SHOW DATABASES" : [("db1" ,)],
@@ -150,6 +158,11 @@ def test_table_size_when_delta_invalid_format_error(mocker):
150
158
"[DELTA_INVALID_FORMAT]"
151
159
)
152
160
153
- results = tsc .snapshot ()
161
+ with caplog .at_level (logging .WARNING ):
162
+ results = tsc .snapshot ()
154
163
155
164
assert len (results ) == 0
165
+ assert (
166
+ "Unable to read Delta table hive_metastore.db1.table1, please check table structure and try again."
167
+ in caplog .text
168
+ )
0 commit comments