Skip to content

Fixes #25359: Bigquery Ingestion Optimization - #25471

Merged
pmbrull merged 4 commits into
mainfrom
issue-25359
Jan 23, 2026
Merged

pmbrull merged 4 commits into
mainfrom
issue-25359

Conversation

@keshavmohta09

@keshavmohta09 keshavmohta09 commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #25359

  • Fetch schema metadata only once to avoid redundant calls
  • Fetch table metadata only once
  • Switched table metadata fetching to API calls instead of SQL queries
  • Consolidated multiple table-constraint queries into a single query
  • Fixed table DDL extraction issues
  • Added support to correctly fetch view definitions for materialized views
  • Reduced extra queries for fetching view definitions
  • Prefetched policy tags to minimize repeated queries

Summary by Gitar

  • Metadata caching:
    • Per-schema caching via _current_dataset_obj, _current_schema_tables, _policy_tag_cache, _table_ddl_cache prevents redundant API calls
  • API optimization:
    • Replaced SQL queries with BigQuery native API methods (list_tables(), get_dataset(), list_datasets())
  • Query consolidation:
    • Unified constraint queries into single BIGQUERY_CONSTRAINTS query reducing round-trips
  • Pre-fetching strategy:
    • Added _prefetch_policy_tags() and _prefetch_table_ddls() to batch-load metadata at schema level

This will update automatically on new commits.


Type of change:

  • Bug fix
  • Improvement
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.

@keshavmohta09 keshavmohta09 self-assigned this Jan 22, 2026
@keshavmohta09
keshavmohta09 requested a review from a team as a code owner January 22, 2026 20:45
@keshavmohta09 keshavmohta09 added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Jan 22, 2026
@github-actions

github-actions Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

🛡️ TRIVY SCAN RESULT 🛡️

Target: openmetadata-ingestion-base-slim:trivy (debian 12.13)

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: Java

Vulnerabilities (33)

Package Vulnerability ID Severity Installed Version Fixed Version
com.fasterxml.jackson.core:jackson-core CVE-2025-52999 🚨 HIGH 2.12.7 2.15.0
com.fasterxml.jackson.core:jackson-core CVE-2025-52999 🚨 HIGH 2.13.4 2.15.0
com.fasterxml.jackson.core:jackson-databind CVE-2022-42003 🚨 HIGH 2.12.7 2.12.7.1, 2.13.4.2
com.fasterxml.jackson.core:jackson-databind CVE-2022-42004 🚨 HIGH 2.12.7 2.12.7.1, 2.13.4
com.google.code.gson:gson CVE-2022-25647 🚨 HIGH 2.2.4 2.8.9
com.google.protobuf:protobuf-java CVE-2021-22569 🚨 HIGH 3.3.0 3.16.1, 3.18.2, 3.19.2
com.google.protobuf:protobuf-java CVE-2022-3509 🚨 HIGH 3.3.0 3.16.3, 3.19.6, 3.20.3, 3.21.7
com.google.protobuf:protobuf-java CVE-2022-3510 🚨 HIGH 3.3.0 3.16.3, 3.19.6, 3.20.3, 3.21.7
com.google.protobuf:protobuf-java CVE-2024-7254 🚨 HIGH 3.3.0 3.25.5, 4.27.5, 4.28.2
com.google.protobuf:protobuf-java CVE-2021-22569 🚨 HIGH 3.7.1 3.16.1, 3.18.2, 3.19.2
com.google.protobuf:protobuf-java CVE-2022-3509 🚨 HIGH 3.7.1 3.16.3, 3.19.6, 3.20.3, 3.21.7
com.google.protobuf:protobuf-java CVE-2022-3510 🚨 HIGH 3.7.1 3.16.3, 3.19.6, 3.20.3, 3.21.7
com.google.protobuf:protobuf-java CVE-2024-7254 🚨 HIGH 3.7.1 3.25.5, 4.27.5, 4.28.2
com.nimbusds:nimbus-jose-jwt CVE-2023-52428 🚨 HIGH 9.8.1 9.37.2
com.squareup.okhttp3:okhttp CVE-2021-0341 🚨 HIGH 3.12.12 4.9.2
commons-beanutils:commons-beanutils CVE-2025-48734 🚨 HIGH 1.9.4 1.11.0
commons-io:commons-io CVE-2024-47554 🚨 HIGH 2.8.0 2.14.0
dnsjava:dnsjava CVE-2024-25638 🚨 HIGH 2.1.7 3.6.0
io.netty:netty-codec-http2 CVE-2025-55163 🚨 HIGH 4.1.96.Final 4.2.4.Final, 4.1.124.Final
io.netty:netty-codec-http2 GHSA-xpw8-rcwv-8f8p 🚨 HIGH 4.1.96.Final 4.1.100.Final
io.netty:netty-handler CVE-2025-24970 🚨 HIGH 4.1.96.Final 4.1.118.Final
net.minidev:json-smart CVE-2021-31684 🚨 HIGH 1.3.2 1.3.3, 2.4.4
net.minidev:json-smart CVE-2023-1370 🚨 HIGH 1.3.2 2.4.9
org.apache.avro:avro CVE-2024-47561 🔥 CRITICAL 1.7.7 1.11.4
org.apache.avro:avro CVE-2023-39410 🚨 HIGH 1.7.7 1.11.3
org.apache.derby:derby CVE-2022-46337 🔥 CRITICAL 10.14.2.0 10.14.3, 10.15.2.1, 10.16.1.2, 10.17.1.0
org.apache.ivy:ivy CVE-2022-46751 🚨 HIGH 2.5.1 2.5.2
org.apache.mesos:mesos CVE-2018-1330 🚨 HIGH 1.4.3 1.6.0
org.apache.thrift:libthrift CVE-2019-0205 🚨 HIGH 0.12.0 0.13.0
org.apache.thrift:libthrift CVE-2020-13949 🚨 HIGH 0.12.0 0.14.0
org.apache.zookeeper:zookeeper CVE-2023-44981 🔥 CRITICAL 3.6.3 3.7.2, 3.8.3, 3.9.1
org.eclipse.jetty:jetty-server CVE-2024-13009 🚨 HIGH 9.4.56.v20240826 9.4.57.v20241219
org.lz4:lz4-java CVE-2025-12183 🚨 HIGH 1.8.0 1.8.1

