Federated Query Reference
Rules, limits, and settings of federated queries, for when you tune a query, set up a connector, or need to know whether something is supported.
Where a query runs
| Tables the query reads | Where it runs |
|---|---|
| Only the active connector's | On the active connector, as always |
| Only one other connector's | Whole on that connector, as if you had run use <connector> first |
| Tables of several connectors | The Wvlet engine coordinates: each connector runs a query over its own tables, and the engine joins the results, also while DuckDB, Trino, or Snowflake is active |
- Engine tables, imported databases, and
valuesbelong to the Wvlet engine. - Local files belong to no connector: a query reading files and one connector's tables runs on that connector when it reads files itself (DuckDB, the Wvlet engine), and on the Wvlet engine otherwise.
- Tables of source connectors like Slack, which have no SQL engine, are read by the Wvlet engine, or copied into an active DuckDB when the rest of the query runs there.
- An L-Store database opened with
import database '<path>' as xlives on the profile's Wvlet engine whichever connector is active, and an import alias can't take a connector's name.
A query that leaves the active connector is compiled again for the site that runs it, so standard library functions use that site's variants. A function that only has an in trino variant can't run on the Wvlet engine, so it fails in a query that federates; pin that part with in <connector> instead.
What each connector runs
Each connector runs as much of the query as it can over its own tables:
- Filters, including filters written above a join, which move to the input whose columns they read. Filters on the kept side of a LEFT join move, and filters on its other side stay on the engine.
- Only the columns the query reads.
limitdirectly over one connector's tables.- Joins and aggregations whose tables are all on one connector.
- Below a join across connectors, Trino and Snowflake compute sums, counts, minimums, and maximums of their own rows per join key first, and the engine combines the partial results.
These expressions stay on the Wvlet engine, because connectors disagree on their results:
- Comparisons of
floatanddoublevalues (NaN), andcharcolumns. /and%, most casts,avg, andorder by.- Standard library function calls.
- String
<and>on Snowflake, whose collations may order strings differently (they're sent to DuckDB and Trino).
A filter using them is applied by the engine after the rows arrive, so the connector returns more rows.
Rows of a DuckDB connector reach the engine as a temporary Parquet file, which is several times faster than reading them row by row (about 10 times for a whole table); the file needs local disk space for the rows read and is deleted after the query. Columns other than integers, double, decimals, boolean, date, timestamp, and strings, and all rows from Trino and Snowflake, are read row by row.
Sending small inputs to a connector
When one side of a join is a remote table and the other side is small and comes from elsewhere (an imported L-Store table, a local file, values), the Wvlet engine reads the small side first and writes its rows into the remote query as VALUES. The join, and the aggregation above it, then run on the connector. A query whose every input ends up on one connector becomes a single remote query.
- Applies to inner joins, and to LEFT joins whose kept side is the remote table.
- The small side may have at most
shipMaxRowsrows (default 1,000), and all inputs sent into one connector's queries of a statement at mostshipMaxBytesof SQL text (default 262,144 bytes). Set both in the receiving connector'sproperties. TD's Trino accepts at most 1,000,000 characters of query text. - Columns of types without a SQL literal (
char,timestamp with time zone, arrays, maps, structs, JSON) keep their input on the engine. - Which rows may be sent at all is decided by the data boundary.
When the small side isn't sent, the Wvlet engine reads it first and sends its join keys to the connector holding the large side as where <key> in (…):
- Only when the small side is estimated at most 10,000 rows and the large side at least ten times as many.
- Integer and date keys turn into a
betweenrange past 10,000 keys. - String keys are sent up to 10,000 keys and 256 KB of text.
Temporary copies for pinned models
A pinned model may read inputs from elsewhere. The Wvlet engine sends each one into the model's query:
- As
VALUES, within the connector'sshipMaxRowsandshipMaxBytes. - Otherwise as a temporary table
_wv_copy_<id>, loaded with batchedINSERTstatements and dropped when the statement ends, also when it fails or is cancelled. DuckDB connectors always take copies. Trino and Snowflake connectors take them only when theirpropertiesset"stagingSchema"to a schema Wvlet may create and drop tables in, such as"memory.staging"or"analytics.tmp". A copy holds at mostcopyMaxRowsrows (default 1,000,000). - Otherwise the statement fails with an error naming the input, its row count, the limits, and
stagingSchema.
Each input table is sent whole, before the model's own filters on it apply, so filter a large input in a model of its own first.
Row limit
A statement reads at most maxRemoteRows rows (default 1,000,000) from each Trino or Snowflake connector into the Wvlet engine, counting every part on that connector together.
- When the connector's estimate is over the limit, the statement fails before any remote query starts.
- Parts without an estimate (Snowflake, or when Trino has no statistics) are counted as their rows arrive.
- The error names the connector and its SQL. Add a filter, or raise
maxRemoteRowsin the connector'sproperties(0turns it off). - DuckDB and other connectors have no limit unless set.
- Flow stages aren't limited.
Connector properties
Set these in a connector's properties in ~/.wvlet/profiles.json:
| Property | Default | Meaning |
|---|---|---|
maxRemoteRows | 1,000,000 for Trino and Snowflake, off for others | Rows a statement may read from this connector into the Wvlet engine; 0 turns the limit off |
shipRows | false | Allow this connector's rows to be sent into other connectors' queries and copies |
shipMaxRows | 1,000 | Rows of one input sent into this connector's query as VALUES, and of each INSERT batch of a copy |
shipMaxBytes | 262,144 | Bytes of SQL text for all inputs sent into this connector's queries of a statement, and of each INSERT batch of a copy |
stagingSchema | none | <schema> or <catalog>.<schema> where Trino and Snowflake take temporary copies; DuckDB uses its current schema unless set |
copyMaxRows | 1,000,000 | Rows of one temporary copy |
{
"name": "td",
"type": "trino",
"host": "api-presto.treasuredata.com",
"user": "${TD_API_KEY}",
"catalog": "td",
"schema": "sample_datasets",
"properties": { "maxRemoteRows": 5000000, "stagingSchema": "td.wvlet_tmp" }
}
Turn steps off
To compare results or work around a problem, turn individual steps off by name with the WVLET_FEDERATION_DISABLED environment variable (or the wvlet.federation.disabled system property), comma-separated:
| Name | Turns off |
|---|---|
federation_filter_pushdown | Moving filters into connectors' queries |
federation_column_pruning | Reading only the columns the query uses |
federation_limit_pushdown | Running limit inside a connector's query |
federation_remote_stats | Asking connectors for row estimates |
federation_ship_small_side | Sending small join inputs into a connector's query |
federation_partial_agg | Partial aggregations on a connector below a cross-connector join |
federation_parquet_transport | Reading DuckDB parts through temporary Parquet files instead of text rows |
WVLET_FEDERATION_DISABLED=federation_ship_small_side,federation_partial_agg wvlet run -f report.wv -p dev
Results don't change with any of these off; only the work each connector does does. An unknown name is an error.
Limitations
Each connector's part is a separate query, so there is no shared snapshot: two parts reading the same connector may see different versions of a table. A limit without order by may return other rows than a single-engine run of the same data.
- The npm (
npx @wvlet/cli) and nativewvletCLIs run each statement on one engine: a query mixing connectors fails there, since connectors to Trino, Snowflake, and DuckDB need the JVM. timestamp with time zonecolumns from another connector can be returned, but not compared, joined, grouped, or sorted on in a federated query.save to,append to, and other writes run on the active connector: saving rows of another connector's tables isn't supported yet. Runuse <connector>first when every table is on that connector.- Semi and anti joins (
exists,in (subquery)) don't send small inputs into a connector's query. - Flow stages on the Wvlet engine send filters and columns to connectors, but don't send small inputs or run partial aggregations there. Stages on DuckDB copy other connectors' tables whole.
explaindoesn't say whether a pinned model's input will go asVALUESor as a temporary copy, since that depends on its row count.- A process killed in the middle of a statement (not cancelled) leaves its
_wv_copy_*tables; drop them by name.