Batch to online

This page brings a warehouse table online. The warehouse exports the table as Parquet files to an object store. A materialized view on featuremeshd reads that export and writes Redis or PostgreSQL sinks, which prepared statements read by key. No warehouse credential enters featuremeshd: the warehouse, or your orchestrator, writes the export, and featuremeshd only reads it.

CREATE OR REPLACE FEATURES IN FM.RISK AS
PERSIST
    EXP := SOURCE_DB('s3://acme-exports/risk' WITH (FORMAT = 'parquet')),
    MERCHANTS := ENTITY(),
    MERCHANT_ID := INPUT(BIGINT#MERCHANTS),
    SCORES := EXTERNAL_COLUMNS(merchant_id BIGINT#MERCHANTS BIND TO MERCHANT_ID, score DOUBLE, tier VARCHAR
                               FROM TABLE(EXP[merchant_scores])),
    SCORES_PG := SINK('postgresql://…' TABLE 'merchant_scores' KEY (merchant_id) WITH (MODE = 'latest')),
    SCORES_REDIS := SINK('redis://…' KEY 'score:{' || KEY_TO_SCALAR(MERCHANT_ID)::VARCHAR || '}'
                         WITH (MODE = 'latest', FORMAT = 'json', WATERMARK_KEY = 'score:{wm}'));

CREATE OR REPLACE MATERIALIZED VIEW FM.RISK.SCORES_ONLINE
TO FM.RISK.SCORES_PG, FM.RISK.SCORES_REDIS
AS
RETURN FM.RISK.MERCHANT_ID AS merchant_id, FM.RISK.SCORES[score] AS score, FM.RISK.SCORES[tier] AS tier
FOR FM.RISK.MERCHANT_ID := @BIND_KEYSET(FM.RISK.SCORES);

-- the orchestrator, once it wrote _latest.json:
RECOMPUTE MATERIALIZED VIEW FM.RISK.SCORES_ONLINE;
sql

Two choices in it matter:

  • The population is the table's own keyset (@BIND_KEYSET(FM.RISK.SCORES)): one scan, no join, and memory that does not grow with the number of keys. A KEYSET string over another table (KEYSET(MERCHANTS, 'SELECT merchant_id FROM EXP[active_merchants]')) is a join, and its keys are held in memory ( Limits ).
  • No SCHEDULE. The orchestrator runs the view once the export is complete ( Trigger the view ).

Declare the export

An object store is a SOURCE_DB() scheme: s3://, gs://, az:// or file://, with FORMAT = 'parquet' (the default and the only format read).

  • A table is a sub-prefix. EXP[merchant_scores] is s3://acme-exports/risk/merchant_scores/. A table name is one path segment, its case kept as written.
  • A table is read through its manifest only, <table prefix>/_latest.json ( The manifest ). Files without a manifest are not read, and a _SUCCESS marker counts for nothing.
  • Columns are declared with EXTERNAL_COLUMNS(). Columns of the files that no EXTERNAL_COLUMNS() declares are not read. A KEYSET string may read declared columns only (UE/KEYSET-UNDECLARED-COLUMN), and one column declared with two types is refused (UE/SOURCE-CONFLICTING-COLUMN-TYPES).
  • Column names match case-insensitively, so Snowflake's upper-case MERCHANT_ID matches merchant_id. A file with two columns equal up to case is refused.
  • TIMEOUT bounds each request to the store (the manifest, a file's footer, a range read), 30 seconds by default. It does not bound the run.
  • source_status is OK when the key has a row and MISS when it has none. A read that fails fails the run, so no other value occurs.
  • Credentials are featuremeshd's own identity, as for object-store sinks: its environment (AWS_* variables, AWS_ENDPOINT_URL), instance or workload identity. One endpoint per process. aggregate_pushdown, target, username and password are refused on an object store.
  • file:// reads a path on featuremeshd's host. It is allowed when serving.sources.allow_file_urls is on, which it is in the embedded Python runtime and the local configuration, and off by default in the daemon. serving.sources.object_store_prefixes limits the prefixes a source may name ( Configure featuremeshd ).

Materialized views only. A prepared statement, the statement a hook runs, or a free-form query on featuremeshd that reaches an object-store source is refused, with the path from the statement to the source:

UE/SERVING-SOURCE-OBJECT-STORE
Object-store sources are read by materialized views only; serving reads what those views write.
Prepared statement FM.RISK.SCORE_NOW reads FM.RISK.EXP through
FM.RISK.SCORE_NOW → FM.RISK.SCORE_ADJ → FM.RISK.SCORES → FM.RISK.EXP[merchant_scores].
hint: Write the table to a Postgres or Redis sink with CREATE MATERIALIZED VIEW, then read that sink here.
null

A statement that replaces the object-store read by an online one with VARIANT is accepted. Batch backends refuse an object-store SOURCE_DB() as they refuse every SOURCE_DB() (UE/FUNCTION-NOT-AVAILABLE). A view reading an export and writing a warehouse table is refused (UE/MATERIALIZED-VIEW-NO-ENGINE).

Trigger the view

A run reads the generation the manifest names when the run starts. Two patterns give a run a complete export.

PatternHowFits
The orchestrator triggers itNo SCHEDULE. After the export and its manifest are written, the orchestrator sends RECOMPUTE MATERIALIZED VIEW ( Run a view from an orchestrator )An orchestrator owns the export
A frequent scheduleA SCHEDULE such as '*/10 * * * *'. A run that finds the same generations as the last run it published publishes nothing (UNCHANGED)The export is written by a warehouse task you do not orchestrate
  • RECOMPUTE is one execution and one publication attempt. A failed one is not retried: the orchestrator retries it, which starts a new run. A scheduled run is retried with backoff, and each new execution reads the manifests again, so an export fixed in the meantime lands without waiting for the next slot.
  • A fixed schedule set to after the export assumes the export is done by then. When it is late, the run reads the previous generation, and the new one waits for the next slot.

UNCHANGED. A view qualifies when its result depends on its object-store tables only:

  • every source it reads is an object store;
  • it binds no SCHEDULED_TIME();
  • it calls no volatile function;
  • none of its sinks has a RETENTION.

Such a view, when every table's manifest names the generation the last published run read, publishes nothing. Its sinks keep that run and its request_time, which then says when the data last changed. The comparison is with the last run this featuremeshd published: after a restart, or on another replica, the first run writes again. Any other view rewrites its sinks at every run.

A stopped exporter. Each run records the generation it read of every table and the manifest's age, in SHOW SERVING STATUS (last.inputs) and in the gauges featuremeshd.views.input.generation and featuremeshd.views.input.age_seconds. Alert on an input older than two export periods ( Metrics ).

Write the export

The exporter does three things:

  1. Write the export under a fresh directory of the table prefix, never reused: merchant_scores/gen=20261127021500/.
  2. Once the export succeeded, write _latest.json listing that directory's files, in one write. featuremesh.write_manifest does it (below).
  3. Never modify a listed file. Delete a generation only once no run can still be reading it ( Limits ).

A warehouse export cannot write a file of an exact name, so the manifest is written by your code, right after the export.

write_manifest

featuremesh.write_manifest lists a generation's directory, reads each Parquet footer, and writes _latest.json with files and rows in one write. It needs pyarrow.

import featuremesh

featuremesh.write_manifest(
    "s3://acme-exports/risk/merchant_scores",   # the table prefix: the source's prefix, then the table
    generation="gen=20261127021500/",           # the export's directory under it
    run=20261127021500,                         # the generation's identity, an integer > 0
)
# {'run': 20261127021500, 'format': 'parquet', 'files': ['gen=20261127021500/part-00000.parquet', …], 'rows': 4812337}
python
Argument
table_prefix<source prefix>/<table>. s3://, gs:// and file:// (or a local path) open with pyarrow
generationthe directory under the prefix, relative, such as gen=20261127021500/
runan integer > 0 below 2^63. A timestamp such as 20261127021500 works
file_format'parquet', the only value
filesystema pyarrow or fsspec filesystem, for other credentials. Required for az://, whose URI names no account

Names starting with _ or . (_SUCCESS, .crc, _committed_*) are skipped. A file that is not Parquet, or more than 10,000 files, raise ValueError.

Snowflake

Unload into an external stage on the store, one directory per generation:

COPY INTO @acme_exports/risk/merchant_scores/gen=20261127021500/
FROM (
    SELECT
        merchant_id::BIGINT AS merchant_id,
        score,
        tier,
        CONVERT_TIMEZONE('UTC', updated_at)::TIMESTAMP_NTZ AS updated_at
    FROM risk.merchant_scores
)
FILE_FORMAT = (TYPE = PARQUET)
HEADER = TRUE;
sql
  • HEADER = TRUE. Without it, the files' columns are named _COL_0, _COL_1, … and no declared column matches.
  • Integers. Snowflake writes every integer column, SMALLINT included, as DECIMAL(38,0). A view reads it as BIGINT, checking each value: one outside 64 bits fails the run. A ::BIGINT cast in the unload writes 64-bit integers and skips the check.
  • Time zones. Snowflake cannot unload TIMESTAMP_TZ or TIMESTAMP_LTZ. Convert them with CONVERT_TIMEZONE('UTC', x)::TIMESTAMP_NTZ.
  • Milliseconds. Snowflake writes every TIMESTAMP_NTZ with millisecond precision, whatever its scale: the sub-millisecond digits are lost in the export.
  • Semi-structured columns. ARRAY, OBJECT and VARIANT arrive as JSON text: declare them VARCHAR.
  • Floats. A FLOAT column arrives as 64-bit floats, read as DOUBLE.

Then call write_manifest for gen=20261127021500/.

BigQuery

Not verified against a real export yet: these rules come from BigQuery's documentation.

EXPORT DATA OPTIONS (
    uri = 'gs://acme-exports/risk/merchant_scores/gen=20261127021500/*.parquet',
    format = 'PARQUET'
) AS
SELECT merchant_id, score, tier FROM risk.merchant_scores;
sql
  • BIGNUMERIC is a 256-bit decimal, which is refused: cast it to NUMERIC or FLOAT64 in the export.
  • Then call write_manifest for gen=20261127021500/.

Databricks

Not verified against a real export yet: these rules come from Databricks' documentation.

INSERT OVERWRITE DIRECTORY 's3://acme-exports/risk/merchant_scores/gen=20261127021500/'
USING PARQUET
SELECT merchant_id, score, tier FROM risk.merchant_scores;
sql
  • Spark's marker files (_SUCCESS, _committed_*, _started_*) are skipped by write_manifest.
  • Then call write_manifest for gen=20261127021500/.

The manifest

<table prefix>/_latest.json names the current generation. It is written last, in one write, after every file it lists is complete.

{
  "run": 20261127021500,
  "format": "parquet",
  "files": ["gen=20261127021500/part-00000.parquet", "gen=20261127021500/part-00001.parquet"],
  "rows": 4812337
}
json
FieldRequiredRule
runyesthe generation's identity: a JSON integer > 0, below 2^63. A lower value than the last run read is allowed (a rollback) and logged
formatyes"parquet", equal to the source's FORMAT
filesyespaths relative to the table prefix: no leading /, no scheme, no \, no empty, . or .. segment, no path twice. May be empty: an empty table
rowsnowhen present, the sum of the listed files' row counts, read from their footers before any scan
any other fieldnoignored
  • A manifest holds at most 10,000 files and 16 MiB (MV-SOURCE-MANIFEST-TOO-LARGE).
  • A materialized view's own object-store sink writes this manifest, so a view can read another view's Parquet output.

What a run does with it

  • It pins one generation per table when it starts: it reads each manifest, checks each listed file's size and footer, and reads exactly those files for every scan of the table.
  • It checks the files before reading rows. A declared column missing from a file, or of a type the table below does not accept, fails the run naming the table, file and column; it never reads as NULL.
  • A file changed or deleted after the pin fails the run. The store must enforce If-Match on reads to detect a change of the same size: S3, GCS and Azure do.
  • A failed run publishes nothing. The sinks keep the last published run, and the view is STALLED with the error.
FailureCode
no _latest.json under the table prefixMV-SOURCE-NO-MANIFEST
the manifest is not JSON, lacks a field, or lists a file outside its prefix or twice; format differs from the source'sMV-SOURCE-MANIFEST-INVALID
a listed file is missingMV-SOURCE-FILE-MISSING
a listed file changed after the pinMV-SOURCE-FILE-CHANGED
a declared column missing, or of a type not acceptedMV-SOURCE-SCHEMA-MISMATCH
the footers' row counts differ from rowsMV-SOURCE-ROWS-MISMATCH
a codec or encryption the reader lacks: Hadoop-framed LZ4, LZO, an encrypted fileMV-SOURCE-UNSUPPORTED-ENCODING
the store unreachable, credentials refused, a request over TIMEOUTUNAVAILABLE, retried

Snappy, Zstandard, gzip, LZ4_RAW and Brotli are read.

Types

A file column is accepted for a declared type when every value converts exactly.

DeclaredAccepted from the file
BIGINTsigned integers, unsigned up to 32 bits, DECIMAL(p,0) (checked per value above 18 digits)
INT, SMALLINT, TINYINTthe integers that fit, DECIMAL(p,0) checked per value
DOUBLE32- and 64-bit floats
FLOAT32-bit floats
DECIMAL(p,s)a decimal with at most s digits of scale and p − s integer digits
VARCHARstrings, dictionary-encoded or not
BOOLEANbooleans
DATEdates
TIMESTAMPevery unit and INT96. A time zone is an instant, read in UTC; no zone is read as UTC. Nanoseconds are truncated to microseconds
ARRAY<T>a list of a type accepted for T
ROW<…>a struct with every declared field, matched by name case-insensitively; extra fields ignored
JSON, INTERVAL, VARBINARYrefused at registration (UE/SOURCE-UNSUPPORTED-PROPERTY)

Refused in a file: 256-bit decimals (BigQuery BIGNUMERIC), fixed-size lists, binary columns, 16-bit floats, maps, unsigned 64-bit integers. NaN and ±Inf in a DOUBLE column read as NULL.

How a run publishes

A run executes the view's query once and streams its result into a local spool file. Only when the query has finished without error does any sink see a row.

  • Every sink prepares, then each publishes. PostgreSQL and MySQL/MariaDB fill a temporary table on one session, Redis fills the run's key set, an object store writes its part files. Each is checked against the result's row count. Then each sink publishes on its own fence, as described in How a run lands .
  • Duplicate keys fail the run. Two rows for one key of a keyed sink fail it with MV-SINK-DUPLICATE-KEY, naming the sink and the key, and no sink publishes. The duplicate is usually in the export.
  • A NULL key is that row's data error on every keyed sink: the row is skipped and counted in data_errors.
  • A failed publication is retried from the spool, so every sink publishes the same rows.
  • A run overtaken by a newer published run stops with the outcome OVERTAKEN, not an error.

SHOW SERVING STATUS shows a running view's phase (WAITING, PIN, EXECUTE, PREPARE, PUBLISH <sink>, CLEANUP) and rows_so_far ( A view's details ).

Limits

LimitWhat to do
Memory per run. A run's query, its Parquet scans, its spool reads and its sinks' buffers share one budget, serving.hooks.view_memory_limit_bytes (1 GiB), apart from the pool serving calls use. A run over it fails with MV-RUN-MEMORY, naming the operator, and publishes nothing. Nothing spills to diskRaise the budget, and the container's memory limit with it (below)
Views per process. At most serving.hooks.max_concurrent_views runs (2) at a time. Others wait, first come first served, shown WAITING. A RECOMPUTE with no free slot answers QUEUED at onceA process needs the serving pool (memoryLimitMb) plus max_concurrent_views × the per-run budget, and room for itself. Memory outside the budget was measured at about 150 MB per run, and up to 1.8 times the budget's peak for a run that joins: size for serving pool + max_concurrent_views × (1.8 × budget + 150 MB)
Own keyset: memory does not grow with the keys. The scan reserves the largest row group's compressed columns read, times serving.hooks.view_target_partitions (1). A row group that does not fit fails at the pin with MV-RUN-MEMORY, naming the row-group size to export withExport smaller row groups
Joins hold one side in memory: a KEYSET string over another table, a dimension read from PostgreSQL, a GROUP BY with many groups, a full sort. Measured at 5 million keys: a KEYSET of 14-character strings takes about 70 bytes per key (about 15 million keys per GiB), a PostgreSQL dimension with a BIGINT key about 27 bytes per key (about 40 million keys per GiB). The hash table grows by doubling, so the need rises in stepsBind the view to its table's own keyset where you can
Spool disk. The result is spooled on local disk, under serving.hooks.view_spool_dir (the system's temporary directory by default), up to serving.hooks.view_spool_limit_bytes (16 GiB) per run (MV-RUN-SPOOL). The spool is about the size of the result: about 110 to 165 bytes per row for 10 columns. A spool directory on tmpfs counts in the memory budgetGive the spool max_concurrent_views × the limit of disk. In Kubernetes, the chart's viewSpool (on by default, hooks service only) mounts a disk-backed emptyDir of viewSpool.sizeLimit (20Gi) at viewSpool.mountPath, sets view_spool_dir to it, and sets view_spool_limit_bytes to 90% of sizeLimit ÷ max_concurrent_views (9 GiB for 20Gi and 2 runs). Set viewSpool.limitBytes, or either key in hooks.config, to override
Redis memory for key sets. A Redis sink keeps the keys of a run in a set, about 100 bytes per key (about 500 MB at 5 million keys), and two sets coexist while a run cleans upSize Redis for twice the key set beside the values
Redis 6.2 or later, with an eviction policy that cannot evict the watermark or a key set: noeviction or a volatile-* policy (they carry no TTL). The sink checks before it writes: an older Redis or an allkeys-* policy fails the run with MV-SINK-REDIS-UNSUPPORTED; a Redis that refuses CONFIG GET gets a warningCONFIG GET maxmemory-policy
MySQL write-set limits. A MySQL/MariaDB sink publishes in one transaction. Millions of rows exceed the default write-set limits of Galera and Group ReplicationRaise wsrep_max_ws_size or group_replication_transaction_size_limit, or write a smaller view
One session from stage to publication. PostgreSQL and MySQL/MariaDB sinks stage the run in a temporary table on one connection, then publish on it. A transaction pooler (PgBouncer in transaction mode, the pooled endpoint of hosted services) or a multiplexing proxy can hand the publication another session: MV-SINK-STAGE-LOST. It is not always detected: a pooler may hand back the same backendPoint view sinks at a direct connection or a session pooler
Retention of exports. A run reads the files of the generation it pinned until it ends. A generation deleted while a run reads it fails the run (MV-SOURCE-FILE-MISSING); the next execution reads the current one. A FeatureMesh object-store sink deletes generations older than the previous oneKeep a generation longer than the longest view run after it stops being current. A view reading another view's sink needs runs shorter than that sink's publish interval
Formats. Parquet only: no CSV, JSON lines, Delta or Iceberg. Hive-partitioned exports whose partition columns are not in the files, and a logger's append output, have no manifest and are not readExport Parquet with the columns in the files
Timestamps are microseconds; Snowflake exports carry milliseconds
gs:// and az:// are built like s3:// but not tested against a store
No trial run of a body on featuremeshd: free-form queries cannot read an object storeRun the body as a view writing an object-store sink and read the sink, or read the export with DuckDB's read_parquet

Related