🛡️ TRIVY SCAN RESULT 🛡️

Target: Node.js

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: Python

Vulnerabilities (9)

Package Vulnerability ID Severity Installed Version Fixed Version
apache-airflow CVE-2025-68438 🚨 HIGH 3.1.5 3.1.6
apache-airflow CVE-2025-68675 🚨 HIGH 3.1.5 3.1.6
jaraco.context CVE-2026-23949 🚨 HIGH 5.3.0 6.1.0
starlette CVE-2025-62727 🚨 HIGH 0.48.0 0.49.1
urllib3 CVE-2025-66418 🚨 HIGH 1.26.20 2.6.0
urllib3 CVE-2025-66471 🚨 HIGH 1.26.20 2.6.0
urllib3 CVE-2026-21441 🚨 HIGH 1.26.20 2.6.3
wheel CVE-2026-24049 🚨 HIGH 0.45.1 0.46.2
wheel CVE-2026-24049 🚨 HIGH 0.45.1 0.46.2

🛡️ TRIVY SCAN RESULT 🛡️

Target: /etc/ssl/private/ssl-cert-snakeoil.key

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /ingestion/pipelines/extended_sample_data.yaml

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /ingestion/pipelines/lineage.yaml

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /ingestion/pipelines/sample_data.json

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /ingestion/pipelines/sample_data.yaml

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /ingestion/pipelines/sample_data_aut.yaml

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /ingestion/pipelines/sample_usage.json

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /ingestion/pipelines/sample_usage.yaml

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /ingestion/pipelines/sample_usage_aut.yaml

No Vulnerabilities Found

@github-actions

github-actions Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

🛡️ TRIVY SCAN RESULT 🛡️

Target: openmetadata-ingestion:trivy (debian 12.12)

Vulnerabilities (4)

Package Vulnerability ID Severity Installed Version Fixed Version
libpam-modules CVE-2025-6020 🚨 HIGH 1.5.2-6+deb12u1 1.5.2-6+deb12u2
libpam-modules-bin CVE-2025-6020 🚨 HIGH 1.5.2-6+deb12u1 1.5.2-6+deb12u2
libpam-runtime CVE-2025-6020 🚨 HIGH 1.5.2-6+deb12u1 1.5.2-6+deb12u2
libpam0g CVE-2025-6020 🚨 HIGH 1.5.2-6+deb12u1 1.5.2-6+deb12u2

