Repository navigation
Fixes #29504: Stop cutting PowerBI BigQuery native query SQL at comment markers [Backport #36207 - 2.0] - #36232
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. (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)
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
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 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 |
|



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.NativeQueryby 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 theFROMwith 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 reachesLineageParseras 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_sourcematches main's apart from its signature line (Optional[List[dict]] # noqa: UP006, UP045), which the change does not touch.test_powerbi_bigquery_native_query.pyis byte-identical to #36207's.Everything the change relies on is already on 2.0 and behaves as on main:
_get_table_and_datamodel_lineage→_parse_table_info_from_source_exp→_parse_bigquery_source→_parse_bigquery_query_source.LineageParser.clean_raw_querydiffers from main's only in its type hint, so it also keeps line breaks and leaves comments to the parsers.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.Databaseextractors 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 pinnedpytest==7.0.1and 2.0's pinnedcollate-sqllineage==2.1.7:test_powerbi.py59,test_powerbi_bigquery_native_query.py5,test_powerbi_client.py14,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_powerbi_filter_query.py10 andtest_powerbi_table_measures.py13. 196 passed, 0 failed.metadata.pyandconstants.pyput 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.re.DOTALLdropped;//strip, or the--strip, put back;test_parse_database_source.constants.py100% andmetadata.py64%; the rest ofmetadata.pyis untouched.tests/unit/topology/dashboard:-n 4 --dist loadfile.test_domodashboard.pyandtest_ssrs.py, which can't importpydomoandrequests_ntlmlocally.test_dashboard_owned_connection.py.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.ruff checkandruff format --checkpass with 2.0's config. basedpyright (--baselinemode=discard) reports 0 errors onmetadata.pyandconstants.py. 2.0 has nocheck_ruff_suppressions.py.Self-review:
c3ee39ca4e5was reviewed with fresh context against main'sREVIEW.md(2.0 has none). The review focused on what can differ on 2.0: the lineage stage's callers of the changed method,LineageParserand 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:
🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Fixes Power BI lineage extraction for BigQuery native queries.
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]Reviews (1) · Last reviewed commit: "test(powerbi): spread the block-commente..." · Reviewed by Greptile