Skip to content

Conversation

@gurmeetsaran
Copy link
Owner

Summary

Introduces BigQueryMockTable class to provide clean, explicit support for BigQuery's three-part naming scheme (project.dataset.table).

Previously, BigQuery mock tables had to awkwardly cram project and dataset together into the database_name field. The new class makes each component explicit using simple class variables.

Changes

Implementation

  • New BigQueryMockTable class in src/sql_testing_library/_mock_table.py
    • Three mandatory class variables: bigquery_project, bigquery_dataset, bigquery_table
    • Supports inheritance pattern for code reuse
    • Backwards compatible with BaseMockTable interface
    • No instance variables, no global state, no complex logic

Tests

  • 16 comprehensive unit tests in tests/test_bigquery_mock_table.py
  • Updated integration tests to use new class in tests/integration/test_bigquery_integration.py
  • All existing tests continue to pass

Documentation

  • Updated README.md with BigQueryMockTable examples and benefits
  • Updated docs/adapters.md with detailed BigQuery-specific section
  • Updated docs/api-reference.md with complete API documentation
  • Updated docs/examples.md with practical usage examples
  • Removed examples/ folder files (redundant with inline documentation)
  • Fixed broken documentation references

Example Usage

Before (Awkward)

class UsersMockTable(BaseMockTable):
    def get_database_name(self) -> str:
        return "test-project.test_dataset"  # Confusing!
    
    def get_table_name(self) -> str:
        return "users"

After (Clean)

class UsersMockTable(BigQueryMockTable):
    bigquery_project = "test-project"
    bigquery_dataset = "test_dataset"
    bigquery_table = "users"

Inheritance Pattern

# Base class with shared project
class MyProjectTable(BigQueryMockTable):
    bigquery_project = "my-project"

# Subclasses just set dataset and table
class UsersTable(MyProjectTable):
    bigquery_dataset = "analytics"
    bigquery_table = "users"

Benefits

  • Clear Semantics - Each BigQuery component is explicit
  • Simple - Just 3 mandatory class variables
  • Type Safe - Full type hints and IDE autocomplete
  • No Complexity - No instance variables, global state, or priority logic
  • Backwards Compatible - Still implements all BaseMockTable methods
  • Flexible - Use inheritance to share common properties

Test Results

  • ✅ All 16 BigQueryMockTable unit tests pass
  • ✅ All 19 existing BaseMockTable tests pass
  • ✅ All linting and type checks pass
  • ✅ Zero breaking changes

Introduces BigQueryMockTable to cleanly handle BigQuery's project.dataset.table
naming scheme using simple class variables instead of cramming project and
dataset into the generic database_name field.

Key changes:
- New BigQueryMockTable class with bigquery_project, bigquery_dataset,
  bigquery_table class variables
- Supports inheritance pattern to share common project/dataset across tables
- Backwards compatible with BaseMockTable interface
- Comprehensive test coverage (16 unit tests)
- Updated BigQuery integration tests to use new class
- Complete documentation in README and docs/
- Removed examples folder files (redundant with inline docs)

Benefits:
- Clear semantics - each BigQuery component is explicit
- Simple - just 3 mandatory class variables
- Type-safe with full IDE autocomplete
- No global state or complex priority logic
- Clean inheritance for code reuse
…_name

Shortened class variable names by removing redundant bigquery_ prefix since
the class is already BigQueryMockTable. Cleaner and more concise.
@gurmeetsaran gurmeetsaran self-assigned this Dec 7, 2025
@gurmeetsaran gurmeetsaran merged commit 9b236dc into master Dec 7, 2025
21 of 23 checks passed
@gurmeetsaran gurmeetsaran deleted the feat/bigquery-mock-table-class branch December 7, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants