Add powermglot: Power Query M parser + transpiler; integrate into pbi2dbr#1
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/brookpatten/daxglot/sessions/3915aeb1-9fc4-4800-9d1d-8989bb5f022e Co-authored-by: brookpatten <518287+brookpatten@users.noreply.github.com>
Agent-Logs-Url: https://github.com/brookpatten/daxglot/sessions/3915aeb1-9fc4-4800-9d1d-8989bb5f022e Co-authored-by: brookpatten <518287+brookpatten@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add powermglot library for powerM parser
Add powermglot: Power Query M parser and SQL transpiler
Mar 30, 2026
Agent-Logs-Url: https://github.com/brookpatten/daxglot/sessions/d416e4a0-3a76-4892-9787-efc4ab71aecc Co-authored-by: brookpatten <518287+brookpatten@users.noreply.github.com>
Copilot
AI
changed the title
Add powermglot: Power Query M parser and SQL transpiler
Add powermglot: Power Query M parser + transpiler; integrate into pbi2dbr
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a proper Power Query M parser (
powermglot) as a new workspace library and replacespbi2dbr's regex-based M expression handling with it.powermglot— new workspace libraryA recursive-descent M parser and sqlglot-backed SQL transpiler for
let…inchain expressions.Architecture:
lexer.py— full M tokeniser: keywords,#"quoted identifiers",""escaped strings, all operatorsast_nodes.py— dataclass AST (LetExpr,CallExpr,NavExpr,EachExpr,BinaryOpExpr, …)parser.py— recursive-descent parser: nestedlet,each,if/then/else, dotted function names,{[Name=…]}[Data]navigation chainstranspiler.py— walks theletbinding graph (following variable references) and emits a sqlglotSELECTSupported M → SQL mappings:
{[Name=…]}[Data]chain (2–3 levels)FROM catalog.schema.tableTable.SelectRows(t, each predicate)WHERE(and/or/not)Table.SelectColumns/RenameColumns/AddColumn/RemoveColumnsTable.GroupGROUP BY+ aggregationsTable.NestedJoin/Table.JoinJOINValue.NativeQuery(src, "sql")parse_m_source— extraction API for embeddersA safe, never-raising entry point that returns a
MSourceInfo(source_ref, native_sql, filter_sql)without generating SQL — designed for use by data-source extractors.pbi2dbrintegrationpbi2dbrnow depends onpowermglot(workspace dependency). The three M-resolution functions inextractor.pyuseparse_m_sourceas primary with the existing regex logic as fallback for patterns powermglot cannot yet parse (e.g.{[Item="x"][Kind="Table"]}navigation style):PbixExtractor._resolve_uc_ref()— powermglot resolves the table ref; applies default catalog/schema to fill in missing parts_extract_filter_expr()— powermglot extractsTable.SelectRowspredicates via the AST; handles nested let chains and variable references the regex cannot_extract_native_query_sql()— powermglot extractsValue.NativeQuerySQL directly from the parsed AST⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.