🛡️ TRIVY SCAN RESULT 🛡️

Target: Java

Vulnerabilities (33)

Package Vulnerability ID Severity Installed Version Fixed Version
com.fasterxml.jackson.core:jackson-core CVE-2025-52999 🚨 HIGH 2.12.7 2.15.0
com.fasterxml.jackson.core:jackson-core CVE-2025-52999 🚨 HIGH 2.13.4 2.15.0
com.fasterxml.jackson.core:jackson-databind CVE-2022-42003 🚨 HIGH 2.12.7 2.12.7.1, 2.13.4.2
com.fasterxml.jackson.core:jackson-databind CVE-2022-42004 🚨 HIGH 2.12.7 2.12.7.1, 2.13.4
com.google.code.gson:gson CVE-2022-25647 🚨 HIGH 2.2.4 2.8.9
com.google.protobuf:protobuf-java CVE-2021-22569 🚨 HIGH 3.3.0 3.16.1, 3.18.2, 3.19.2
com.google.protobuf:protobuf-java CVE-2022-3509 🚨 HIGH 3.3.0 3.16.3, 3.19.6, 3.20.3, 3.21.7
com.google.protobuf:protobuf-java CVE-2022-3510 🚨 HIGH 3.3.0 3.16.3, 3.19.6, 3.20.3, 3.21.7
com.google.protobuf:protobuf-java CVE-2024-7254 🚨 HIGH 3.3.0 3.25.5, 4.27.5, 4.28.2
com.google.protobuf:protobuf-java CVE-2021-22569 🚨 HIGH 3.7.1 3.16.1, 3.18.2, 3.19.2
com.google.protobuf:protobuf-java CVE-2022-3509 🚨 HIGH 3.7.1 3.16.3, 3.19.6, 3.20.3, 3.21.7
com.google.protobuf:protobuf-java CVE-2022-3510 🚨 HIGH 3.7.1 3.16.3, 3.19.6, 3.20.3, 3.21.7
com.google.protobuf:protobuf-java CVE-2024-7254 🚨 HIGH 3.7.1 3.25.5, 4.27.5, 4.28.2
com.nimbusds:nimbus-jose-jwt CVE-2023-52428 🚨 HIGH 9.8.1 9.37.2
com.squareup.okhttp3:okhttp CVE-2021-0341 🚨 HIGH 3.12.12 4.9.2
commons-beanutils:commons-beanutils CVE-2025-48734 🚨 HIGH 1.9.4 1.11.0
commons-io:commons-io CVE-2024-47554 🚨 HIGH 2.8.0 2.14.0
dnsjava:dnsjava CVE-2024-25638 🚨 HIGH 2.1.7 3.6.0
io.netty:netty-codec-http2 CVE-2025-55163 🚨 HIGH 4.1.96.Final 4.2.4.Final, 4.1.124.Final
io.netty:netty-codec-http2 GHSA-xpw8-rcwv-8f8p 🚨 HIGH 4.1.96.Final 4.1.100.Final
io.netty:netty-handler CVE-2025-24970 🚨 HIGH 4.1.96.Final 4.1.118.Final
net.minidev:json-smart CVE-2021-31684 🚨 HIGH 1.3.2 1.3.3, 2.4.4
net.minidev:json-smart CVE-2023-1370 🚨 HIGH 1.3.2 2.4.9
org.apache.avro:avro CVE-2024-47561 🔥 CRITICAL 1.7.7 1.11.4
org.apache.avro:avro CVE-2023-39410 🚨 HIGH 1.7.7 1.11.3
org.apache.derby:derby CVE-2022-46337 🔥 CRITICAL 10.14.2.0 10.14.3, 10.15.2.1, 10.16.1.2, 10.17.1.0
org.apache.ivy:ivy CVE-2022-46751 🚨 HIGH 2.5.1 2.5.2
org.apache.mesos:mesos CVE-2018-1330 🚨 HIGH 1.4.3 1.6.0
org.apache.thrift:libthrift CVE-2019-0205 🚨 HIGH 0.12.0 0.13.0
org.apache.thrift:libthrift CVE-2020-13949 🚨 HIGH 0.12.0 0.14.0
org.apache.zookeeper:zookeeper CVE-2023-44981 🔥 CRITICAL 3.6.3 3.7.2, 3.8.3, 3.9.1
org.eclipse.jetty:jetty-server CVE-2024-13009 🚨 HIGH 9.4.56.v20240826 9.4.57.v20241219
org.lz4:lz4-java CVE-2025-12183 🚨 HIGH 1.8.0 1.8.1

