mistercrunch commented on code in PR #30760: URL: https://github.com/apache/superset/pull/30760#discussion_r1823789501
########## tests/integration_tests/db_engine_specs/bigquery_tests.py: ########## @@ -111,108 +121,45 @@ def values(self): result = BigQueryEngineSpec.fetch_data(None, 0) assert result == [1, 2] - def test_get_extra_table_metadata(self): + @mock.patch.object( + BigQueryEngineSpec, "get_engine", side_effect=mock_engine_with_credentials + ) + @mock.patch.object(BigQueryEngineSpec, "get_time_partition_column") + @mock.patch.object(BigQueryEngineSpec, "get_max_partition_id") + @mock.patch.object(BigQueryEngineSpec, "quote_table", return_value="`table_name`") + def test_get_extra_table_metadata( + self, + mock_quote_table, + mock_get_max_partition_id, + mock_get_time_partition_column, + mock_get_engine, + ): """ DB Eng Specs (bigquery): Test extra table metadata """ database = mock.Mock() + sql = "SELECT * FROM `table_name`" + database.compile_sqla_query.return_value = sql + tbl = Table("some_table", "some_schema") + # Test no indexes - database.get_indexes = mock.MagicMock(return_value=None) - result = BigQueryEngineSpec.get_extra_table_metadata( - database, - Table("some_table", "some_schema"), - ) + mock_get_time_partition_column.return_value = None + mock_get_max_partition_id.return_value = None + result = BigQueryEngineSpec.get_extra_table_metadata(database, tbl) assert result == {} - index_metadata = [ - { - "name": "clustering", - "column_names": ["c_col1", "c_col2", "c_col3"], - }, - { - "name": "partition", - "column_names": ["p_col1", "p_col2", "p_col3"], + mock_get_time_partition_column.return_value = "ds" + mock_get_max_partition_id.return_value = "19690101" + result = BigQueryEngineSpec.get_extra_table_metadata(database, tbl) + print(result) + assert result == { + "indexes": [{"cols": ["ds"], "name": "partitioned", "type": "partitioned"}], + "partitions": { + "cols": ["ds"], + "latest": {"ds": "19690101"}, + "partitionQuery": sql, }, - ] - expected_result = { - "partitions": {"cols": [["p_col1", "p_col2", "p_col3"]]}, - "clustering": {"cols": [["c_col1", "c_col2", "c_col3"]]}, } - database.get_indexes = mock.MagicMock(return_value=index_metadata) - result = BigQueryEngineSpec.get_extra_table_metadata( - database, - Table("some_table", "some_schema"), - ) - assert result == expected_result - - def test_get_indexes(self): Review Comment: turns out BigQuery's implementation of get_indexes is a no-op -> https://github.com/googleapis/python-bigquery-sqlalchemy/blob/150143ce27c02f1cd711b8df4ffe587a98ada288/sqlalchemy_bigquery/base.py#L1266-L1268 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org