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; 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. AKEYSETstring 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]iss3://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_SUCCESSmarker counts for nothing. - Columns are declared with
EXTERNAL_COLUMNS(). Columns of the files that noEXTERNAL_COLUMNS()declares are not read. AKEYSETstring 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_IDmatchesmerchant_id. A file with two columns equal up to case is refused. TIMEOUTbounds 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_statusisOKwhen the key has a row andMISSwhen 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,usernameandpasswordare refused on an object store. file://reads a path on featuremeshd's host. It is allowed whenserving.sources.allow_file_urlsis on, which it is in the embedded Python runtime and the local configuration, and off by default in the daemon.serving.sources.object_store_prefixeslimits 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. 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.
| Pattern | How | Fits |
|---|---|---|
| The orchestrator triggers it | No 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 schedule | A 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 |
RECOMPUTEis 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:
- Write the export under a fresh directory of the table prefix, never reused:
merchant_scores/gen=20261127021500/. - Once the export succeeded, write
_latest.jsonlisting that directory's files, in one write.featuremesh.write_manifestdoes it (below). - 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} | Argument | |
|---|---|
table_prefix | <source prefix>/<table>. s3://, gs:// and file:// (or a local path) open with pyarrow |
generation | the directory under the prefix, relative, such as gen=20261127021500/ |
run | an integer > 0 below 2^63. A timestamp such as 20261127021500 works |
file_format | 'parquet', the only value |
filesystem | a 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; HEADER = TRUE. Without it, the files' columns are named_COL_0,_COL_1, … and no declared column matches.- Integers. Snowflake writes every integer column,
SMALLINTincluded, asDECIMAL(38,0). A view reads it asBIGINT, checking each value: one outside 64 bits fails the run. A::BIGINTcast in the unload writes 64-bit integers and skips the check. - Time zones. Snowflake cannot unload
TIMESTAMP_TZorTIMESTAMP_LTZ. Convert them withCONVERT_TIMEZONE('UTC', x)::TIMESTAMP_NTZ. - Milliseconds. Snowflake writes every
TIMESTAMP_NTZwith millisecond precision, whatever its scale: the sub-millisecond digits are lost in the export. - Semi-structured columns.
ARRAY,OBJECTandVARIANTarrive as JSON text: declare themVARCHAR. - Floats. A
FLOATcolumn arrives as 64-bit floats, read asDOUBLE.
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; BIGNUMERICis a 256-bit decimal, which is refused: cast it toNUMERICorFLOAT64in the export.- Then call
write_manifestforgen=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; - Spark's marker files (
_SUCCESS,_committed_*,_started_*) are skipped bywrite_manifest. - Then call
write_manifestforgen=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
} | Field | Required | Rule |
|---|---|---|
run | yes | the generation's identity: a JSON integer > 0, below 2^63. A lower value than the last run read is allowed (a rollback) and logged |
format | yes | "parquet", equal to the source's FORMAT |
files | yes | paths relative to the table prefix: no leading /, no scheme, no \, no empty, . or .. segment, no path twice. May be empty: an empty table |
rows | no | when present, the sum of the listed files' row counts, read from their footers before any scan |
| any other field | no | ignored |
- 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-Matchon 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
STALLEDwith the error.
| Failure | Code |
|---|---|
no _latest.json under the table prefix | MV-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's | MV-SOURCE-MANIFEST-INVALID |
| a listed file is missing | MV-SOURCE-FILE-MISSING |
| a listed file changed after the pin | MV-SOURCE-FILE-CHANGED |
| a declared column missing, or of a type not accepted | MV-SOURCE-SCHEMA-MISMATCH |
the footers' row counts differ from rows | MV-SOURCE-ROWS-MISMATCH |
| a codec or encryption the reader lacks: Hadoop-framed LZ4, LZO, an encrypted file | MV-SOURCE-UNSUPPORTED-ENCODING |
the store unreachable, credentials refused, a request over TIMEOUT | UNAVAILABLE, 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.
| Declared | Accepted from the file |
|---|---|
BIGINT | signed integers, unsigned up to 32 bits, DECIMAL(p,0) (checked per value above 18 digits) |
INT, SMALLINT, TINYINT | the integers that fit, DECIMAL(p,0) checked per value |
DOUBLE | 32- and 64-bit floats |
FLOAT | 32-bit floats |
DECIMAL(p,s) | a decimal with at most s digits of scale and p − s integer digits |
VARCHAR | strings, dictionary-encoded or not |
BOOLEAN | booleans |
DATE | dates |
TIMESTAMP | every 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, VARBINARY | refused 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
NULLkey is that row's data error on every keyed sink: the row is skipped and counted indata_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
| Limit | What 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 disk | Raise 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 once | A 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 with | Export 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 steps | Bind 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 budget | Give 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 up | Size 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 warning | CONFIG 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 Replication | Raise 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 backend | Point 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 one | Keep 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 read | Export 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 store | Run the body as a view writing an object-store sink and read the sink, or read the export with DuckDB's read_parquet |
Related
- Materialized views : schedules, runs and how each sink lands a run.
- Run a view from an orchestrator : triggering and following a run.
-
SOURCE_DB(): the declaration and its properties. - Configure featuremeshd : the view settings.