Skip to content

Fixes #29504: Stop cutting PowerBI BigQuery native query SQL at comment markers [Backport #36207 - 2.0] - #36232

Merged
harshsoni2024 merged 3 commits into
2.0from
backport-36207-2.0
Oct 26, 2026
Merged

harshsoni2024 merged 3 commits into
2.0from
backport-36207-2.0

Conversation

@harshsoni2024

@harshsoni2024 harshsoni2024 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Backport of #36207 to 2.0. It picks the PR's three commits (6d6e89c0d5f, f8eec1699d8, 2fa90bd34dc) and fixes #29504 on 2.0. #36207 is still open, so any change made to it in review needs picking here too.

PowerBI finds the upstream tables of a table backed by a BigQuery Value.NativeQuery by pulling the SQL out of the M expression and parsing it. The extractor stripped --, // and /* */ with regexes that cannot tell a comment from a string literal, then flattened the SQL onto one line. So a literal such as '--', 'https://…' or 'exports/*.csv' cut the query, and a BigQuery # comment ran to its end. When the cut took the FROM with it, the table resolved no upstream table, and its data model got no lineage. The M comment strip now skips M text literals, and the SQL reaches LineageParser as written, with its line breaks and comments. #36207 explains the approach, and why the issue's own expression already gets its lineage through the SqlParse fallback.

Differences from #36207

None. The three picks applied without conflicts, and each has the same patch-id as its commit on #36207. 2.0's _parse_bigquery_query_source matches main's apart from its signature line (Optional[List[dict]] # noqa: UP006, UP045), which the change does not touch. test_powerbi_bigquery_native_query.py is byte-identical to #36207's.

Everything the change relies on is already on 2.0 and behaves as on main:

  • The data model lineage stage reaches the changed method the same way: _get_table_and_datamodel_lineage → _parse_table_info_from_source_exp → _parse_bigquery_source → _parse_bigquery_query_source.
  • LineageParser.clean_raw_query differs from main's only in its type hint, so it also keeps line breaks and leaves comments to the parsers.
  • 2.0 pins collate-sqllineage==2.1.7 (main: 2.1.8), with the same sqlparse 0.6.0, sqlglot 29.0.1 and collate-sqlfluff 3.5.3. The tests below ran with 2.1.7.

As on main, the Snowflake, Databricks and SQL Server Sql.Database extractors are not changed; #36207 describes what they still get wrong.

Tests

Run locally on this branch, with 2.0's own generated models, PYTHONPATH=src, CI's pinned pytest==7.0.1 and 2.0's pinned collate-sqllineage==2.1.7:

  • Unit tests covering the changed files. These are the new file plus every test importing a changed module: test_powerbi.py 59, test_powerbi_bigquery_native_query.py 5, test_powerbi_client.py 14, test_powerbi_report_pages.py 17, test_powerbi_resilience.py 17, test_powerbi_workspace_state.py 12, test_dashboard_owned_connection.py 5, source/dashboard/powerbi/test_connection.py 39, test_file_client_path_traversal.py 5, test_powerbi_filter_query.py 10 and test_powerbi_table_measures.py 13. 196 passed, 0 failed.
  • Fail without the fix. With 2.0's original metadata.py and constants.py put back, 4 of the 5 new tests fail, as on main: the table resolves no upstream table. The fifth, test_block_commented_source_step_is_ignored, passes there too; it guards the block-comment half of the new pattern.
  • Mutations. The 7 single-change reverts from Fixes #29504: Stop cutting PowerBI BigQuery native query SQL at comment markers #36207 each fail the same tests on 2.0:
    • the literal-unaware M comment strip;
    • a literal-unaware block-comment strip run ahead of the new pattern;
    • the block-comment alternative dropped, or re.DOTALL dropped;
    • the SQL // strip, or the -- strip, put back;
    • newline flattening put back, which also fails the existing test_parse_database_source.
  • Coverage. Every changed executable line is covered. File totals are constants.py 100% and metadata.py 64%; the rest of metadata.py is untouched.
  • Whole dashboard suite. 2.0 still shares one topology context across dashboard sources, so I also ran all of tests/unit/topology/dashboard:
    • In one process, 701 passed on this branch and 696 on untouched 2.0, with 0 failed on both. This branch also gives 701 passed with -n 4 --dist loadfile.
    • The 2 errors on both are test_domodashboard.py and test_ssrs.py, which can't import pydomo and requests_ntlm locally.
    • The new file also passes before and after each of the other PowerBI test files and test_dashboard_owned_connection.py.
  • Integration. tests/integration/powerbi/test_powerbi_file_client.py: 1 passed. It is the only PowerBI integration test on 2.0, and it covers the file client, not lineage.
  • Static checks. ruff check and ruff format --check pass with 2.0's config. basedpyright (--baselinemode=discard) reports 0 errors on metadata.py and constants.py. 2.0 has no check_ruff_suppressions.py.

