Skip to content

Fix PowerBI BigQuery native query parsing for comment-like literals - #29946

Closed
reachsrinivaschennupati-tech wants to merge 4 commits into
open-metadata:mainfrom
reachsrinivaschennupati-tech:fix/powerbi-bigquery-nativequery-comment-literals
Closed

reachsrinivaschennupati-tech wants to merge 4 commits into
open-metadata:mainfrom
reachsrinivaschennupati-tech:fix/powerbi-bigquery-nativequery-comment-literals

Conversation

@reachsrinivaschennupati-tech

@reachsrinivaschennupati-tech reachsrinivaschennupati-tech commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

#29504
PowerBI BigQuery Value.NativeQuery parsing stripped -- sequences with a regex before SQL lineage extraction. That removed valid SQL string literal content when a query contained values such as '--', "contains -- text", or escaped quotes before comment-like text.

Solution

  • Replace regex-only SQL line comment removal with a small scanner that skips -- comments only outside quoted SQL literals.
  • Preserve doubled SQL quotes and backslash-escaped quote characters while tracking quoted strings.
  • Preserve existing Power Query unescaping and BigQuery lineage parsing behavior.
  • Add regression coverage for BigQuery native queries with -- inside string literals and escaped quotes before comment-like text.

Validation

  • python -m pytest ingestion/tests/unit/topology/dashboard/test_powerbi.py::PowerBIUnitTest::test_parse_database_source ingestion/tests/unit/topology/dashboard/test_powerbi.py::PowerBIUnitTest::test_strip_sql_line_comments_preserves_backslash_escaped_quotes -q

Fixes #29504

Greptile Summary

This PR fixes PowerBI BigQuery native query parsing when SQL literals contain comment-like text. The main changes are:

  • A scanner replaces regex-only removal of SQL -- comments.
  • Quoted SQL literals keep embedded -- text during lineage extraction.
  • BigQuery triple-quoted literals and escaped delimiters are covered by tests.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py Adds scanner-based SQL comment stripping for BigQuery native queries while preserving quoted literal content.
ingestion/tests/unit/topology/dashboard/test_powerbi.py Adds tests for dash literals, triple-quoted literals, and escaped triple delimiters.

Reviews (5): Last reviewed commit: "Handle escaped BigQuery triple quote del..." | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - openmetadata-ui-core-components/CLAUDE.md (source)
  • Context used - AGENTS.md (source)

@reachsrinivaschennupati-tech
reachsrinivaschennupati-tech requested a review from a team as a code owner July 10, 2026 23:24
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@reachsrinivaschennupati-tech reachsrinivaschennupati-tech changed the title Fix PowerBI BigQuery NativeQuery comment parsing Fix PowerBI BigQuery native query parsing for comment-like literals Jul 10, 2026
@reachsrinivaschennupati-tech
reachsrinivaschennupati-tech force-pushed the fix/powerbi-bigquery-nativequery-comment-literals branch from d5b4a76 to dd6825d Compare July 11, 2026 00:18
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@reachsrinivaschennupati-tech

Copy link
Copy Markdown
Contributor Author

Hi Mantainers,

The latest commit has been pushed and the focused PowerBI tests pass locally. The current py-tests failure appears to be from the pull_request_target label gate: the workflow stops at “Verify PR labels” because the PR does not yet have the safe to test label, so checkout and integration tests are skipped.

Could a maintainer please apply safe to test when ready so CI can run against the updated commit?

Thanks

@reachsrinivaschennupati-tech

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The code changes and tests are ready. I do not have permission to add issue #29504 to the Shipping project, so could a maintainer please add it there or apply the skip-pr-checks label if appropriate?

@IceS2
IceS2 requested a review from mohittilala July 17, 2026 13:39
@mohittilala

Copy link
Copy Markdown
Contributor

Thanks for opening the PR.

Stepping back, I don't think this is the right way to solve the problem, and I'd suggest we close it rather than keep iterating.

The goal here, "strip -- comments but not when they appear inside a string literal", can't really be done safely with a regex or a small scanner. To get it right you'd have to correctly track single / double / backtick quotes, escaped quotes, doubled quotes, triple-quoted strings, and those rules vary by SQL dialect. That's effectively hand-writing a SQL tokenizer, and it's unbounded. The review already surfaced backslash escapes, triple quotes and escaped delimiters, and there are still cases it doesn't cover (for example #-style comments, or -- and // sitting inside other literals like a URL). Each one is another special case bolted on, and the scanner will keep growing them.

A bespoke comment/literal scanner like this isn't something we want to take on and maintain. The edge cases here are genuinely endless. I would lean to closure of this approach than moving forward.

@mohittilala mohittilala self-assigned this Jul 21, 2026
@gitar-bot

gitar-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Replaces regex-based SQL comment stripping with a scanner to correctly identify comments outside of quoted literals. No issues found.

✅ 1 resolved
✅ Edge Case: Backslash-escaped quotes not handled in string literal scan

📄 ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py:1105-1119
_strip_sql_line_comments tracks string literals by matching quote characters and treats a doubled quote ('') as an escaped quote. However, BigQuery Standard SQL also permits backslash escaping inside string literals, e.g. WHERE name = 'O\'Brien -- x'. When the scanner hits the \' it will see char == quote_char with a following non-quote character and close the literal prematurely (quote_char = None). Any -- appearing later inside what is actually still a string literal would then be stripped as a comment, and lineage parsing could truncate/corrupt the query.

This is an improvement over the previous unconditional re.sub(r"--[^ ]*", "", ...), so it is not a regression, but backslash-escaped quotes are a real (if uncommon) BigQuery pattern. Consider handling a backslash escape by skipping the next character while inside a quoted region. A regression test with a backslash-escaped quote followed by -- would guard this.

Options

Display: compact → Showing less information.

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

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

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.

[PowerBI] BigQuery NativeQuery lineage lost: -- comment stripper truncates SQL string literals containing "--"

2 participants