|
28 | 28 | execute_through_cursor, |
29 | 29 | ) |
30 | 30 |
|
| 31 | +_SNOWFLAKE_SHOW_OBJECTS_COLUMNS: tuple[str, ...] = ("name", "kind", "rows", "bytes") |
31 | 32 | _DATABRICKS_DETAIL_HEADER: tuple[tuple[object, ...], ...] = ( |
32 | 33 | ("order_id", "bigint", None), |
33 | 34 | ("", "", ""), |
|
79 | 80 | expected_sql_fragment="pg_class", |
80 | 81 | ), |
81 | 82 | RelationRowCountEstimateTestCase( |
82 | | - description="snowflake table reports information schema row count", |
| 83 | + description="snowflake table reports its row count from SHOW OBJECTS", |
83 | 84 | adapter=SnowflakeAdapter(), |
84 | | - metadata_rows=((5000,),), |
| 85 | + metadata_rows=(("ORDERS", "TABLE", 5000, 65536),), |
| 86 | + metadata_columns=_SNOWFLAKE_SHOW_OBJECTS_COLUMNS, |
85 | 87 | expected_row_count=5000, |
86 | 88 | expected_detail=None, |
87 | | - expected_sql_fragment="SELECT row_count FROM", |
| 89 | + expected_sql_fragment="SHOW OBJECTS LIKE 'ORDERS' IN SCHEMA", |
88 | 90 | ), |
89 | 91 | RelationRowCountEstimateTestCase( |
90 | | - description="snowflake view has no row count", |
| 92 | + description="snowflake view has no row count although SHOW lists zero rows", |
91 | 93 | adapter=SnowflakeAdapter(), |
92 | | - metadata_rows=((None,),), |
| 94 | + metadata_rows=(("ORDERS", "VIEW", 0, 0),), |
| 95 | + metadata_columns=_SNOWFLAKE_SHOW_OBJECTS_COLUMNS, |
93 | 96 | expected_row_count=None, |
94 | 97 | expected_detail="no row count (view)", |
95 | | - expected_sql_fragment="('ORDERS', 'DEV', 'ANALYTICS')", |
| 98 | + expected_sql_fragment="SHOW OBJECTS LIKE 'ORDERS' IN SCHEMA", |
96 | 99 | ), |
97 | 100 | RelationRowCountEstimateTestCase( |
98 | | - description="snowflake missing relation is unknown", |
| 101 | + description="snowflake neighbour matched by the LIKE wildcard is not the relation", |
99 | 102 | adapter=SnowflakeAdapter(), |
100 | | - metadata_rows=(), |
| 103 | + metadata_rows=(("ORDERS_ARCHIVE", "TABLE", 9, 512),), |
| 104 | + metadata_columns=_SNOWFLAKE_SHOW_OBJECTS_COLUMNS, |
101 | 105 | expected_row_count=None, |
102 | 106 | expected_detail="relation not found", |
103 | | - expected_sql_fragment="information_schema.tables", |
| 107 | + expected_sql_fragment="SHOW OBJECTS LIKE 'ORDERS' IN SCHEMA", |
| 108 | + ), |
| 109 | + RelationRowCountEstimateTestCase( |
| 110 | + description="snowflake name with a backslash reads the information schema", |
| 111 | + adapter=SnowflakeAdapter(), |
| 112 | + metadata_rows=((5000, 65536),), |
| 113 | + name="order\\s", |
| 114 | + expected_row_count=5000, |
| 115 | + expected_detail=None, |
| 116 | + expected_sql_fragment="SELECT row_count,bytes FROM", |
| 117 | + ), |
| 118 | + RelationRowCountEstimateTestCase( |
| 119 | + description="snowflake relation without a schema reads the information schema", |
| 120 | + adapter=SnowflakeAdapter(), |
| 121 | + metadata_rows=((5000, 65536),), |
| 122 | + schema=None, |
| 123 | + expected_row_count=5000, |
| 124 | + expected_detail=None, |
| 125 | + expected_sql_fragment="SELECT row_count,bytes FROM", |
104 | 126 | ), |
105 | 127 | RelationRowCountEstimateTestCase( |
106 | 128 | description="databricks analyzed table reports statistics rows", |
|
185 | 207 | RelationRowCountEstimateTestCase( |
186 | 208 | description="snowflake bytes and rows are distinct", |
187 | 209 | adapter=SnowflakeAdapter(), |
188 | | - metadata_rows=((17, 4096),), |
| 210 | + metadata_rows=(("ORDERS", "TABLE", 17, 4096),), |
| 211 | + metadata_columns=_SNOWFLAKE_SHOW_OBJECTS_COLUMNS, |
189 | 212 | expected_row_count=17, |
190 | 213 | expected_detail=None, |
191 | | - expected_sql_fragment="SELECT row_count,bytes FROM", |
| 214 | + expected_sql_fragment="SHOW OBJECTS LIKE 'ORDERS' IN SCHEMA", |
192 | 215 | metadata_only=True, |
193 | 216 | expected_byte_count=4096, |
194 | | - expected_byte_count_basis="information_schema_bytes", |
| 217 | + expected_byte_count_basis="show_objects_bytes", |
195 | 218 | ), |
196 | 219 | RelationRowCountEstimateTestCase( |
197 | 220 | description="snowflake missing view statistics remain unavailable", |
198 | 221 | adapter=SnowflakeAdapter(), |
199 | | - metadata_rows=((None, None),), |
| 222 | + metadata_rows=(("ORDERS", "VIEW", 0, 0),), |
| 223 | + metadata_columns=_SNOWFLAKE_SHOW_OBJECTS_COLUMNS, |
200 | 224 | expected_row_count=None, |
201 | 225 | expected_detail="no row count (view)", |
| 226 | + expected_sql_fragment="SHOW OBJECTS LIKE 'ORDERS' IN SCHEMA", |
| 227 | + metadata_only=True, |
| 228 | + ), |
| 229 | + RelationRowCountEstimateTestCase( |
| 230 | + description="snowflake bytes without a schema keep the information schema basis", |
| 231 | + adapter=SnowflakeAdapter(), |
| 232 | + metadata_rows=((17, 4096),), |
| 233 | + schema=None, |
| 234 | + expected_row_count=17, |
| 235 | + expected_detail=None, |
202 | 236 | expected_sql_fragment="SELECT row_count,bytes FROM", |
203 | 237 | metadata_only=True, |
| 238 | + expected_byte_count=4096, |
| 239 | + expected_byte_count_basis="information_schema_bytes", |
204 | 240 | ), |
205 | 241 | RelationRowCountEstimateTestCase( |
206 | 242 | description="databricks bytes do not imply an analyzed row count", |
|
240 | 276 | def test_given_catalog_metadata_when_estimating_row_count_then_reads_only_metadata( |
241 | 277 | test_case: RelationRowCountEstimateTestCase, monkeypatch: pytest.MonkeyPatch |
242 | 278 | ) -> None: |
243 | | - connection: MetadataConnection = MetadataConnection(test_case.metadata_rows) |
| 279 | + connection: MetadataConnection = MetadataConnection( |
| 280 | + test_case.metadata_rows, test_case.metadata_columns |
| 281 | + ) |
244 | 282 |
|
245 | 283 | monkeypatch.setattr(test_case.adapter, "execute", execute_through_cursor) |
246 | 284 |
|
247 | 285 | estimate: RelationRowCountEstimate = test_case.adapter.estimate_relation_row_count( |
248 | 286 | connection=connection, |
249 | 287 | database=test_case.database, |
250 | 288 | schema=test_case.schema, |
251 | | - name="orders", |
| 289 | + name=test_case.name, |
252 | 290 | metadata_only=test_case.metadata_only, |
253 | 291 | ) |
254 | 292 |
|
|
0 commit comments