Exports and Field Visibility

How a package's index.malloy decides which sources callers can query, how public, internal and private decide which fields each source exposes, what to expose at each layer of a model, and how this differs from access rules

A model decides what callers can see at two grains, and both are set in the model:

GrainSet withControls
SourcesThe package's index.malloyWhich sources callers can query
Fieldspublic, internal, privateWhich fields each source exposes

Set both on every layer of the three-layer model, not only the top one. The examples below use the support model from that page.

Exports: index.malloy

Each package has one index.malloy. The sources it exports are the only ones callers can query:

import "support_performance.malloy"

export { support_performance }

A source that isn't exported still compiles and can be imported, joined and extended, but it is:

  • Not listed: people and agents browsing the package don't see it.
  • Not indexed on its own: its #(doc) and #(index) values don't enter the concept index or value search, except for fields an exported source joins in.
  • Refused by name: a query that names it fails as if the source doesn't exist.

The exports are the same for every caller, on every surface. Changing them requires publishing a new version.

Without an index.malloy, every source in the package can be queried. Add one to any package with layers beneath its domains.

Field Visibility

Prefix a definition with an access modifier, or set levels in an include block before extend. Access modifiers are an experimental Malloy feature, so turn them on at the top of every file that uses them:

##! experimental.access_modifiers

Without that line, Malloy refuses include blocks and the public, internal and private modifiers.

ModifierQueryableUsable in definitions
public✅✅
internal❌ by name, but a query can re-expose it✅ In this source and sources that extend it
private❌✅ In this source only

internal keeps a field off the source's public field list, but it doesn't protect the field: a query can still read it by extending the source (extend { dimension: e is first_response_hours }) or re-including it (include { public: first_response_hours }). Only private fields stay unreadable, so use private for anything sensitive.

See Access Modifiers (opens in a new tab) in the Malloy documentation for the full rules.

At the domain, the public fields are the source's interface: what callers can query and what the source's access rules apply to. In support_performance.malloy:

##! experimental.access_modifiers
import "core.malloy"

source: support_performance is ticket_core include {
  private: *
  internal: first_response_hours
  public: tenant, segment, priority, status, created_at,
          ticket_count, open_ticket_count, avg_first_response_hours
} extend {
  view: backlog_by_priority is {
    group_by: priority
    aggregate: open_ticket_count
  }
}
  • private: * hides every field by default, so a column added to the table later stays hidden until it is listed.
  • internal: first_response_hours keeps the field available to avg_first_response_hours and off the public field list.
  • public: lists the eight fields callers can query. Querying any other field by name is a compile error.

An include block can also list what to hide, such as include { except: customer_email, credit_card_number }. Use the form that lists what to show for sensitive data, so new columns aren't exposed automatically.

What to Expose at Each Layer

LayerMake publicMake internal or private
Base sourcesThe table's concepts, such as first_response_hoursRaw columns and inputs to derived fields, such as first_response_minutes, ETL ids and deprecated columns
The coreThe definitions domains build fromHelper fields that exist only to compute a measure
Analytical domainsThe fields callers may queryEverything else

Export only the analytical domains from index.malloy.

Exports and Visibility Are Not Access Rules

Exports and field visibility decide what exists for every caller. They can't vary by caller: a source is exported for everyone, and a field is public for everyone. To decide who may query a source and which rows each person sees, add access rules to the exported sources. A caller refused by #(authorize) still sees the source listed, and is refused if they query it.

To show a column to some callers only, use two sources.

Next Steps

On this page