Self-review: c3ee39ca4e5 was reviewed with fresh context against main's REVIEW.md (2.0 has none). The review focused on what can differ on 2.0: the lineage stage's callers of the changed method, LineageParser and the parser stack 2.0 pins, the test fixture's patch targets, and the shared topology context. It found no 🔴 and no 🟡.

Type of change:

  • Bug fix

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Fixes Power BI lineage extraction for BigQuery native queries.

  • BigQuery native queries keep their source tables in Power BI lineage.

No actionable issues were found. This review inspected code and tests; it did not run the tests.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Power BI M expression] --> B[Remove M comments outside text literals]
    B --> C[Extract and unescape SQL]
    C --> D[Keep SQL comments and line breaks]
    D --> E[LineageParser with BigQuery dialect]
    E --> F[Upstream tables]
Loading

Reviews (1) · Last reviewed commit: "test(powerbi): spread the block-commente..." · Reviewed by Greptile

…nt markers

_parse_bigquery_query_source stripped -- and // from the native query SQL,
and /* */ and // from the whole M expression, with regexes that cannot tell
a comment from a string literal, then flattened the SQL onto one line. A
literal such as '--' or 'https://...' cut the query, and a BigQuery #
comment ran to its end. A table whose FROM was cut resolved no upstream
table, so its data model got no lineage.

The M comment strip now matches M text literals first and keeps them, and
the SQL reaches LineageParser as written, with its line breaks and
comments. The parsers know where a literal ends.

(cherry picked from commit 6d6e89c)
Dropping /\*.*?\*/ from the pattern, or stripping block comments ahead of
it without regard to literals, left every test green. A block-commented
Source step above the live one, and a '/*' inside a SQL literal before
FROM, now fail under each of those.

(cherry picked from commit f8eec16)
With the comment on one line, dropping re.DOTALL from the M comment strip
left every test green.

(cherry picked from commit 2fa90bd)
@harshsoni2024
harshsoni2024 requested a review from a team as a code owner October 26, 2026 10:09
@harshsoni2024
harshsoni2024 requested review from ulixius9 and removed request for a team October 26, 2026 10:09
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@harshsoni2024 harshsoni2024 added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Oct 26, 2026
@gitar-bot

gitar-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Preserving SQL comments and line breaks in PowerBI BigQuery extraction could change parsed lineage, causing upstream tables to be omitted or misidentified.

Stops the PowerBI BigQuery native query extractor from cutting SQL at --, //, and /* */ sequences inside string literals, and keeps line breaks so LineageParser receives the query as written. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@harshsoni2024
harshsoni2024 enabled auto-merge (squash) October 26, 2026 12:59
@harshsoni2024
harshsoni2024 merged commit e067dba into 2.0 Oct 26, 2026
98 of 113 checks passed
@harshsoni2024
harshsoni2024 deleted the backport-36207-2.0 branch October 26, 2026 13:10
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants