Skip to content

Fix LookML ${view.field} reference resolution and cycle handling#242

Open
nicosuave wants to merge 1 commit into
fix/lookml-filtersfrom
fix/lookml-reference-resolver
Open

Fix LookML ${view.field} reference resolution and cycle handling#242
nicosuave wants to merge 1 commit into
fix/lookml-filtersfrom
fix/lookml-reference-resolver

Conversation

@nicosuave

Copy link
Copy Markdown
Member

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

  • Self-view refs (${this_view.field}) are normalized to ${field} before resolution, so they resolve like bare refs (common in machine-generated LookML).
  • Cross-view refs (${other_view.field}) now emit a qualified column view.field plus a warning, instead of leaking ${...}.
  • Cycle-safe resolution: replaced the fixed depth-10 cap (which silently truncated long chains and let self-refs expand 10x) with path-based cycle detection — acyclic chains of any depth resolve fully; circular refs terminate.
  • Regression tests for each case.

Known limitation

Cross-view field references are a deeper modeling gap: sidemantic cannot represent an inline cross-model column (the generator emits customers.name against FROM orders with no join). This PR stops the silent invalid-SQL leak and surfaces a warning; full support is a separate effort.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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*)\}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
@nicosuave nicosuave force-pushed the fix/lookml-reference-resolver branch from af2d6ba to 5efe508 Compare June 26, 2026 20:02
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.

1 participant