Semi related to: https://community.palantir.com/t/aggregate-pushdown-from-foundry-sql-api-to-databricks-malformed-schema-probe/7388
Context: We are trying to query a combination of Foundry datasets / managed Iceberg, S3 Iceberg, and Snowflake virtual tables using the API (POST /api/v2/sqlQueries/execute).
Summary of findings (please confirm):
- Virtual tables never route to Trino, even
SELECT id FROM t LIMIT 1. - There is a hard limit of 10,000 rows: Furnace routes to Trino only when it can tell the result is at most 10,000 rows. A
LIMITof 10,000 or less, a small table, or a one-row aggregate likeCOUNT(*)qualifies; aWHEREfilter doesn’t.
Tests
| Input | Query | Engine |
|---|---|---|
| Foundry-managed Iceberg table | SELECT id FROM t LIMIT 1 |
TRINO |
| Foundry dataset | SELECT id FROM t LIMIT 1 |
TRINO |
| Snowflake virtual table | SELECT id FROM t LIMIT 1 |
SPARK (UNSUPPORTED_INPUT_TYPE) |
| Iceberg table on S3 (not Foundry-managed) | SELECT id FROM t LIMIT 1 |
SPARK (UNSUPPORTED_INPUT_TYPE?) |
| Foundry-managed Iceberg table, 5.6M rows | SELECT id FROM t LIMIT 10000 |
TRINO |
| Foundry-managed Iceberg table, 5.6M rows | SELECT id FROM t LIMIT 10001 |
SPARK (ROW_LIMIT_EXCEEDED) |
| Foundry-managed Iceberg table, 5.6M rows | SELECT id FROM t |
SPARK (ROW_LIMIT_EXCEEDED) |
| Foundry-managed Iceberg table, 5.6M rows | SELECT id FROM t WHERE id = 'x' (returns 0 rows) |
SPARK (ROW_LIMIT_EXCEEDED) |
| Foundry-managed Iceberg table, 5.6M rows | SELECT COUNT(*) FROM t |
TRINO |
| Foundry-managed Iceberg table, 1,712 rows | SELECT id FROM t |
TRINO |
| Foundry dataset, 19 rows | SELECT id FROM t |
TRINO |
How we saw the engine and reason
/api/v2/sqlQueries/execute reports neither, and EXPLAIN through it returns Default:Internal. So we reproduced the queries on the SQL Studio API (POST /foundry-sql-server/api/sql-endpoint/v1/queries/query), which returns the engine when you submit (queryStructure.metadata.backend). EXPLAIN only works when the query routes to Trino, but when it routes to Spark, the error names the reason.
Request:
{
"querySpec": { "query": "EXPLAIN SELECT id FROM t", "dialect": "SPARK", "tableProviders": {}, "options": { "options": [] } },
"executionParams": { "resultFormat": "ARROW", "resultMode": "AUTO", "defaultBranchIds": [] }
}
Response (t has 5.6M rows):
{
"errorCode": "INVALID_ARGUMENT",
"errorName": "FurnaceSql:IncompatibleBackendError",
"parameters": {
"backend": "SPARK",
"userFriendlyMessage": "Query routed to SPARK because ROW_LIMIT_EXCEEDED, but EXPLAIN is currently only supported for queries routed to Trino"
}
}
Spark routing reasons I’ve seen:
| Reason | Query |
|---|---|
UNSUPPORTED_INPUT_TYPE |
SELECT id FROM t LIMIT 1 on a Snowflake virtual table |
ROW_LIMIT_EXCEEDED |
SELECT id FROM t on a 5.6M-row Iceberg table |
NO_ROW_LIMIT |
SELECT id FROM t on a 63K-row Foundry dataset |
REQUIRES_SPARK |
SELECT IF(n > 0, 'in', 'out') FROM t LIMIT 1 |
CONTAINS_VIEW |
SELECT id FROM t on a view-backed Foundry dataset |
Questions:
- Is Trino support for virtual tables coming and/or is there something I’m doing incorrectly?
- Is there any way to get more control over routing? I understand the single pane of glass vision, but if I’m the end user.. <1 sec is fast, 1-5 w/ a spinner (where Trino seems to land) is good, but by 10 sec I’m irritated and by 15-20 when a larger query lands on Spark I’ve left the page.