Repository navigation
Fixes #29504: Stop cutting PowerBI BigQuery native query SQL at comment markers - #36207
Conversation
…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.
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.
With the comment on one line, dropping re.DOTALL from the M comment strip left every test green.
Code Review ✅ Approved🟡 Medium risk · Preserving SQL comments and line breaks in PowerBI BigQuery lineage parsing could misattribute upstream tables if the parser interprets them unexpectedly. Stops the PowerBI BigQuery native query parser from cutting SQL at comment markers that appear inside string literals, such as VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
…- comments end at their line (#36748) _extract_tables_from_sql turned #(lf) into newlines and then collapsed all whitespace onto one line before calling LineageParser. A -- comment then ran to the end of the query, so every table after it was dropped from lineage. The SQL now reaches LineageParser with its line breaks, as the BigQuery native query path already does since #36207.



Describe your changes:
Fixes #29504
PowerBI finds the upstream tables of a table backed by a BigQuery
Value.NativeQueryby pulling the SQL out of the M expression and parsing it._parse_bigquery_query_sourcecleaned that SQL with regexes that cannot tell a comment from a string literal, and then flattened it onto one line:--was stripped to the end of the line, so a literal such as'--'cut the query and left an unterminated string./* */and//were stripped from the whole M expression, the SQL literal included. A literal such as'https://…'or'gs://…'cut the M string, so the SQL was never found, and one such as'exports/*.csv'lost everything up to the next*/.#comment run to the end of the query.When the cut took the
FROMwith it, the table resolved no upstream table and its data model got no lineage. The M comment strip now matches M text literals first and keeps them, and the SQL reachesLineageParseras written, with its line breaks and comments. SqlGlot, SqlFluff and SqlParse know where a literal ends and where each BigQuery comment (--,#,/* */) ends.This needs no SQL tokenizer of our own, the approach #29946 was closed over: the SQL is no longer scanned for comments at all. M text literals have one syntax (
"…", with""as the only escape), so skipping them takes one exact pattern.The issue's own expression (
where ISO2 <> '--'on the last line) already gets its lineage onmain. SqlGlot and SqlFluff fail on the cut query, with theTokenError/IndexErrorand "partially unparsable" errors the issue quotes, but the SqlParse fallback still findsfull_CountriesTbl_Current_State. The same holds on 1.13.0.0 with the reporter's collate-sqllineage 2.1.3. So the regression tests use shapes that do lose lineage onmain. With this change the issue's expression reaches the parser intact, and SqlGlot parses it on the first try.Not changed: three other SQL extractors in this connector flatten the SQL onto one line the same way: the Snowflake native query parser (
_parse_snowflake_query_source), the Databricks one (parse_databricks_native_query_source), and_extract_tables_from_sql, which reads SQL ServerSql.Databasequeries for semantic-model tables and dataflows.--, so a real-- commenthides the rest of the query.select id, amount -- net of tax#(lf)from sales.ordersresolves no table on any of the three, while the same query without the comment resolvessales.orders.//from the SQL, so'https://…'beforeFROMresolves no table there.Those paths are untouched by this PR and have their own dialect rules (Snowflake treats
//as a comment), so they are left for a follow-up; no issue filed yet.Type of change:
High-level design:
N/A — small bug fix in one method; the approach is described above.
Tests:
Use cases covered
'--'in a literal beforeFROMresolves its upstream table.//('https://…') beforeFROMresolves its upstream table./*('exports/*.csv') beforeFROM, with a/* */comment after it, resolves its upstream table.#comment line no longer hides theFROMafter it.Sourcestep is still ignored, so lineage goes to the live query's table, not the commented-out one.--comments, and M/* */and//comments, including a commented-outValue.NativeQuerystep, still work: the existingtest_parse_database_sourcecases, unchanged.Unit tests
ingestion/tests/unit/topology/dashboard/test_powerbi_bigquery_native_query.py(5 tests). A realPowerbiSource, with only its connection patched, is driven through_parse_table_info_from_source_exp, which the data model lineage stage calls. Each literal case puts its marker beforeFROMon the same line, so a cut there leaves no table for the SqlParse fallback to find.main, 4 of the 5 fail: the table resolves no upstream table (None).test_block_commented_source_step_is_ignoredpasses onmain; it guards the block-comment half of the new pattern, which nothing else tests.[m-line-comment-marker]and[m-block-comment-marker];[m-block-comment-marker];re.DOTALLdropped from the strip:test_block_commented_source_step_is_ignored;//strip:[m-line-comment-marker];--strip:[sql-line-comment-marker];test_bigquery_hash_comment_ends_at_its_line, and the existingtest_parse_database_source, whose-- main tablecomment then hides theJOIN.test_powerbi.py59,test_powerbi_bigquery_native_query.py5,test_powerbi_client.py14,test_powerbi_metrics.py22,test_powerbi_report_pages.py17,test_powerbi_resilience.py17,test_powerbi_workspace_state.py12,test_dashboard_owned_connection.py5,source/dashboard/powerbi/test_connection.py39,test_file_client_path_traversal.py5,test_file_client_tmpdir.py6,test_powerbi_filter_query.py10,test_powerbi_table_measures.py13: 224 passed, 0 failed.pytest-cov): every changed executable line is covered. File totals areconstants.py100% andmetadata.py66%; the rest ofmetadata.pyis untouched.ruff check,ruff format --checkandscripts/check_ruff_suppressions.py --checkare clean. basedpyright (--baselinemode=discard) reports 0 errors onmetadata.pyandconstants.py.Backend integration tests
Ingestion integration tests
tests/integration/).tests/integration/powerbi/test_powerbi_file_client.py: 1 passed. It is the only PowerBI integration test, and it covers the file client, not lineage. No integration test added: the change is confined to parsing the M expression, before any API or server call, and the unit test drives that boundary with a real source.Playwright (UI) tests
Manual testing performed
No PowerBI dataset backed by a BigQuery native query was available. The M expressions were replayed through
_parse_bigquery_source, with the realLineageParser(collate-sqllineage 2.1.8), onmainand on this branch.The issue's expression, with debug logging:
main: the SQL handed toLineageParserendswhere ISO2 <> '(query hash33262d6d, the same as the production logs in Lineage: SQLParse & SQLGlot query masking and tokenization failures #28894). SqlGlot raisesTokenError(IndexError: string index out of range), SqlFluff reports "select_statement is partially unparsable", and the SqlParse fallback returnsfull_CountriesTbl_Current_State.where ISO2 <> '--'. SqlGlot parses it on the first try and returns the same table.Query shapes,
mainvs this branch:main'--'on the last line)'--'beforeFROM'--'in a CTE,JOINon later lines'https://…'literal'exports/*.csv'literal,/* */comment afterFROM#comment line--comment mid-query/* */and--comments in the SQLSourcestep above the live oneUI screen recording:
Not applicable — ingestion-only change.
Checklist:
I have read the CONTRIBUTING document.
My PR title is
Fixes <issue-number>: <short explanation>My PR is linked to a GitHub issue via
Fixes #<issue-number>above.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. Not applicable: no schema change.
For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable). Not applicable: ingestion-only change.
I have added tests (unit / integration / Playwright as applicable) and listed them above.
Self-review: I reviewed the final diff against
REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.Pass 1 on
6d6e89c0d5f: no 🔴. 🟡 the Snowflake, Databricks and_extract_tables_from_sqlpaths keep the same flattening and//strip: pre-existing and outside [PowerBI] BigQuery NativeQuery lineage lost: -- comment stripper truncates SQL string literals containing "--" #29504, stated under "Not changed" with the trigger inputs, re-run on this branch, and left for a follow-up. 🟡 the block-comment half of the new pattern had no test (dropping it, or running a literal-unaware block strip ahead of it, left every test green): fixed inf8eec1699d8, a test-only change that both mutants now fail. Pass 2 onf8eec1699d8: no 🔴. Noted, not a finding:re.DOTALLon the strip went untested, because the test's block comment sat on one line. The comment now spans lines (2fa90bd34dc), and dropping the flag fails the test. Pass 3 on2fa90bd34dc: no 🔴.Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under
docs/decisions/(see itsREADME.md). This description is gone fromgit logafter the squash-merge.Not applicable: a self-evident bug fix that sets no contract, default or ordering.
I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.
The tests cover the defect the issue reports, a
'--'literal cutting the SQL, in shapes that lose lineage onmain; the reported expression itself is rescued by SqlParse onmain(see above).🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable issue was found.Summary
This PR keeps comment markers inside BigQuery SQL strings from cutting off Power BI lineage queries.
The ancestry check passed, but the target merge bases differed. The full PR diff was therefore reviewed as the changes since the last review. No previous review threads were supplied. Tests were inspected, not run.
Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix-29504-power..." · Reviewed by Greptile