🛡️ TRIVY SCAN RESULT 🛡️

Target: Node.js

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: Python

Vulnerabilities (17)

Package Vulnerability ID Severity Installed Version Fixed Version
Werkzeug CVE-2024-34069 🚨 HIGH 2.2.3 3.0.3
aiohttp CVE-2025-69223 🚨 HIGH 3.12.12 3.13.3
aiohttp CVE-2025-69223 🚨 HIGH 3.13.2 3.13.3
apache-airflow CVE-2025-68438 🚨 HIGH 3.1.5 3.1.6
apache-airflow CVE-2025-68675 🚨 HIGH 3.1.5 3.1.6
azure-core CVE-2026-21226 🚨 HIGH 1.37.0 1.38.0
jaraco.context CVE-2026-23949 🚨 HIGH 5.3.0 6.1.0
jaraco.context CVE-2026-23949 🚨 HIGH 5.3.0 6.1.0
pyasn1 CVE-2026-23490 🚨 HIGH 0.6.1 0.6.2
ray CVE-2025-62593 🔥 CRITICAL 2.47.1 2.52.0
starlette CVE-2025-62727 🚨 HIGH 0.48.0 0.49.1
urllib3 CVE-2025-66418 🚨 HIGH 1.26.20 2.6.0
urllib3 CVE-2025-66471 🚨 HIGH 1.26.20 2.6.0
urllib3 CVE-2026-21441 🚨 HIGH 1.26.20 2.6.3
wheel CVE-2026-24049 🚨 HIGH 0.45.1 0.46.2
wheel CVE-2026-24049 🚨 HIGH 0.45.1 0.46.2
wheel CVE-2026-24049 🚨 HIGH 0.45.1 0.46.2

🛡️ TRIVY SCAN RESULT 🛡️

Target: /etc/ssl/private/ssl-cert-snakeoil.key

No Vulnerabilities Found

🛡️ TRIVY SCAN RESULT 🛡️

Target: /home/airflow/openmetadata-airflow-apis/openmetadata_managed_apis.egg-info/PKG-INFO

No Vulnerabilities Found

@gitar-bot

gitar-bot Bot commented Jan 23, 2026 •

Copy link
Copy Markdown
🔍 CI failure analysis for b2cac45: All CI failures are unrelated to PR changes. PR modifies only BigQuery Python backend code, while failures occur in frontend UI tests and PostgreSQL auto-classification tests, indicating pre-existing infrastructure/flakiness issues.

Issue

Python test jobs (py-run-tests 3.10 and 3.11) failed with 1 test failure:

  • test_it_returns_the_expected_classifications in ingestion/tests/integration/auto_classification/test_tag_processor.py

Multiple Playwright CI jobs have failed across different shards:

  • Job 3/6 (61262114554): 4 hard failures, 9 flaky tests, 541 passed
  • Job 4/6: 1 hard failure, 17 flaky tests
  • Job 6/6: 3 hard failures, 12 flaky tests

Playwright Job 3/6 Specific Failures (Latest)

4 Hard Failures:

  1. MutuallyExclusiveColumnTags test (MutuallyExclusiveColumnTags.spec.ts:33) - "Should show error toast when adding mutually exclusive tags to column" - 60s timeout on page.click
  2. Table glossary consistency tests (Table.spec.ts:543, Table.spec.ts:649) - "Tags and glossary terms should be consistent for search" - Target page/browser closed errors
  3. Schema table test (SchemaTable.spec.ts:205) - "Copy column link should have valid URL format" - expect(locator).toContainText() assertion failed

9 Flaky Tests: Including permissions tests, widgets tests, explore/discovery tests, and metric expression tests

Additional Failures from Job 6/6

3 Hard Failures:

  1. InputOutputPorts tests (InputOutputPorts.spec.ts) - Issues with removing single output port, section collapse/expand, independent port collapse
  2. Lineage test (Lineage.spec.ts:631) - Cycle detection should be handled properly
  3. Tag test (Tag.spec.ts:558) - "Add and Remove Assets and Check Restricted Entity" with limited EditTag permissions

12 Flaky Tests: Multiple glossary tests, tag classification page tests, permission-related tests

Root Cause

