Skip to content

feat(qwp): read INTERVAL and NULL columns, report the designated timestamp and omit BINARY values of query results - #135

Open
glasstiger wants to merge 8 commits into
mainfrom
ia_ui_qwp
Open

glasstiger wants to merge 8 commits into
mainfrom
ia_ui_qwp

Conversation

@glasstiger

@glasstiger glasstiger commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Adds INTERVAL and NULL result columns, a designated timestamp report and the omission of BINARY values to the Java QWP query client: the client side of questdb/questdb#8693.

New functionality

  • The client asks the query endpoint for QWP version 3 (QwpQueryClient.QWP_MAX_VERSION, now QwpConstants.EGRESS_MAX_VERSION), whose results can carry INTERVAL and NULL columns.
  • An INTERVAL column (TYPE_INTERVAL), such as the one today() returns, holds two inclusive bounds per value. QwpColumnBatch.getIntervalLo(), getIntervalHi() and getIntervalUnit() read them and their unit: INTERVAL_UNIT_MICROS for TIMESTAMP bounds, INTERVAL_UNIT_NANOS for TIMESTAMP_NS bounds and INTERVAL_UNIT_RAW for the plain integers of a lo:hi range. RowView and ColumnView read the bounds with getIntervalLo() and getIntervalHi().
  • A NULL column (TYPE_NULL) has the type of an untyped NULL, such as the NULL and NaN literals, and every value of it reads as NULL.
  • QwpQueryOptions.designatedTimestamp(true) asks the server which column of the result is its designated timestamp, as /exec reports it in timestamp.
  • QwpQueryDetails.getDesignatedTimestampIndex() returns that column's index in the result's schema, or QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP (-1) when the result has none. hasDesignatedTimestampIndex() tells whether the server reported it at all.
  • It reaches onEnd(requestId, totalRows, details) through QwpQueryClient.execute(...) and the pooled Query.options(...) alike. Statements and errors report none.
  • QwpQueryOptions.omitBinaryValues(true) asks the server to leave the bytes of BINARY values out, as /exec does, which sends every BINARY value as []. Each non-NULL BINARY value then reaches the handler empty, zero bytes long, and a NULL stays NULL; the server neither copies nor sends the bytes.

Compatibility and implementation

  • A server that speaks only QWP version 1 negotiates it, and fails a query whose result has an INTERVAL or NULL column, as before.
  • Connecting to QuestDB 9.4.0 to 9.4.2 or Enterprise 3.3.0 to 3.3.1 now fails at once, where it used to time out waiting for SERVER_INFO. Those servers negotiate version 2 for an earlier wire format, which the client would misread, and the client speaks versions 1 and 3 only (QwpConstants.isSupportedVersion()): the upgrade fails with a QwpVersionMismatchException that asks to upgrade the server.
  • Code that switches over column wire types can now meet TYPE_INTERVAL (0x19) and TYPE_NULL (0x1A), in results of queries that used to fail.
  • TYPE_INTERVAL carries the null flag and bitmap, one unit byte, then the lo and hi bounds of each non-NULL value as int64s. TYPE_NULL carries no bytes, not even the null flag; the NULL columns of a batch share one all-NULL bitmap, so a few bytes on the wire cannot make the decoder allocate a bitmap per column.
  • The decoder fails a RESULT_BATCH whose version is not the one the connection negotiated with a QwpProtocolVersionException.
  • QUERY_FLAG_DESIGNATED_TIMESTAMP (0x80) asks for a designated_timestamp:i32 trailer at the end of RESULT_END, after the row count and the statistics block.
  • QUERY_FLAG_OMIT_BINARY_VALUES (0x100) adds no request field and no trailer. The BINARY column keeps its layout, so the batch decoder is unchanged: an omitted value decodes as an empty one, which getBinary() and getBinaryA() tell apart from NULL.
  • Like the other details, both options need CAP_QUERY_DETAILS: the client drops them for a server without the capability, including after a failover. Such a server sends the BINARY values in full.
  • Query requests without the options remain byte-identical on the wire.
  • A trailer that cannot name a result column, outside -1 to 2047, fails the stream as a decode error, as a truncated trailer does.

