Skip to content

Bug fixes for Place Aggregation#666

Open
SandeepTuniki wants to merge 7 commits into
masterfrom
fix-place-aggr-bugs
Open

Bug fixes for Place Aggregation#666
SandeepTuniki wants to merge 7 commits into
masterfrom
fix-place-aggr-bugs

Conversation

@SandeepTuniki

@SandeepTuniki SandeepTuniki commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This PR contains a few fixes & improvements in place aggregations:

  1. Parent Type Filtering: When allow_multiple_to_place = False, the aggregator previously ran MIN(parent_id) across all containment edges before checking parent types. For child places contained in multiple parent types (e.g., a County contained in both State geoId/06 and Country country/USA), MIN() picked country/USA alphabetically, causing counties to drop out of State rollups.
    • Fix: Updated the BQ SQL in steps 1 & 2 to filter candidate parents by destination_type first before selecting MIN(parent_id).
  2. Duplicate dc/Aggregate prefixing: During multi-stage chained rollups (e.g., County → State → Country), each aggregation stage blindly prepended dcAggregate/ to measurementMethod, resulting in corrupted strings like dcAggregate/dcAggregate/CensusACS5yrSurvey.
    • Fixed this by doing a conditional check.
  3. Dynamic Aggregation Strategy: The aggregator hardcoded SUM() for all statistical variables, incorrectly summing rates, medians, percentiles, and averages, while ignoring denominators.
    • Fix: Added helpers and a query snippet to check for eligible SVs to dynamically determine `SUM/MIN/MAX/MEAN etc.
  4. Ignoring output_import_name: The code was ignoring the yaml config field output_import_name and was generating it's own value. Fixed this by reading it from the config file.
  5. The google3 code excluded CensusACS5yrSurveySubjectTable. So I updated this code to do the same.
  6. Query Optimization: Streamed less query into BigQuery performing some early filtering.
  7. Consolidated E2E Tests: Consolidated 9 individual test methods into 4 tests. This cut down test execution time from ~9.5 minutes to ~4.5 minutes, while preserving the same coverage.

@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 12 medium · 16 minor

Alerts:
⚠ 28 issues (≤ 0 issues of at least minor severity)

Results:
28 new issues

Category Results
Documentation 4 minor
Security 10 medium
CodeStyle 12 minor
Complexity 2 medium

View in Codacy

🟢 Metrics -6 complexity

Metric Results
Complexity -6

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces dynamic place aggregation strategies (SUM, MIN, MAX, MEAN) based on statistical variable metadata, refactors the SQL queries to handle these strategies, and updates the orchestrator and tests to support a mandatory output_import_name parameter. The review feedback highlights two important improvements: first, avoiding a JOIN inside the Spanner EXTERNAL_QUERY to prevent execution failures when Spanner Data Boost is enabled, and second, grouping by sv.aggr_strategy directly in the SQL query to eliminate redundant ANY_VALUE evaluations.

# Conflicts:
#	pipeline/workflow/aggregation-helper/aggregation/aggregation_test.py
#	pipeline/workflow/aggregation-helper/aggregation/orchestrator.py
#	pipeline/workflow/aggregation-helper/aggregation/orchestrator_test.py
#	pipeline/workflow/aggregation-helper/aggregation/place_aggregation_generator.py
@SandeepTuniki

Copy link
Copy Markdown
Contributor Author

/gemini review

@SandeepTuniki SandeepTuniki changed the title Few bug fixes for Place Aggregation Bug fixes for Place Aggregation Jul 23, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the place aggregation pipeline by introducing dynamic aggregation strategies (SUM, MIN, MAX, MEAN) based on statistical variable metadata, supporting custom output import names, and preserving multi-entity dimensions. It also refactors and expands the integration tests to cover these hierarchical and multi-facet scenarios. The review feedback correctly identifies a critical issue where a SQL JOIN is performed inside an EXTERNAL_QUERY block; because Spanner Data Boost does not support joins or subqueries within external queries, the tables must be queried separately and joined in BigQuery instead.

@SandeepTuniki
SandeepTuniki marked this pull request as ready for review July 23, 2026 15:37
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.

1 participant