Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions documentation/client/adbc_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ Set this as the statement's SQL (`stmt.setSqlQuery(...)`) and read the Arrow str

---

## The schema before the rows

*Since arrow-extensions `0.3.5`*, `executeSchema()` answers the schema `executeQuery()` streams,
without running anything. A `SELECT` the relational engine runs (a cross-index JOIN, a correlated
subquery, a derived table, a `WITH`, a set operation other than `UNION ALL`) is typed from each
leg's declared schema, then by DuckDB over legs holding no row; any other `SELECT` from the schema
the engine declares for it (the index mapping, computed columns, aggregates). It answered
`NOT_IMPLEMENTED` before.

```scala
stmt.setSqlQuery("""
SELECT e.name, e.salary, d.dept_name
FROM jdbc_join_emp e
JOIN jdbc_join_dept d ON e.dept_id = d.dept_id
""")
val schema = stmt.executeSchema() // the schema executeQuery() streams; nothing is searched
```

A statement other than a `SELECT`, and a `SELECT` that cannot be typed before it runs (a text the
parser refuses, a statement or a leg the engine refuses, more JOINs than your plan's `maxJoins`
allows), still answers `NOT_IMPLEMENTED`, and nothing runs. `executeQuery()` runs it and returns its
rows, or its error.

---

## JDK 16 and later: one required flag