The README example shows the new options, and TypedResultExample prints INTERVAL columns.

CI

  • The x64 JDK 8 CI job no longer fetches Maven plugins on every run.

The job shared setup-java's Maven cache key with the JDK 25 and 26 compile jobs, which finish first and save a repository without the plugins of the phases after package. Both JDK 8 jobs now keep a cache of their own.

Tandem PRs: questdb/questdb#8693, questdb/nodejs-questdb-client#83.

Add the designatedTimestamp option to QwpQueryOptions. A server that
advertises CAP_QUERY_DETAILS then ends RESULT_END with
designated_timestamp:i32, after the row count and the statistics
block: the index of the result column that is the designated
timestamp, or NO_DESIGNATED_TIMESTAMP (-1) when the result has none,
as the timestamp of the /exec HTTP endpoint reports it.
QwpQueryDetails passes it to onEnd() through
hasDesignatedTimestampIndex() and getDesignatedTimestampIndex().

- QUERY_FLAG_DESIGNATED_TIMESTAMP (0x80) asks for the trailer. Like the
  other reports, the client drops it for a server without
  CAP_QUERY_DETAILS, after a failover too.
- The decoder rejects a designated_timestamp that cannot name a result
  column, outside -1 to 2047, as a broken stream, the way it rejects a
  truncated trailer.
- Statements and errors carry no designated timestamp.
- The README example asks for it.