All CI failures are NOT related to the PR changes because:

  • PR Changes: Only modifies 6 Python files in BigQuery ingestion:

    • ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py
    • ingestion/src/metadata/ingestion/source/database/bigquery/helper.py
    • ingestion/src/metadata/ingestion/source/database/bigquery/queries.py
    • ingestion/src/metadata/ingestion/source/database/bigquery/incremental_table_processor.py
    • ingestion/tests/unit/test_handle_partitions.py
    • ingestion/tests/unit/topology/database/test_bigquery.py
  • Python Test Failure: Tests PostgreSQL auto-classification functionality - no shared code with BigQuery ingestion optimization

  • Playwright Test Failures: All are frontend UI tests (React/TypeScript) for tags, glossary, lineage, permissions, widgets - completely separate from backend Python ingestion code

Common failure patterns indicating environment/infrastructure issues:

  1. Timeout errors - Multiple 60s timeouts during page loads and API responses (page.click, page.goto, page.waitForResponse)
  2. Flaky tests - 38+ flaky tests across all jobs (9 + 17 + 12) indicating timing/race condition issues
  3. Browser closure errors - "Target page, context or browser has been closed" errors suggest infrastructure/resource problems
  4. Visibility/element assertion failures - Elements not appearing when expected (classic UI test flakiness)
  5. File system errors - ENOENT errors for certificate files with malformed paths

Details

Test Infrastructure Context

Python Tests: 519 passed, 1 failed, 21 skipped, 1 xfailed, 1367-1398 warnings

Aggregate Playwright Test Results (Jobs 3, 4, 6):

  • ✅ ~2600+ tests passed across all jobs
  • ⚠️ 38+ tests flaky (9 + 17 + 12)
  • ❌ 8+ unique test failures (4 + 1 + 3)
  • ⏭️ Multiple tests skipped

Evidence these are pre-existing/environment issues:

  1. Zero code overlap between BigQuery Python backend changes and failing frontend UI tests
  2. Multiple timeout errors (60s) suggest infrastructure/environment problems rather than code bugs
  3. High flaky test count (38+) indicates test infrastructure instability
  4. Browser closure errors suggest resource exhaustion or instability in CI environment
  5. Tests pass locally but fail in CI environment (timing, resource, network issues)

Recommendation: These failures should be investigated separately from this PR. The BigQuery ingestion optimization changes are isolated to the BigQuery connector backend code and cannot affect frontend UI test behavior or PostgreSQL auto-classification tests.

Code Review 👍 Approved with suggestions 2 resolved / 5 findings

Well-structured optimization PR with significant performance improvements. Previous concerns around thread safety, SQL injection risk, and cache validation remain unaddressed.

⚠️ Edge Case: `get_dataset_obj` cache doesn't validate schema name matches

📄 ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py:340-345

The get_dataset_obj method caches the dataset object in _current_dataset_obj but doesn't validate that the cached object corresponds to the requested schema_name:

def get_dataset_obj(self, schema_name: str):
    """Get dataset object with per-schema caching"""
    if self._current_dataset_obj is None:
        database = self.context.get().database
        self._current_dataset_obj = self.client.get_dataset(
            f"{database}.{schema_name}"
        )
    return self._current_dataset_obj

If this method is called with a different schema_name after the cache is populated, it will return the wrong dataset object. The cache is cleared in query_table_names_and_types when iterating schemas, but if get_dataset_obj is called outside that flow with a different schema, it could return stale data.

Suggested fix: Store the schema name alongside the cached object and validate it:

def get_dataset_obj(self, schema_name: str):
    if self._current_dataset_obj is None or self._current_dataset_schema != schema_name:
        database = self.context.get().database
        self._current_dataset_obj = self.client.get_dataset(f"{database}.{schema_name}")
        self._current_dataset_schema = schema_name
    return self._current_dataset_obj
⚠️ Bug: SQL injection risk: `schema_name` used directly in WHERE clause

📄 ingestion/src/metadata/ingestion/source/database/bigquery/queries.py:198-208

The BIGQUERY_GET_TABLE_DDLS query uses string formatting with schema_name directly in a WHERE clause string comparison:

SELECT table_name, ddl
FROM `{database_name}`.`{schema_name}`.INFORMATION_SCHEMA.TABLES
WHERE table_schema = '{schema_name}'
  AND table_catalog = '{database_name}'
  AND table_type IN ('BASE TABLE', 'EXTERNAL')

