Skip to main content

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 readsWhere it runs
Only the active connector'sOn the active connector, as always
Only one other connector'sWhole on that connector, as if you had run use <connector> first
Tables of several connectorsThe 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 values belong 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 x lives 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.
  • limit directly 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 float and double values (NaN), and char columns.
  • / and %, most casts, avg, and order 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 shipMaxRows rows (default 1,000), and all inputs sent into one connector's queries of a statement at most shipMaxBytes of SQL text (default 262,144 bytes). Set both in the receiving connector's properties. 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 between range 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:

  1. As VALUES, within the connector's shipMaxRows and shipMaxBytes.
  2. Otherwise as a temporary table _wv_copy_<id>, loaded with batched INSERT statements 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 their properties set "stagingSchema" to a schema Wvlet may create and drop tables in, such as "memory.staging" or "analytics.tmp". A copy holds at most copyMaxRows rows (default 1,000,000).
  3. 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 maxRemoteRows in the connector's properties (0 turns 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:

PropertyDefaultMeaning
maxRemoteRows1,000,000 for Trino and Snowflake, off for othersRows a statement may read from this connector into the Wvlet engine; 0 turns the limit off
shipRowsfalseAllow this connector's rows to be sent into other connectors' queries and copies
shipMaxRows1,000Rows of one input sent into this connector's query as VALUES, and of each INSERT batch of a copy
shipMaxBytes262,144Bytes of SQL text for all inputs sent into this connector's queries of a statement, and of each INSERT batch of a copy
stagingSchemanone<schema> or <catalog>.<schema> where Trino and Snowflake take temporary copies; DuckDB uses its current schema unless set
copyMaxRows1,000,000Rows of one temporary copy
~/.wvlet/profiles.json
{
"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:

NameTurns off
federation_filter_pushdownMoving filters into connectors' queries
federation_column_pruningReading only the columns the query uses
federation_limit_pushdownRunning limit inside a connector's query
federation_remote_statsAsking connectors for row estimates
federation_ship_small_sideSending small join inputs into a connector's query
federation_partial_aggPartial aggregations on a connector below a cross-connector join
federation_parquet_transportReading 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​

Consistency across connectors

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 native wvlet CLIs 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 zone columns 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. Run use <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.
  • explain doesn't say whether a pinned model's input will go as VALUES or 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.