Repository navigation
feat(qwp): read INTERVAL and NULL columns, report the designated timestamp and omit BINARY values of query results - #135
glasstiger wants to merge 8 commits into
Conversation
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.
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.
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.
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.
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.
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.
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.
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.
Review of #135 (level 3), reviewed at
|
[PR Coverage check]😍 pass : 108 / 108 (100.00%) file detail
|
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
QwpQueryClient.QWP_MAX_VERSION, nowQwpConstants.EGRESS_MAX_VERSION), whose results can carry INTERVAL and NULL columns.TYPE_INTERVAL), such as the onetoday()returns, holds two inclusive bounds per value.QwpColumnBatch.getIntervalLo(),getIntervalHi()andgetIntervalUnit()read them and their unit:INTERVAL_UNIT_MICROSfor TIMESTAMP bounds,INTERVAL_UNIT_NANOSfor TIMESTAMP_NS bounds andINTERVAL_UNIT_RAWfor the plain integers of alo:hirange.RowViewandColumnViewread the bounds withgetIntervalLo()andgetIntervalHi().TYPE_NULL) has the type of an untyped NULL, such as theNULLandNaNliterals, and every value of it reads as NULL.QwpQueryOptions.designatedTimestamp(true)asks the server which column of the result is its designated timestamp, as/execreports it intimestamp.QwpQueryDetails.getDesignatedTimestampIndex()returns that column's index in the result's schema, orQwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP(-1) when the result has none.hasDesignatedTimestampIndex()tells whether the server reported it at all.onEnd(requestId, totalRows, details)throughQwpQueryClient.execute(...)and the pooledQuery.options(...)alike. Statements and errors report none.QwpQueryOptions.omitBinaryValues(true)asks the server to leave the bytes of BINARY values out, as/execdoes, 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
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 aQwpVersionMismatchExceptionthat asks to upgrade the server.TYPE_INTERVAL(0x19) andTYPE_NULL(0x1A), in results of queries that used to fail.TYPE_INTERVALcarries the null flag and bitmap, one unit byte, then the lo and hi bounds of each non-NULL value as int64s.TYPE_NULLcarries 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.RESULT_BATCHwhose version is not the one the connection negotiated with aQwpProtocolVersionException.QUERY_FLAG_DESIGNATED_TIMESTAMP(0x80) asks for adesignated_timestamp:i32trailer at the end ofRESULT_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, whichgetBinary()andgetBinaryA()tell apart from NULL.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.The README example shows the new options, and
TypedResultExampleprints INTERVAL columns.CI
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.