While the backtick-quoted identifiers in FROM are safe, the WHERE table_schema = '{schema_name}' uses single quotes, which could be vulnerable to SQL injection if schema_name contains special characters like '.

BigQuery schema names are typically restricted, but this pattern is risky. Consider using parameterized queries or at minimum escaping the values. The same applies to database_name.

Note: The existing BIGQUERY_CONSTRAINTS query also uses {project_id} and {dataset_name} in a similar pattern but only in backtick-quoted identifiers which is safer.

More details 💡 1 suggestion ✅ 2 resolved
💡 Quality: Global mutable state with `CONSTRAINT_CACHE` needs thread-safety consideration

📄 ingestion/src/metadata/ingestion/source/database/bigquery/helper.py:21-26

The CONSTRAINT_CACHE is a global dictionary that could have thread-safety issues if multiple BigQuery sources run concurrently:

CONSTRAINT_CACHE = {}

def clear_constraint_cache():
    global CONSTRAINT_CACHE
    CONSTRAINT_CACHE.clear()

While the previous implementation also had global caches (FK_CACHE, PK_CACHE), consolidating them into one doesn't change this. If this is expected to run in a multi-threaded environment, consider using threading.Lock() or instance-level caching instead of global state.

This is a pre-existing design pattern, so it's minor for this PR, but worth noting for future improvements.

✅ Bug: Cache cleared before `_prefetch_table_ddls` - DDL cache won't persist

📄 ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py:286
In query_table_names_and_types, _prefetch_table_ddls(schema_name) is called on line 405, but clear_constraint_cache_for_schema is called after. However, the more significant issue is in the method flow:

self._current_schema_tables.clear()  # line 283
self._current_dataset_obj = None
self._prefetch_table_ddls(schema_name)  # Called AFTER clearing
clear_constraint_cache_for_schema(database, schema_name)

This order is correct, but _prefetch_table_ddls itself calls self._table_ddl_cache.clear() at the beginning (line 401), which means the DDL cache is cleared on every schema iteration anyway. This is fine for the first schema but potentially wasteful if there are cross-schema DDL lookups. More critically, if get_schema_definition is called for a table before query_table_names_and_types completes iteration (unlikely but possible in async scenarios), DDLs won't be available.

The main concern: ensure _prefetch_table_ddls is always called before any table processing for that schema.

✅ Edge Case: View definition fallback logic handles both view types correctly

📄 ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py:837-843
The condition getattr(table_obj, "view_query", None) will be falsy for an empty string, which triggers the fallback correctly. The logic sequence checks view_query first, then mview_query:

if getattr(table_obj, "view_query", None):
    return f"CREATE VIEW {schema_name}.{table_name} AS {table_obj.view_query}"
elif getattr(table_obj, "mview_query", None):
    return f"CREATE MATERIALIZED VIEW {schema_name}.{table_name} AS {table_obj.mview_query}"

Note: For a MaterializedView table type, if mview_query is missing but view_query exists (unlikely), it would return a CREATE VIEW statement instead of MATERIALIZED VIEW. Consider checking table_type first to ensure the correct DDL prefix is used.

What Works Well

Good caching strategy with clear cache-per-schema lifecycle. API-based table listing is more efficient than SQL queries. Pre-fetching policy tags and DDLs reduces per-item API calls.

Recommendations

Consider using parameterized queries for BIGQUERY_GET_TABLE_DDLS to avoid SQL injection. Add thread safety to CONSTRAINT_CACHE if concurrent access is possible.

Rules ✅ All requirements met

Gitar Rules

✅ Summary Enhancement: Summary accurately reflects all major optimization changes

2 rules not applicable. Show all rules by commenting gitar display:verbose.

Tip

Comment Gitar fix CI or enable auto-apply: gitar auto-apply:on

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@harshsoni2024 harshsoni2024 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.

lgtm, let's check if this is concerning
#25471 (comment)

@pmbrull
pmbrull merged commit a992867 into main Jan 23, 2026
@pmbrull
pmbrull deleted the issue-25359 branch January 23, 2026 15:05
@github-actions

Copy link
Copy Markdown
Contributor

Changes have been cherry-picked to the 1.11.7 branch.

This branch had an error being deployed

1 failed deployment
test — b2cac450 Deployed Jan 23, 2026 by keshavmohta09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigQuery Ingestion Performance Optimization

3 participants