Server counterpart: questdb/questdb#8693.
@glasstiger glasstiger added enhancement New feature or request tandem QWP labels Dec 1, 2026
glasstiger added a commit to questdb/questdb that referenced this pull request Dec 1, 2026
Bump java-questdb-client to the commit that adds the
designatedTimestamp query option (questdb/java-questdb-client#135),
and check the designated timestamp through it, as changes to the QWP
wire format require.

- QwpEgressQueryDetailsClientTest compares the index the pinned client
  reports with /exec across table scans, projections, a TIMESTAMP_NS
  table, SAMPLE BY, an ASOF JOIN and an empty result, with and without
  a row window, and checks that it names a TIMESTAMP or TIMESTAMP_NS
  column of the schema the client decoded. It also covers the pooled
  Query facade, statements and errors, and that the client and server
  constants match.
- QwpEgressFuzzTest asks for the designated timestamp a third of the
  time, and checks it against /exec in both of its query paths.

The bump also brings in questdb/java-questdb-client#130, which adds
owned_by to the QWP sender.
Add the omitBinaryValues option to QwpQueryOptions. It sets the new
QUERY_FLAG_OMIT_BINARY_VALUES (0x100) bit of query_flags, which asks a
server that advertises CAP_QUERY_DETAILS to send each non-NULL BINARY
value empty, zero bytes long, and a NULL as NULL, in the usual layout
of the column. The /exec HTTP endpoint never sends BINARY content
either: it writes every BINARY value as []. The server neither copies
nor sends the bytes, so a client that does not read them no longer
waits for them.

- The flag adds no request field and no trailer, and the batch decoder
  needs no change: an omitted value decodes as an empty one, which
  getBinary() and getBinaryA() tell apart from NULL.
- Like the query details, the client drops the flag for a server
  without CAP_QUERY_DETAILS, after a failover too. Such a server sends
  the values in full.
- The README example asks for it.

Server counterpart: questdb/questdb#8693.
glasstiger added a commit to questdb/questdb that referenced this pull request Dec 1, 2026
Bump java-questdb-client to the commit that adds the omitBinaryValues
query option (questdb/java-questdb-client#135), and check the omission
of BINARY values through it, as changes to the QWP wire format require.

- QwpEgressQueryDetailsClientTest checks that each value the pinned
  client decodes is NULL where length() reads -1 and empty elsewhere,
  and as long as length() reads without the option. It covers the page
  frames of parquet and native partitions and of a column top, forwards
  and backwards; the RecordCursors of a filter, a sort, LIMIT, a CASE,
  a join, UNION ALL and a CTE; a row window; and the pooled Query
  facade. It also checks the NULLs of rnd_bin(), which length() does
  not see, that a row whose BINARY value overflows the send buffer
  streams with the option and fails the query without it, and that the
  client and server constants match.
- QwpEgressFuzzTest leaves the BINARY values out a third of the time,
  and its BINARY columns now hold NULLs too.
@glasstiger glasstiger changed the title feat(qwp): report the designated timestamp of query results feat(qwp): report the designated timestamp and omit BINARY values of query results Dec 1, 2026
Ask the query endpoint for QWP version 2, which adds two result column
types, and decode them. A server that speaks only version 1 negotiates
that version and fails a query whose result has a column of either
type, as every server did before.

- INTERVAL (TYPE_INTERVAL, 0x19): the null bitmap, one unit byte, then
  the lo and hi bounds of each non-NULL value as int64s, both
  inclusive. The unit is INTERVAL_UNIT_MICROS for TIMESTAMP bounds,
  INTERVAL_UNIT_NANOS for TIMESTAMP_NS bounds and INTERVAL_UNIT_RAW for
  the plain integers of a lo:hi range. QwpColumnBatch reads them with
  getIntervalLo(), getIntervalHi() and getIntervalUnit(), RowView and
  ColumnView with getIntervalLo() and getIntervalHi().
- NULL (TYPE_NULL, 0x1A): the type of an untyped NULL, such as the NULL
  and NaN literals. Its column carries no bytes, not even the null
  flag, and every value reads as NULL. The NULL columns of a batch share
  one all-NULL bitmap, so a few bytes on the wire cannot make the
  decoder allocate a bitmap per column.
- QwpQueryClient.QWP_MAX_VERSION is now EGRESS_MAX_VERSION, 2. The I/O
  thread hands the decoder the version the upgrade negotiated, and the
  decoder fails a RESULT_BATCH of another version with a
  QwpProtocolVersionException.
- TypedResultExample prints INTERVAL columns.

Server counterpart: questdb/questdb#8693.
glasstiger added a commit to questdb/questdb that referenced this pull request Dec 2, 2026
Bump java-questdb-client to the commit that asks for QWP version 2 and
reads INTERVAL and NULL result columns
(questdb/java-questdb-client#135), and check the new column types
through it, as changes to the QWP wire format require.

- QwpEgressTypesExhaustiveTest reads INTERVAL columns of each unit with
  their bounds and NULLs, today(), INTERVAL values across many batches,
  NULL columns beside other columns, through views, UNION ALL and a
  CTE, and both types in an empty result and in a row window.
- QwpEgressCompressionTest and QwpEgressServerInfoTest expect the
  pinned client to negotiate version 2, the highest the query endpoint
  speaks.
Brings in the per-query timeout of the query client (#105).

QwpQueryClient conflicted where both sides added constants after
QUERY_DETAILS_FLAGS: this branch added QUERY_FLAG_DESIGNATED_TIMESTAMP
and QUERY_FLAG_OMIT_BINARY_VALUES to the query-details flags, and main
added REQUEST_ENCODED_POLL_NANOS. The resolution keeps both.

The new flag bits (0x80, 0x100) do not collide with QUERY_FLAG_TIMEOUT
(0x02), and carry no QUERY_REQUEST field, so timeout_ms, skip_rows and
max_rows keep their order on the wire.
@glasstiger glasstiger changed the title feat(qwp): report the designated timestamp and omit BINARY values of query results feat(qwp): read INTERVAL and NULL columns, report the designated timestamp and omit BINARY values of query results Dec 2, 2026
QwpResultBatchDecoder points the layout of every NULL column at one
shared table of -1s, and replaces that table when a NULL batch outgrows
it. parseNullSection recognised only the current table as shared, so a
layout still holding a replaced one took it as its own. Two nullable
columns in such slots of a later batch then filled the same table, and
the first one read the dense indexes of the second: wrong values, or
bytes from outside its values, without an error. It took a query with
two untyped NULL columns, then a NULL column with more rows, then
nullable columns with NULLs in the same positions, on one connection.

- QwpColumnLayout keeps the table it fills in ownedNonNullIdx, apart
  from nonNullIdx, which a NULL column points at the shared table.
  parseNullSection writes only the owned table, so no layout writes
  into a shared one, current or replaced. A column without NULLs keeps
  its owned table for the next batch with NULLs.
- The all-NULL bitmap grows with the largest NULL batch seen, from 64
  bytes up to the 128 KiB of the largest batch the decoder accepts,
  instead of taking 128 KiB on the first NULL column: a batch of
  16_384 rows, the most the server sends, needs 2 KiB. It moves when
  it grows, as the connection dict and the zstd scratch do, so the
  decode(QwpBatchBuffer) javadoc now keeps a batch valid only until
  the next decode.
- testNullColumnTableGrowthLeavesEveryColumnItsOwnIndex grows the table
  in the same buffer and in another one, then checks every value and
  dense index of three nullable columns, and that the shared table
  stays all -1.
- testNullColumnAtEveryBatchSize replaces
  testNullColumnEveryRowIsNullAtAnyBatchSize, whose comment described
  a per-layout bitmap that does not exist. It also asserts the dense
  index of every row, and the bitmap the decoder holds at each size,
  up to the largest batch it accepts.
QuestDB 9.4.0 to 9.4.2 and Enterprise 3.3.0 to 3.3.1 already negotiate
QWP version 2 on the query endpoint, for an earlier wire format:
version 1 with SERVER_INFO, and table blocks that carry a schema mode
and a schema id. The query client asked for version 2 and accepted any
version from 1 up to it, so against those servers it read the schema
mode and the schema id as the first column definition. The first result
on a connection failed to decode, and after some failed queries a LONG
column arrived as an unnamed BOOLEAN with wrong values, without an
error.

The query client now asks for version 3, which carries the INTERVAL
and NULL columns that version 2 did, and speaks versions 1 and 3 only.

- QwpConstants: EGRESS_MAX_VERSION is VERSION_3. VERSION_2_RETIRED
  names the old version, and isSupportedVersion() tells the versions
  the client speaks up to a maximum: from VERSION to it, except 2.
- WebSocketClient fails the upgrade with QwpVersionMismatchException
  when the server names a version isSupportedVersion() rejects, so the
  client fails to connect to those servers at once instead of
  misreading their frames. For version 2, the message names the
  releases that speak it and asks to upgrade the server.
- QwpResultBatchDecoder reports a version 2 frame as a version the
  client does not speak, not as a mismatch with the negotiated one.
- QwpQueryClientVersionTest drives the upgrade against the mock server:
  the client asks for version 3, runs queries at versions 1 and 3, and
  fails to connect at versions 2, 4 and 99. TestWebSocketServer can
  name the negotiated version and records X-QWP-Max-Version, and
  QwpEgressMockServer stamps the negotiated version on every frame it
  sends, as the server does.
glasstiger added a commit to questdb/questdb that referenced this pull request Dec 2, 2026
QuestDB 9.4.0 to 9.4.2 already negotiate QWP version 2 on the query
endpoint, for an earlier wire format: version 1 with SERVER_INFO, and
table blocks that carry a schema mode and a schema id. The Java clients
released with them still ask for version 2. Reusing the number for the
INTERVAL and NULL columns would have those clients misread this
server's frames, and had those servers send their format to the new
client, which misread it: decode failures, and after some failed
queries a LONG column read as an unnamed BOOLEAN with wrong values.

The INTERVAL and NULL columns now come with version 3, and no
connection runs at version 2.

- QwpConstants: EGRESS_MAX_VERSION is VERSION_3, and VERSION_2_RETIRED
  says why version 2 stays unused.
- QwpEgressUpgradeProcessor.negotiateVersion() picks the highest
  version the endpoint speaks up to the client's maximum: version 3
  for a client that asks for 3 or more, version 1 for one that asks
  for 2, as before version 3.
- QwpColumnTypeMapper maps INTERVAL and NULL from version 3 on.
- QwpEgressVersionWireTest: a version 3 connection carries the new
  columns; a client that asks for version 2, in the header or the URL
  parameter, gets version 1 and fails INTERVAL and NULL queries as
  before; 4 and 99 get version 3.
- QwpEgressIntervalAndNullTypesTest pins negotiateVersion(), and that
  neither version 1 nor version 2 maps the new types.

Bump java-questdb-client to the commit that asks for version 3 and
fails to connect to a server that negotiates version 2
(questdb/java-questdb-client#135). The bump also brings the decoder
fix that gives each column its own null index table, so a nullable
column no longer writes into the table that NULL columns share.
glasstiger added a commit to questdb/nodejs-questdb-client that referenced this pull request Dec 2, 2026
QuestDB 9.4.0 to 9.4.2 and Enterprise 3.3.0 to 3.3.1 already negotiate
QWP version 2 on the query endpoint, for an earlier wire format:
version 1 with SERVER_INFO, and table blocks that carry a schema mode
and a schema id. The query client asked for version 2 and accepted any
version from 1 up to it, so against those servers it would read the
schema mode and the schema id as the first column definition.

The INTERVAL and NULL columns now come with version 3, as on the server
(questdb/questdb#8693) and in the Java client
(questdb/java-questdb-client#135), and the client speaks versions 1 and
3 only.

- QWP_EGRESS_MAX_VERSION is 3: Node sends X-QWP-Max-Version: 3 to
  /read/v1, and a browser the qwp_max_version=3 URL parameter.
- isQwpVersionSupported(), internal to _core/frame.ts, tells the
  versions the client speaks up to a maximum: from 1 to it, except
  version 2, QWP_VERSION_2_RETIRED.
- Node fails the upgrade with a QwpVersionMismatchError when the server
  names a version the client does not speak, at once, rather than
  reading that server's frames. For a version 2 answer to a client that
  asked for more, the message names the releases that speak it and asks
  to upgrade the server. The error stays retryable, and the endpoint
  walk moves on to the next endpoint.
- The frame decoder rejects a frame of version 2 as unsupported, not as
  a mismatch with the negotiated version. A browser, which learns the
  version from SERVER_INFO, refuses a version 2 connection there; no
  released server reads qwp_max_version, so none negotiates version 2
  with a browser.
- Node's maxVersion takes only a version its side speaks: 1 or 3 on
  queries, 1 on ingress. A request for version 2 would get the earlier
  wire format from QuestDB 9.4.0 to 9.4.2, and version 1 from later
  servers.

Regenerate the API reference: most generated-file changes are TypeDoc
source-link and line-number refreshes.
On x64, setup-java's `cache: maven` key (OS, arch, pom hash) is shared
by the JDK 8 build job and the JDK 25/26 compile jobs. The compile jobs
run `clean package -DskipTests`, finish within a minute and save the
cache first; the JDK 8 job's own save then fails with "Unable to reserve
cache". The saved repository lacks the plugins that only the phases
after `package` use, such as maven-dependency-plugin and its dependency
tree and maven-install-plugin, so every x64 JDK 8 run downloaded them
from Maven Central: copy-dependencies took 2.5-4.3 s on x64 against
0.3 s on ARM64, whose cache only the JDK 8 job writes.

One of those downloads, commons-text-1.12.0.jar, stalled on PR #135.
Maven Resolver's default request timeout is 30 minutes, so the job hung
for 30 minutes and then failed, after all tests had passed.

The JDK 8 jobs now cache ~/.m2/repository through actions/cache under a
key of their own, so they save everything they use and stop depending
on Maven Central once the cache is warm. The compile jobs keep
setup-java's cache, which they alone now write.
The @throws clause of QwpEgressIoThread.decodeResultEnd() said the
method fails when the designated timestamp names no result column. The
method sees only the RESULT_END frame, not the schema of the result,
so it rejects only an index outside -1 to MAX_COLUMNS_PER_TABLE - 1,
which names no column of any result: index 5 of a 3-column result
decodes. The clause now states the bound the method checks.

Javadoc only; the decoding does not change.
@glasstiger

Copy link
Copy Markdown
Contributor Author

Review of #135 (level 3), reviewed at a86558d0

Verdict: approve. Nothing blocks the PR. The one optional doc fix is addressed in d40ba339.

The title, labels and description follow the repo conventions and cross-link the tandem PRs. No submodule pointers move and no binaries are committed.

Critical

None.

Moderate

None.

Minor

1. The decodeResultEnd javadoc promised a stricter check than the code makes (in the diff). Fixed in d40ba339.

  • Problem: the @throws clause overstated how the designated_timestamp value is checked.
  • Net impact: none for users. Maintainers could assume the index is checked against the result's columns.
  • Evidence: core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressIoThread.java:269-271 against line 287, at a86558d0.

The javadoc said the method throws when "the designated timestamp names no result column". The check on line 287 only rejects values outside [-1, MAX_COLUMNS_PER_TABLE). This static method has no access to the result's column count, so a 3-column result carrying index 5 decodes cleanly, and that 5 then reaches QwpQueryDetails.getDesignatedTimestampIndex(). QwpEgressTerminatorDecodeTest already pins this range-only behaviour. A correct server never sends such a value, because it writes metadata.getTimestampIndex(). On base this trailer didn't exist.

The clause now reads: "…or the designated timestamp is outside -1 to MAX_COLUMNS_PER_TABLE - 1, where it can name no column of any result".

Coverage

  • Test gate: passes, with no coverage gaps worth reporting.
  • Local tests: the changed test classes pass at a86558d0: 176 tests, 0 failures. At review time this PR's GitHub CI was green on JDK 8 (x64 and ARM64) and on the JDK 25 and 26 compile and MRJAR smoke jobs; Azure coverage and javadoc were pending.
  • OSS tandem: feat(qwp): support INTERVAL and NULL columns, report designated timestamps and omit BINARY values in QWP query results questdb#8693 links back to this PR and pins the client at this PR's head. QwpEgressTypesExhaustiveTest, QwpEgressQueryDetailsClientTest and QwpEgressFuzzTest drive this client against a live server. Its CI was pending at review time.
  • Enterprise tandem: there is none, and I didn't find one to be needed. The sender's version check accepts exactly what it did before (version 1 only), and the query client still treats a version mismatch as a transport error that moves on to the next host.

Summary

  • Correctness gate: passes. Severity: 0 Critical, 0 Moderate, 1 Minor. The Minor is in the diff; nothing outside the diff breaks.
  • Submodules: none of this repo's submodule pointers move; the only one, zstd, is unchanged.
  • Behaviour changes users will see (all intended and documented in the PR):
    • On a server that speaks version 3, queries returning INTERVAL or NULL columns now succeed. Handlers that switch on the column wire type will see the new type codes 0x19 and 0x1A.
    • Against QuestDB 9.4.0–9.4.2 and Enterprise 3.3.0–3.3.1 the client now fails at connect time with a clear message. Before, it timed out waiting for SERVER_INFO. This was confirmed against those release tags.
    • Every release from 9.4.3 through 10.2.0 still negotiates version 1, and that path behaves as on base.

@mtopolnik

Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 108 / 108 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/client/cutlass/qwp/client/QwpProtocolVersionException.java 4 4 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpQueryDetails.java 12 12 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpEgressColumnInfo.java 1 1 100.00%
🔵 io/questdb/client/cutlass/http/client/WebSocketClient.java 1 1 100.00%
🔵 io/questdb/client/cutlass/qwp/protocol/QwpConstants.java 5 5 100.00%
🔵 io/questdb/client/cutlass/qwp/client/ColumnView.java 4 4 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpColumnBatch.java 7 7 100.00%
🔵 io/questdb/client/cutlass/qwp/client/RowView.java 2 2 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpResultBatchDecoder.java 43 43 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java 14 14 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QueryEvent.java 2 2 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpEgressIoThread.java 11 11 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpVersionMismatchException.java 2 2 100.00%

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request QWP tandem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants