Fix LookML ${view.field} reference resolution and cycle handling#242
Fix LookML ${view.field} reference resolution and cycle handling#242nicosuave wants to merge 1 commit into
Conversation
345f8c2 to
00ff35d
Compare
6093f6f to
af2d6ba
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af2d6ba158
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| self._parse_explore(explore_def, graph) | ||
|
|
||
| # Matches ${field} and ${view.field}. ${TABLE} is handled specially. | ||
| _REF_RE = re.compile(r"\$\{(?:([a-zA-Z_]\w*)\.)?([a-zA-Z_]\w*)\}") |
There was a problem hiding this comment.
Apply dotted-ref handling to number measures
This new dotted-reference resolver is not used by the type: number measure path, which still applies the old bare-only regex in _parse_measure. In a LookML view with a derived number measure such as measure: margin_pct { type: number sql: ${customers.total} / ${orders.total} ;; }, the self-view ref is normalized but the cross-view ref remains a literal ${customers.total}, so generated SQL still contains invalid LookML syntax despite the new cross-view handling. Route that branch through the same dotted-reference resolver or explicitly handle the two-part match there.
Useful? React with 👍 / 👎.
The reference resolver regex (${name}) never matched dotted refs, so:
- self-view-qualified refs (${this_view.field}) leaked the literal ${...}
into generated SQL (a hard syntax error); for measures it also broke the
metric. Real models (e.g. the GA360 block) use this form pervasively.
- cross-view refs (${other_view.field}) likewise leaked literally.
- chains deeper than 10 silently truncated; self-references expanded 10x.
Normalize self-view qualifiers to bare refs before resolution, make both
resolvers dotted-ref aware (cross-view -> qualified column + warning, since
sidemantic cannot represent an inline cross-model column), and replace the
fixed depth cap with cycle detection so acyclic chains of any depth resolve
and circular refs terminate.
Note: cross-view field references remain a modeling gap (sidemantic has no
inline cross-model column); the adapter now emits a qualified column and
warns instead of producing invalid ${...} SQL.
af2d6ba to
5efe508
Compare
Summary
Part of the LookML adapter correctness series. Stacked on #241 (base =
fix/lookml-filters).The reference resolver's regex
\${name}never matched dotted references, so any${view.field}leaked the literal${...}into generated SQL — a guaranteed database syntax error. Confirmed firsthand: the canonical GA360 block fixture left 26 fields unresolved.Changes
${this_view.field}) are normalized to${field}before resolution, so they resolve like bare refs (common in machine-generated LookML).${other_view.field}) now emit a qualified columnview.fieldplus a warning, instead of leaking${...}.Known limitation
Cross-view field references are a deeper modeling gap: sidemantic cannot represent an inline cross-model column (the generator emits
customers.nameagainstFROM orderswith no join). This PR stops the silent invalid-SQL leak and surfaces a warning; full support is a separate effort.