Skip to content

Fix query rewrite rules to match by source table, not cube name#34

Merged
acmeguy merged 1 commit intomainfrom
fix/query-rewrite-table-resolution
Mar 29, 2026
Merged

Fix query rewrite rules to match by source table, not cube name#34
acmeguy merged 1 commit intomainfrom
fix/query-rewrite-table-resolution

Conversation

@acmeguy
Copy link
Copy Markdown

@acmeguy acmeguy commented Mar 29, 2026

Summary

  • extractTableName(): New function that resolves the source table from meta.source_tablesql_table → SQL FROM clause. This ensures rules like semantic_events.partition = team.partition apply to ALL cubes backed by that table (e.g. SemanticEvents, semantic_events, RentalEvent) regardless of cube naming.
  • Block on missing dimension: If a cube is backed by a ruled table but lacks the required dimension, the query is now blocked instead of silently skipping the rule. Dropping a dimension must not bypass access control.

Problem

Rules stored cube_name = "semantic_events" (the table name). But buildCubeToTableMap only mapped cubes with meta.source_table set. The hand-written SemanticEvents cube (capital S, no meta) fell back to using the cube name for rule lookup — SemanticEvents != semantic_events — so the partition filter was never applied. Teams like somi.is could see bluecar.is data and vice versa.

Test plan

  • Verified extractTableName resolves SemanticEvents (sql: SELECT * FROM cst.semantic_events) → semantic_events
  • Full end-to-end simulation: rule applied as SemanticEvents.partition equals ["somi.is"]
  • Security test: cube without partition dimension → query blocked (not skipped)
  • Unruled tables pass through unaffected

🤖 Generated with Claude Code

Rules target table names (e.g. "semantic_events") but buildCubeToTableMap
only mapped cubes that had meta.source_table set. Cubes like SemanticEvents
with sql: "SELECT * FROM cst.semantic_events" but no meta.source_table
were falling back to the cube name, which didn't match the rule.

New extractTableName() resolves the table from:
1. meta.source_table (explicit)
2. sql_table property (strip schema prefix)
3. sql FROM clause (regex parse)

Also: if a cube is backed by a ruled table but lacks the required
dimension, the query is now blocked instead of silently skipping the
rule — dropping a dimension must not bypass access control.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@acmeguy acmeguy merged commit c7a11d4 into main Mar 29, 2026
3 checks passed
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.

2 participants