The ADBC driver is Arrow-native in process, and Apache Arrow reaches into `java.nio` to address off-heap memory. **JDK 16 and later deny that access by default** ([JEP 396](https://openjdk.org/jeps/396)), so a modern JVM must be started with:
Expand Down
39 changes: 28 additions & 11 deletions documentation/client/arrow_flight_sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,34 @@ elastic.credentials {
| `ARRAY<*>` | — | `List` |
| `ARRAY<STRUCT>` | `nested` | `List<Struct>` |

The table is the declared mapping. A plain query's Arrow schema is inferred from the values of its
rows; the engine answers every value it reads by type in the class of its column's declared type
(*since engine `0.25.0`*), so the schema follows the table: a `BIGINT` column arrives as `Int(64)`
whatever its values, and a computed column the engine declares `DOUBLE` (`x * 2` over a `DOUBLE`
column) as `Float(DOUBLE)` — in the advertised schema and in the stream alike. A value the engine
answers as stored keeps its own class (see [Value classes](gateway.md#value-classes)), and a column
of no known type (`ANY`) can carry whole and decimal numbers alike: there, the column takes the type
of its first value. A set operation's branches are typed from the declared
types above when the statement is planned, and a JOIN result carries DuckDB's types. A column the
reader cannot answer — a dictionary-encoded column, an Arrow type it has no reader for — fails
naming the column instead of reading `NULL` (*since arrow-extensions `0.3.4`*).
The table is the declared mapping. A query's Arrow schema is the engine's declared schema, read
before any row (*since arrow-extensions `0.3.5`*; it was inferred from the first rows): the
advertised schema (`GetFlightInfo`, a prepared statement's schema, the ADBC result schema) and the
stream always agree, and preparing a statement runs no search. A `BIGINT` column arrives as
`Int(64)` whatever its values, and a computed column the engine declares `DOUBLE` (`x * 2` over a
`DOUBLE` column) as `Float(DOUBLE)`. Each leg of a JOIN or of a derived table is typed the same
way, from its own statement. A column of no known type (`ANY`, an object with no declared fields, a
flattened or disabled object) is `Utf8`, its cells the engine's text (see
[Value classes](gateway.md#value-classes)). A cell holding several values in a column
declared as one value fails, naming the column, the row and how to declare the column a list,
instead of reading `NULL`; so does a value its column's type cannot hold. A set operation's branches
are typed from the declared types above when the statement is planned, and a JOIN result carries
DuckDB's types. A column the reader cannot answer — a dictionary-encoded column, an Arrow
type it has no reader for — fails naming the column instead of reading `NULL` (*since
arrow-extensions `0.3.4`*).

*Since arrow-extensions `0.3.5`*, a statement the relational engine runs — a cross-index JOIN, a
correlated subquery, a derived table, a `WITH`, a set operation other than `UNION ALL` — is typed
when it is prepared too: each leg from its declared schema, then the result by DuckDB over legs
holding no row. Its prepared statement, `GetSchema` and `GetFlightInfo` advertise the schema it
streams (such a prepared statement carried no schema before). A `?` that stands for a value in a
condition (`WHERE a.id = ?`) does not stop the typing: the prepared schema is the one its bound
execution streams. Such a statement that cannot be typed before it runs — a text the parser refuses,
a leg the engine refuses, more JOINs than your plan's `maxJoins` allows, a result DuckDB cannot bind
— advertises an empty schema: the prepare succeeds and the error comes at execution. A prepared
statement is typed again at every execution: re-executed after an `ALTER TABLE` run through this
server widened a column, it streams the widened type, which `GetFlightInfo` advertises. The schema
returned when it was prepared is not updated: prepare the statement again to refresh it.

---

Expand Down
36 changes: 27 additions & 9 deletions documentation/client/jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ Elasticsearch has no server-side prepared statements, so the driver substitutes
- **Parameters are length-bounded.** A bound value may render to at most **8192 characters** (after escaping — an apostrophe or a backslash contributes two). Above that the driver raises a `SQLException` naming the limit rather than building a statement the engine's parser cannot read. Store long text in the document and filter on a shorter key, or narrow the value.
- **A parameter you never set is an error**, not an implicit `NULL`, and an index with no matching placeholder is refused at set time. Use `setNull` to bind SQL `NULL` deliberately.

**The metadata before execution.** `PreparedStatement.getMetaData()` answers the `ResultSetMetaData`
its execution reports, without running anything (*since JDBC driver `0.3.5`*; it answered `null`).
It reads the statement as bound so far: the engine's declared schema of it, or, for a statement the
relational engine runs (a cross-index JOIN, a correlated subquery, a derived table, a `WITH`, a set
operation other than `UNION ALL`), that engine's declared result. A `?` not bound yet reads as
`NULL` there, so a column made of a bare `?` is reported as `NULL` until it is bound (the relational
engine types it as DuckDB types a `NULL`); executing still refuses an unset parameter. A column of
no known type is reported as `ANY` (`Types.OTHER`, `java.lang.Object`): there is no value yet to
type it by. `getMetaData()` answers `null` where the result is not known before the statement runs:
a statement that is not a query, a text the parser refuses, a statement or a leg the engine refuses,
one with more JOINs than your plan's `maxJoins` allows.

> **Known limitation, plain `Statement` only:** a multi-statement string executed through `Statement` (not `PreparedStatement`) with a very long literal typed directly into the SQL can still exhaust the parser's stack, and reports a timeout rather than a parse error. Bound parameters are not affected. Split such SQL into separate statements.

```java
Expand Down Expand Up @@ -260,15 +272,21 @@ The JDBC driver supports the full SQL Gateway syntax:
- **DQL** — SELECT with WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, set operators (`UNION [ALL]` / `INTERSECT` / `EXCEPT`), JOIN UNNEST, window functions
- **SHOW/DESCRIBE** — Tables, pipelines, watchers, enrich policies

**Column types.** A plain query's `ResultSetMetaData` is inferred from the first non-null value of
each column. The engine answers every value it reads by type in the class of its column's declared
type (*since engine `0.25.0`*), so the inferred type is the declared one: a `BIGINT` column is
reported as `BIGINT`, its small values included, and `getObject` answers a `Long` on every row; a
computed column the engine declares `DOUBLE` (`x * 2` over a `DOUBLE` column) is reported as
`DOUBLE` and answers a `Double` on every row. A `TINYINT` or `SMALLINT` column, whose values are
`Integer`s, is reported as `INTEGER`. A value the engine answers as stored keeps its own class (see
[Value classes](gateway.md#value-classes)), and a column of no known type (`ANY`) can carry whole
and decimal numbers alike: there, the column is reported as the type of its first value.
**Column types.** A query's `ResultSetMetaData` is the engine's declared schema (*since JDBC driver
`0.3.5`*; it was inferred from the first non-null value of each column): every column, in its order,
typed by its declared type whatever the rows hold, so a column no row holds keeps its type and a
result with no row keeps its columns. A `BIGINT` column is reported as `BIGINT`, a computed column
the engine declares `DOUBLE` (`x * 2` over a `DOUBLE` column) as `DOUBLE`, and a `TINYINT` or
`SMALLINT` column as itself, its values `Integer`s (JDBC 4.3, Table B-3). Only a column of no known
type (`ANY`) is typed from its rows: it takes the type of its first non-null value. `SHOW` and
`DESCRIBE` still report the types of their rows. `getObject` (*since JDBC driver `0.3.5`*) answers
the class `getColumnClassName` names (`Integer` for `TINYINT`, `SMALLINT` and `INTEGER`, `Long` for
`BIGINT`, `Float` for `REAL`, `Double` for the other numbers, `java.sql.Date`, `java.sql.Time` and
`java.sql.Timestamp` for the dates and times, `List` for an array, `Map` for a `STRUCT`) wherever
that class holds the value exactly; a value it cannot hold (a whole number beyond the column's type,
a fraction in a whole-number column) comes back as stored (see [Value
classes](gateway.md#value-classes)).

`getByte`, `getShort`, `getInt`, `getLong` and `getFloat` throw `SQLException` on a number outside
their type (*since engine `0.25.0`*: `Value 3000000000 is out of range for INT`) instead of
answering a wrapped value: `getInt` of a `BIGINT` past the integer range, a value answered as stored
Expand Down
5 changes: 3 additions & 2 deletions documentation/client/scroll.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ count (an explicit ceiling below it is still a whole-shard split on the Elastics
`_doc`-ordered before). Add an `ORDER BY` when order matters — ordered statements stay sequential.
- A licence-quota-capped result (`maxDocuments`) is now an **arbitrary subset** of the matching
rows, not a stable prefix.
- `SELECT *` column metadata derived from the first row (JDBC, Arrow) may vary between runs on
heterogeneous multi-shard indices.
- With a JDBC driver or arrow-extensions older than `0.3.5`, `SELECT *` column metadata derived from
the first row may vary between runs on heterogeneous multi-shard indices (since `0.3.5` both
report the declared schema).
- In-flight memory is bounded by about `2 × slices × scrollSize` rows plus `slices` raw page
responses (each slice keeps one page in flight while the previous one drains).
- The PIT is opened lazily (at materialization) and closed exactly once — on completion, failure
Expand Down
2 changes: 1 addition & 1 deletion documentation/sql/dql_statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ position — a column, a field, an element — every branch's value there is con
position holds ONE class: a `DOUBLE` a `Double`, a `BIGINT` a `Long`, a `TIMESTAMP` a
`ZonedDateTime` (a date-only, zone-less or epoch-milliseconds value included), a `VARBINARY`
bytes, a `VARCHAR` a string, a list a list of its element's type, an object a map of its fields
in order — which is the type JDBC and Arrow report, since they read it from the first value. A
in order — the type JDBC and Arrow report. A
position whose branches already have one type is returned as each branch reads it, nothing
converted, and a branch over an aggregate answers the class of the aggregate's type (*since
`0.25.0`*: a `Double` before). So, `n` being an `INT` column, `SELECT MAX(n) AS k FROM t UNION ALL
Expand Down
16 changes: 16 additions & 0 deletions documentation/sql/joins.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,22 @@ FROM `prod_us`.orders o
JOIN `prod_fr`.customers c ON o.customer_id = c.id;
```

**The result schema before the rows** (*since arrow-extensions `0.3.5`*). A JOIN,
correlated-subquery, derived-table, `WITH` or set-operation `SELECT` sent to the coordinator is
typed when it is prepared, whether it reads one cluster or several: each leg takes the schema its
cluster's sidecar declares (within the coordinator's `query-timeout-seconds`, Helm
`federation.queryTimeoutSeconds`), then DuckDB types the result, with no leg run on a `0.3.5`
sidecar (see below for older ones). Its prepared statement and `GetSchema` carry that schema;
before, such a prepared statement carried no schema, and `GetSchema` failed as unimplemented for
every statement. For any other `SELECT`, which the coordinator forwards whole to one cluster,
`GetSchema` returns that sidecar's answer. Among the statements the coordinator runs itself, one
with a `?`, a write, and one that cannot be typed before it runs (a leg refused, a cluster that does
not answer in time, more JOINs than `maxJoins` allows) carry no schema at prepare; a query among
them is typed at execution. Against a sidecar older than `0.3.5`, declaring a leg's schema runs that
leg's search on a sample of rows, and the declared types can differ from the streamed ones: the
prepared schema is then only advisory, while `GetFlightInfo` always matches the stream. Upgrade the
sidecars along with the coordinator.

---

## Performance characteristics
Expand Down
14 changes: 5 additions & 9 deletions documentation/sql/known_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,15 +743,11 @@ the column it aggregates, whatever the other rows answer.
text and stored value round differently then differs from DuckDB: `0.35` rounds to `0.4` in the
view, where DuckDB rounds the `REAL` `0.35` (`0.3499999940…`) to `0.3`. A plain query over the
same column answers as DuckDB. Declare the column `DOUBLE` to avoid it.
- **JDBC and Arrow Flight read a plain query's column types from its values.** The values the engine
reads by type carry the class of their column's declared type (*since `0.25.0`*), so a `BIGINT`
column is reported as a `BIGINT` (`Int(64)`) whatever its values, and a computed column the engine
declares `DOUBLE` holds a `Double` on every row. A value the engine answers as stored keeps its
own class (see [Value classes](../client/gateway.md#value-classes)), and a column of no known type
(`ANY`) can carry whole and decimal numbers alike: there, the column is reported as the type of
its first value. JDBC reports a `TINYINT` or `SMALLINT` column, whose
values are `Integer`s, as an `INTEGER`. A set operation (`UNION ALL` and the others) is typed from
the declared types.
- **A JDBC driver or arrow-extensions older than `0.3.5` reads a plain query's column types from its
values** (the first non-null value; JDBC reports a `TINYINT` or `SMALLINT` column as an
`INTEGER`). Since `0.3.5` both report the engine's declared schema, read before any row: see [JDBC
column types](../client/jdbc.md#supported-sql) and [Arrow type
mapping](../client/arrow_flight_sql.md#arrow-type-mapping).

## Coming in the upcoming release (Quarter 1 2027)

Expand Down
Loading