From 356957cbcb207411b7c75aba90a0fd5df5d17e30 Mon Sep 17 00:00:00 2001 From: glasstiger Date: Tue, 1 Dec 2026 00:26:34 +0000 Subject: [PATCH 1/2] feat(qwp): report the designated timestamp of query results 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. --- README.md | 22 ++-- .../main/java/io/questdb/client/Query.java | 7 +- .../client/cutlass/qwp/client/QueryEvent.java | 12 +- .../qwp/client/QwpColumnBatchHandler.java | 11 +- .../cutlass/qwp/client/QwpEgressIoThread.java | 29 ++++- .../cutlass/qwp/client/QwpEgressMsgKind.java | 25 +++- .../cutlass/qwp/client/QwpQueryClient.java | 10 +- .../cutlass/qwp/client/QwpQueryDetails.java | 42 +++++- .../cutlass/qwp/client/QwpQueryOptions.java | 48 +++++-- .../client/test/QuestDBQueryOptionsTest.java | 32 ++++- .../cutlass/qwp/client/QueryEventTest.java | 18 ++- .../client/QwpEgressTerminatorDecodeTest.java | 120 ++++++++++++++++-- .../QwpQueryClientQueryDetailsTest.java | 83 ++++++++++-- .../client/QwpQueryClientQueryFlagsTest.java | 16 ++- .../qwp/client/QwpQueryOptionsTest.java | 11 +- .../qwp/client/RecordingQueryHandler.java | 13 +- 16 files changed, 422 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 311c985d..e7259dc0 100644 --- a/README.md +++ b/README.md @@ -242,21 +242,23 @@ try (Query q = db.borrowQuery()) { ### Page Through a Result `QwpQueryOptions` asks the server for one page of the result set, and for what the `/exec` HTTP endpoint reports -besides the rows: the row count of the whole result set, execution statistics, and the position of an error in the SQL -text. The handler receives them through the detailed overloads of its callbacks, and a failed `await()` throws a -`QueryException` whose `getPosition()` carries the position. The options need a QuestDB server that supports them; an -older server fails a query that sets `skipRows` or `maxRows`, and runs the others without the details. +besides the rows: the row count of the whole result set, execution statistics, the designated timestamp column, and the +position of an error in the SQL text. The handler receives them through the detailed overloads of its callbacks, and a +failed `await()` throws a `QueryException` whose `getPosition()` carries the position. The options need a QuestDB server +that supports them; an older server fails a query that sets `skipRows` or `maxRows`, and runs the others without the +details. ```java import io.questdb.client.cutlass.qwp.client.QwpQueryDetails; import io.questdb.client.cutlass.qwp.client.QwpQueryOptions; QwpQueryOptions page = new QwpQueryOptions() - .skipRows(100) // leave out the first 100 rows - .maxRows(50) // stream at most 50 rows - .countRows(true) // count the rows of the whole result set - .stats(true) // report compile and execution times - .errorPosition(true); // report where in the SQL text an error is + .skipRows(100) // leave out the first 100 rows + .maxRows(50) // stream at most 50 rows + .countRows(true) // count the rows of the whole result set + .stats(true) // report compile and execution times + .designatedTimestamp(true) // report which column is the designated timestamp + .errorPosition(true); // report where in the SQL text an error is QwpColumnBatchHandler pageHandler = new QwpColumnBatchHandler() { @Override @@ -273,6 +275,8 @@ QwpColumnBatchHandler pageHandler = new QwpColumnBatchHandler() { public void onEnd(long requestId, long totalRows, QwpQueryDetails details) { System.out.println(totalRows + " of " + details.getRowCount() + " rows in " + details.getExecuteNanos() / 1_000 + " us"); + // the column index, or -1 when the result has no designated timestamp + System.out.println("designated timestamp: column " + details.getDesignatedTimestampIndex()); } @Override diff --git a/core/src/main/java/io/questdb/client/Query.java b/core/src/main/java/io/questdb/client/Query.java index 216cbe27..83175576 100644 --- a/core/src/main/java/io/questdb/client/Query.java +++ b/core/src/main/java/io/questdb/client/Query.java @@ -107,9 +107,10 @@ public interface Query extends Closeable { /** * Sets the per-query options: a row window that pages through the result * set, and what the server reports besides the rows -- the row count of the - * whole result set, execution statistics and the error position. See - * {@link QwpQueryOptions}. The handle copies the values, so the instance can - * be reused right away; they apply to every {@link #submit()} until changed. + * whole result set, execution statistics, the designated timestamp column + * and the error position. See {@link QwpQueryOptions}. The handle copies the + * values, so the instance can be reused right away; they apply to every + * {@link #submit()} until changed. * Each {@link #submit()} runs with the options set when it is called, so * changing them while a query is in flight affects only the next one. Pass * null to drop them. diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QueryEvent.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QueryEvent.java index 75b61735..9d1f0d6a 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QueryEvent.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QueryEvent.java @@ -45,7 +45,8 @@ public class QueryEvent { */ public static final int KIND_TRANSPORT_ERROR = 4; - // valid for KIND_END and KIND_EXEC_DONE: the row count and statistics trailers + // valid for KIND_END and KIND_EXEC_DONE: the row count, statistics and + // designated timestamp trailers public final QwpQueryDetails details = new QwpQueryDetails(); public QwpBatchBuffer buffer; // valid for KIND_BATCH (must be released to pool by consumer) public String errorMessage; // valid for KIND_ERROR @@ -122,6 +123,15 @@ public void reset() { this.details.clear(); } + /** + * Records the {@code designated_timestamp} trailer of a {@code RESULT_END} + * on {@link #details}. Call after {@link #asEnd(long)}. + */ + public QueryEvent withDesignatedTimestampIndex(int designatedTimestampIndex) { + this.details.setDesignatedTimestampIndex(designatedTimestampIndex); + return this; + } + /** * Records the {@code row_count} trailer of a {@code RESULT_END} on * {@link #details}. Call after {@link #asEnd(long)}. diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpColumnBatchHandler.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpColumnBatchHandler.java index ce809df6..258505a2 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpColumnBatchHandler.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpColumnBatchHandler.java @@ -83,15 +83,16 @@ default void onEnd(long requestId, long totalRows) { /** * Details-aware overload of {@link #onEnd(long, long)}. Receives what the * query reported besides its rows on the request of {@link QwpQueryOptions}: - * the row count of the whole result set and execution statistics. The - * default delegates to {@link #onEnd(long, long)} for backwards - * compatibility; override this method when you need the details. + * the row count of the whole result set, execution statistics and the + * designated timestamp column. The default delegates to + * {@link #onEnd(long, long)} for backwards compatibility; override this + * method when you need the details. * * @param requestId client-assigned request id (matches {@link QwpColumnBatch#requestId()}) * @param totalRows server-reported number of rows streamed, which a row window * of {@link QwpQueryOptions} bounds - * @param details the row count and statistics the server reported; never null, - * and valid only for the duration of this call + * @param details the row count, statistics and designated timestamp the server + * reported; never null, and valid only for the duration of this call */ default void onEnd(long requestId, long totalRows, QwpQueryDetails details) { onEnd(requestId, totalRows); diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressIoThread.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressIoThread.java index 7fd63f92..c6adb5bc 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressIoThread.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressIoThread.java @@ -252,11 +252,14 @@ public static QueryEvent decodeExecDone(QueryEvent ev, long payload, int payload * {@code msg_kind(1) + request_id(8) + final_seq(varint) + total_rows(varint)}, * then {@code row_count(varint)} when {@code queryFlags} has * {@link QwpEgressMsgKind#QUERY_FLAG_COUNT_ROWS}, then the statistics block - * when it has {@link QwpEgressMsgKind#QUERY_FLAG_STATS}. Bytes after the + * when it has {@link QwpEgressMsgKind#QUERY_FLAG_STATS}, then + * {@code designated_timestamp(i32)} when it has + * {@link QwpEgressMsgKind#QUERY_FLAG_DESIGNATED_TIMESTAMP}. Bytes after the * known fields are ignored. * * @throws QwpDecodeException if the frame ends inside a field the flags call - * for, or a varint does not fit in 64 bits + * for, a varint does not fit in 64 bits, or the + * designated timestamp names no result column */ public static QueryEvent decodeResultEnd(QueryEvent ev, long payload, int payloadLen, long queryFlags) throws QwpDecodeException { TerminatorReader rd = new TerminatorReader("RESULT_END", payload + QwpConstants.HEADER_SIZE + 1 + 8, payload + payloadLen); @@ -268,6 +271,15 @@ public static QueryEvent decodeResultEnd(QueryEvent ev, long payload, int payloa if ((queryFlags & QwpEgressMsgKind.QUERY_FLAG_STATS) != 0) { readStats(rd, ev); } + if ((queryFlags & QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP) != 0) { + int index = rd.int32("designated_timestamp"); + // a result has at most MAX_COLUMNS_PER_TABLE columns, as the batch + // decoder checks: any other value names no column of it + if (index < QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP || index >= QwpConstants.MAX_COLUMNS_PER_TABLE) { + throw new QwpDecodeException("RESULT_END designated_timestamp out of range: " + index); + } + ev.withDesignatedTimestampIndex(index); + } return ev; } @@ -854,6 +866,19 @@ private static final class TerminatorReader { this.limit = limit; } + /** + * Reads a little-endian int32, as the server writes the fixed-width + * trailers. + */ + int int32(String field) throws QwpDecodeException { + if (p + Integer.BYTES > limit) { + throw new QwpDecodeException(frame + " frame truncated " + (p < limit ? "mid " : "before ") + field); + } + int value = Unsafe.getUnsafe().getInt(p); + p += Integer.BYTES; + return value; + } + byte int8(String field) throws QwpDecodeException { if (p >= limit) { throw new QwpDecodeException(frame + " frame truncated before " + field); diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressMsgKind.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressMsgKind.java index 571e1d63..83187b1b 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressMsgKind.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressMsgKind.java @@ -42,9 +42,10 @@ public final class QwpEgressMsgKind { * {@code SERVER_INFO.capabilities} bit: the server honours the query-details * flags of {@code QUERY_REQUEST.query_flags} -- {@link #QUERY_FLAG_ERROR_POSITION}, * {@link #QUERY_FLAG_STATS}, {@link #QUERY_FLAG_COUNT_ROWS}, - * {@link #QUERY_FLAG_SKIP_ROWS} and {@link #QUERY_FLAG_MAX_ROWS}. The client - * sends those bits only when this bit is set: a server without it ignores - * them and answers with the baseline frames. Mirrors the server-side constant + * {@link #QUERY_FLAG_SKIP_ROWS}, {@link #QUERY_FLAG_MAX_ROWS} and + * {@link #QUERY_FLAG_DESIGNATED_TIMESTAMP}. The client sends those bits only + * when this bit is set: a server without it ignores them and answers with + * the baseline frames. Mirrors the server-side constant * {@code io.questdb.cutlass.qwp.codec.QwpEgressMsgKind#CAP_QUERY_DETAILS}. */ public static final int CAP_QUERY_DETAILS = 0x00000010; @@ -79,6 +80,14 @@ public final class QwpEgressMsgKind { * {@code request_id:u64, op_type:u8, rows_affected:varint}. */ public static final byte EXEC_DONE = 0x16; + /** + * Designated timestamp index of a result whose columns include no + * designated timestamp, as the {@code timestamp} of the {@code /exec} HTTP + * endpoint reports it, and of every result when the index was not requested + * or not reported. Mirrors the server-side constant + * {@code io.questdb.cutlass.qwp.codec.QwpEgressMsgKind#NO_DESIGNATED_TIMESTAMP}. + */ + public static final int NO_DESIGNATED_TIMESTAMP = -1; /** * Error position that points nowhere in the SQL text: the position of an * error that does not come from the SQL text, such as a {@code CANCEL} the @@ -98,6 +107,16 @@ public final class QwpEgressMsgKind { * {@link #CAP_QUERY_DETAILS}. */ public static final int QUERY_FLAG_COUNT_ROWS = 0x10; + /** + * {@code QUERY_REQUEST.query_flags} bit: report which column of the result + * is its designated timestamp. {@code RESULT_END} then ends with + * {@code designated_timestamp:i32}, after the statistics block when + * {@link #QUERY_FLAG_STATS} is set too: the index of that column in the + * schema of the result's batches, or {@link #NO_DESIGNATED_TIMESTAMP}. + * Statements that do not produce rows ignore it. Sent only when the server + * advertised {@link #CAP_QUERY_DETAILS}. + */ + public static final int QUERY_FLAG_DESIGNATED_TIMESTAMP = 0x80; /** * {@code QUERY_REQUEST.query_flags} bit: report the error position. A * {@code QUERY_ERROR} then carries the bare message, without the diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryClient.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryClient.java index 20caf9a2..5c5bae36 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryClient.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryClient.java @@ -105,8 +105,8 @@ * {@link #execute(CharSequence, QwpBindSetter, QwpColumnBatchHandler, QwpQueryOptions)} * pages through a result set with a row window, and asks the server for what * the {@code /exec} HTTP endpoint reports besides the rows: the row count of - * the whole result set, execution statistics and the error position. See - * {@link QwpQueryOptions}. + * the whole result set, execution statistics, the designated timestamp column + * and the error position. See {@link QwpQueryOptions}. */ public class QwpQueryClient implements QuietCloseable { @@ -168,7 +168,8 @@ public class QwpQueryClient implements QuietCloseable { | QwpEgressMsgKind.QUERY_FLAG_STATS | QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS | QwpEgressMsgKind.QUERY_FLAG_SKIP_ROWS - | QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS; + | QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS + | QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP; // query_flags bits of the row window, which change what the server streams private static final int ROW_WINDOW_QUERY_FLAGS = QwpEgressMsgKind.QUERY_FLAG_SKIP_ROWS | QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS; @@ -821,7 +822,8 @@ public void execute(CharSequence sql, QwpBindSetter binds, QwpColumnBatchHandler * As {@link #execute(CharSequence, QwpBindSetter, QwpColumnBatchHandler)}, * with per-query {@code options}: a row window that pages through the * result set, and what the server reports besides the rows -- the row count - * of the whole result set and execution statistics, which reach + * of the whole result set, execution statistics and the designated + * timestamp column, which reach * {@link QwpColumnBatchHandler#onEnd(long, long, QwpQueryDetails)} and * {@link QwpColumnBatchHandler#onExecDone(long, short, long, QwpQueryDetails)}, * and the error position, which reaches diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryDetails.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryDetails.java index 0b683c7a..db67ad15 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryDetails.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryDetails.java @@ -26,8 +26,8 @@ /** * What a successful query reported besides its rows, on the request of - * {@link QwpQueryOptions}: the row count of the whole result set and execution - * statistics. Passed to + * {@link QwpQueryOptions}: the row count of the whole result set, execution + * statistics and the designated timestamp column. Passed to * {@link QwpColumnBatchHandler#onEnd(long, long, QwpQueryDetails)} and * {@link QwpColumnBatchHandler#onExecDone(long, short, long, QwpQueryDetails)}, * never null. @@ -40,7 +40,9 @@ public final class QwpQueryDetails { private long clientWaitNanos = -1; private long compileNanos = -1; private long countNanos = -1; + private int designatedTimestampIndex = QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP; private long executeNanos = -1; + private boolean hasDesignatedTimestampIndex; private boolean hasRowCount; private boolean hasStats; private boolean isJitCompiled; @@ -74,6 +76,17 @@ public long getCountNanos() { return countNanos; } + /** + * Returns the index of the result column that is the designated timestamp, + * in the schema of the result's batches, as the {@code timestamp} of the + * {@code /exec} HTTP endpoint reports it. + * {@link QwpEgressMsgKind#NO_DESIGNATED_TIMESTAMP} when the result has no + * designated timestamp, or {@link #hasDesignatedTimestampIndex()} is false. + */ + public int getDesignatedTimestampIndex() { + return designatedTimestampIndex; + } + /** * Returns how long, in nanoseconds, the query ran on the server, from the * arrival of the request to its last frame, or -1 when {@link #hasStats()} @@ -92,6 +105,18 @@ public long getRowCount() { return rowCount; } + /** + * Returns true when the server reported which column of the result is its + * designated timestamp: the query asked for it with + * {@link QwpQueryOptions#designatedTimestamp(boolean)}, the server advertises + * {@link QwpEgressMsgKind#CAP_QUERY_DETAILS}, and the statement produced + * rows. {@link #getDesignatedTimestampIndex()} may still be + * {@link QwpEgressMsgKind#NO_DESIGNATED_TIMESTAMP}: the result has none. + */ + public boolean hasDesignatedTimestampIndex() { + return hasDesignatedTimestampIndex; + } + /** * Returns true when the server reported the row count of the whole result * set: the query asked for it with {@link QwpQueryOptions#countRows(boolean)}, @@ -135,6 +160,12 @@ public String toString() { .append(", clientWaitNanos=").append(clientWaitNanos) .append(", jitCompiled=").append(isJitCompiled); } + if (hasDesignatedTimestampIndex) { + if (hasRowCount || hasStats) { + sb.append(", "); + } + sb.append("designatedTimestampIndex=").append(designatedTimestampIndex); + } return sb.append('}').toString(); } @@ -142,13 +173,20 @@ void clear() { clientWaitNanos = -1; compileNanos = -1; countNanos = -1; + designatedTimestampIndex = QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP; executeNanos = -1; + hasDesignatedTimestampIndex = false; hasRowCount = false; hasStats = false; isJitCompiled = false; rowCount = -1; } + void setDesignatedTimestampIndex(int designatedTimestampIndex) { + this.designatedTimestampIndex = designatedTimestampIndex; + this.hasDesignatedTimestampIndex = true; + } + void setRowCount(long rowCount) { this.rowCount = rowCount; this.hasRowCount = true; diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java index 93f5034e..b57f474f 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java @@ -29,17 +29,19 @@ * {@link QwpQueryClient#execute(CharSequence, QwpBindSetter, QwpColumnBatchHandler, QwpQueryOptions)} * and {@link io.questdb.client.Query#options(QwpQueryOptions)}: a row window * that pages through the result set, and what the server reports besides the - * rows -- the row count of the whole result set, execution statistics and the - * position of an error in the SQL text. A new instance has every option off, - * and a query run with it is the same on the wire as one run without options. + * rows -- the row count of the whole result set, execution statistics, the + * designated timestamp column and the position of an error in the SQL text. A + * new instance has every option off, and a query run with it is the same on + * the wire as one run without options. *

- * The row window, the row count, the statistics and the error position need a - * server that advertises {@link QwpEgressMsgKind#CAP_QUERY_DETAILS}. Against a - * server without it, the client fails a query that sets a row window, since the - * server would stream every row, and runs a query that asks only for the row - * count, the statistics or the error position without them: the handler then - * sees {@link QwpQueryDetails#hasRowCount()} and - * {@link QwpQueryDetails#hasStats()} false and the position + * The row window, the row count, the statistics, the designated timestamp and + * the error position need a server that advertises + * {@link QwpEgressMsgKind#CAP_QUERY_DETAILS}. Against a server without it, the + * client fails a query that sets a row window, since the server would stream + * every row, and runs a query that asks only for the reports without them: the + * handler then sees {@link QwpQueryDetails#hasRowCount()}, + * {@link QwpQueryDetails#hasStats()} and + * {@link QwpQueryDetails#hasDesignatedTimestampIndex()} false and the position * {@link QwpEgressMsgKind#NO_ERROR_POSITION}. *

* The client reads the options when the query starts, so one instance can be @@ -48,6 +50,7 @@ */ public final class QwpQueryOptions { + private boolean isDesignatedTimestampRequested; private boolean isErrorPositionRequested; private boolean isRowCountRequested; private boolean isStatsRequested; @@ -62,6 +65,7 @@ public final class QwpQueryOptions { * @return this instance */ public QwpQueryOptions clear() { + isDesignatedTimestampRequested = false; isErrorPositionRequested = false; isRowCountRequested = false; isStatsRequested = false; @@ -81,6 +85,7 @@ public QwpQueryOptions copyFrom(QwpQueryOptions other) { if (other == null) { return clear(); } + isDesignatedTimestampRequested = other.isDesignatedTimestampRequested; isErrorPositionRequested = other.isErrorPositionRequested; isRowCountRequested = other.isRowCountRequested; isStatsRequested = other.isStatsRequested; @@ -106,6 +111,21 @@ public QwpQueryOptions countRows(boolean isRequested) { return this; } + /** + * Asks the server which column of the result is its designated timestamp, + * as the {@code timestamp} of the {@code /exec} HTTP endpoint reports it. + * The column's index, in the schema of the result's batches, or + * {@link QwpEgressMsgKind#NO_DESIGNATED_TIMESTAMP} when the result has none, + * reaches {@link QwpColumnBatchHandler#onEnd(long, long, QwpQueryDetails)}. + * Statements that do not produce rows report none. + * + * @return this instance + */ + public QwpQueryOptions designatedTimestamp(boolean isRequested) { + isDesignatedTimestampRequested = isRequested; + return this; + } + /** * Asks the server for the position of an error in the SQL text, as the * {@code position} of the {@code /exec} HTTP endpoint. A failed query then @@ -136,6 +156,10 @@ public long getSkipRows() { return skipRows; } + public boolean isDesignatedTimestampRequested() { + return isDesignatedTimestampRequested; + } + public boolean isErrorPositionRequested() { return isErrorPositionRequested; } @@ -225,6 +249,7 @@ public String toString() { + ", countRows=" + isRowCountRequested + ", stats=" + isStatsRequested + ", errorPosition=" + isErrorPositionRequested + + ", designatedTimestamp=" + isDesignatedTimestampRequested + ", resetSymbolDict=" + isSymbolDictResetRequested + '}'; } @@ -253,6 +278,9 @@ long toQueryFlags() { if (maxRows != Long.MAX_VALUE) { flags |= QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS; } + if (isDesignatedTimestampRequested) { + flags |= QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP; + } return flags; } } diff --git a/core/src/test/java/io/questdb/client/test/QuestDBQueryOptionsTest.java b/core/src/test/java/io/questdb/client/test/QuestDBQueryOptionsTest.java index 32a398bb..2047459e 100644 --- a/core/src/test/java/io/questdb/client/test/QuestDBQueryOptionsTest.java +++ b/core/src/test/java/io/questdb/client/test/QuestDBQueryOptionsTest.java @@ -72,6 +72,28 @@ public void testAbandonDropsOptions() throws Exception { }); } + @Test + public void testDesignatedTimestampReachesOnEnd() throws Exception { + TestUtils.assertMemoryLeak(() -> { + try (QwpEgressMockServer server = new QwpEgressMockServer(ALL_CAPABILITIES, QuestDBQueryOptionsTest::model); + QuestDB db = connect(server); + Query q = db.borrowQuery()) { + RecordingQueryHandler handler = new RecordingQueryHandler(); + q.sql("SELECT x").options(new QwpQueryOptions().designatedTimestamp(true)).handler(handler).submit().await(); + handler.assertNoWrongOverloads(); + Assert.assertEquals(1, handler.endCount); + Assert.assertTrue(handler.hasDesignatedTimestampIndex); + Assert.assertEquals(0, handler.designatedTimestampIndex); + Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP, server.getRequests().get(0).queryFlags); + + // the next query without the option reports none + q.options(null).submit().await(); + handler.assertNoDetails(); + server.assertNoFailure(); + } + }); + } + @Test public void testErrorPositionReachesQueryException() throws Exception { TestUtils.assertMemoryLeak(() -> { @@ -292,9 +314,10 @@ private static QuestDB connect(QwpEgressMockServer server) { } /** - * A 10-row table {@code x = 0..9} in one batch per query; an - * {@code INSERT} that reports 4 rows; anything else fails at position 7. - * Trailers follow the flags of the request, as on the server. + * A 10-row table {@code x = 0..9} in one batch per query, whose designated + * timestamp is {@code x}; an {@code INSERT} that reports 4 rows; anything + * else fails at position 7. Trailers follow the flags of the request, as on + * the server. */ private static byte[][] model(QwpEgressFrames.QueryRequest r) { boolean hasStats = r.has(QwpEgressMsgKind.QUERY_FLAG_STATS); @@ -312,6 +335,9 @@ private static byte[][] model(QwpEgressFrames.QueryRequest r) { if (hasStats) { end.stats(123, 456, 0, 0, 0); } + if (r.has(QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP)) { + end.i32(0); + } return new byte[][]{QwpEgressFrames.resultBatchOfLongs(r.requestId, 0, values), end.toFrame()}; } if (r.sql.startsWith("INSERT")) { diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QueryEventTest.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QueryEventTest.java index a1762fc8..5adfecc7 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QueryEventTest.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QueryEventTest.java @@ -51,10 +51,10 @@ public void testAsBatchSetsBufferAndKind() { @Test public void testAsEndAndAsExecDoneDropStaleDetails() { - QueryEvent ev = new QueryEvent().asEnd(1).withRowCount(9).withStats(1, 2, 3, 4, true); + QueryEvent ev = new QueryEvent().asEnd(1).withRowCount(9).withStats(1, 2, 3, 4, true).withDesignatedTimestampIndex(3); ev.asEnd(2); RecordingQueryHandler.assertNoDetails(ev.details); - ev.withRowCount(9).withStats(1, 2, 3, 4, true).asExecDone((short) 1, 2); + ev.withRowCount(9).withStats(1, 2, 3, 4, true).withDesignatedTimestampIndex(3).asExecDone((short) 1, 2); RecordingQueryHandler.assertNoDetails(ev.details); } @@ -199,6 +199,20 @@ public void testResetClearsEverythingFromExecDone() { Assert.assertEquals(0L, ev.rowsAffected); } + @Test + public void testWithDesignatedTimestampIndex() { + QueryEvent ev = new QueryEvent().asEnd(5); + Assert.assertSame("builder must return this for chaining", ev, ev.withDesignatedTimestampIndex(2)); + Assert.assertTrue(ev.details.hasDesignatedTimestampIndex()); + Assert.assertEquals(2, ev.details.getDesignatedTimestampIndex()); + // a result without a designated timestamp still reports it + ev.asEnd(5).withDesignatedTimestampIndex(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP); + Assert.assertTrue(ev.details.hasDesignatedTimestampIndex()); + Assert.assertEquals(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP, ev.details.getDesignatedTimestampIndex()); + ev.withDesignatedTimestampIndex(1).reset(); + RecordingQueryHandler.assertNoDetails(ev.details); + } + @Test public void testWithRowCountAndStats() { QueryEvent ev = new QueryEvent().asEnd(5); diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpEgressTerminatorDecodeTest.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpEgressTerminatorDecodeTest.java index 46eb962d..31368084 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpEgressTerminatorDecodeTest.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpEgressTerminatorDecodeTest.java @@ -43,9 +43,9 @@ /** * Decoding of the trailers the query-details flags add to the terminator - * frames: {@code row_count} and the statistics block on {@code RESULT_END}, - * the statistics block on {@code EXEC_DONE}, and {@code position} on - * {@code QUERY_ERROR}. The frames are built byte by byte in the layout of the + * frames: {@code row_count}, the statistics block and + * {@code designated_timestamp} on {@code RESULT_END}, the statistics block on + * {@code EXEC_DONE}, and {@code position} on {@code QUERY_ERROR}. The frames are built byte by byte in the layout of the * server's {@code QwpEgressFrameWriter}, and decoded through the same static * decoders the I/O thread runs, with the flags the request carried. */ @@ -55,12 +55,36 @@ public class QwpEgressTerminatorDecodeTest { | QwpEgressMsgKind.QUERY_FLAG_STATS | QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS | QwpEgressMsgKind.QUERY_FLAG_SKIP_ROWS - | QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS; + | QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS + | QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP; + private static final int DESIGNATED_TIMESTAMP = QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP; + // the flags of the trailers RESULT_END can carry + private static final int RESULT_END_TRAILER_FLAGS = QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS + | QwpEgressMsgKind.QUERY_FLAG_STATS + | DESIGNATED_TIMESTAMP; private static final int PRELUDE = QwpConstants.HEADER_SIZE + 1 + 8; private static final long[] VARINT_VALUES = { 0, 1, 127, 128, 16_383, 16_384, 1_000_000_000L, Long.MAX_VALUE - 1, Long.MAX_VALUE }; + @Test + public void testExecDoneCarriesNoDesignatedTimestamp() throws Exception { + // a statement produces no rows: the statistics follow rows_affected, + // and a frame without trailers is whole, whatever the flags + TestUtils.assertMemoryLeak(() -> { + byte[] withStats = QwpEgressFrames.execDone(3, 2, 30).stats(11, 22, 0, 44, 1).toFrame(); + QueryEvent ev = decodeExecDone(withStats, DESIGNATED_TIMESTAMP | QwpEgressMsgKind.QUERY_FLAG_STATS); + Assert.assertEquals(30, ev.rowsAffected); + assertStats(ev.details, 11, 22, 0, 44, true); + Assert.assertFalse(ev.details.hasDesignatedTimestampIndex()); + Assert.assertEquals(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP, ev.details.getDesignatedTimestampIndex()); + + ev = decodeExecDone(QwpEgressFrames.execDone(3, 2, 30).toFrame(), DESIGNATED_TIMESTAMP); + Assert.assertEquals(30, ev.rowsAffected); + RecordingQueryHandler.assertNoDetails(ev.details); + }); + } + @Test public void testExecDoneCarriesNoRowCount() throws Exception { // COUNT_ROWS does not apply to statements without rows: the statistics @@ -257,6 +281,36 @@ public void testQueryErrorWithoutTrailerWhenPositionRequested() throws Exception }); } + @Test + public void testResultEndDesignatedTimestamp() throws Exception { + // a column index, or NO_DESIGNATED_TIMESTAMP for a result without one + TestUtils.assertMemoryLeak(() -> { + for (int index : new int[]{QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP, 0, 1, 255, 256, QwpConstants.MAX_COLUMNS_PER_TABLE - 1}) { + byte[] frame = QwpEgressFrames.resultEnd(7, 0, 5).i32(index).toFrame(); + QueryEvent ev = decodeResultEnd(frame, DESIGNATED_TIMESTAMP); + Assert.assertEquals(QueryEvent.KIND_END, ev.kind); + Assert.assertEquals(5, ev.totalRows); + Assert.assertTrue(ev.details.hasDesignatedTimestampIndex()); + Assert.assertEquals(index, ev.details.getDesignatedTimestampIndex()); + Assert.assertFalse(ev.details.hasRowCount()); + Assert.assertFalse(ev.details.hasStats()); + Assert.assertEquals("QwpQueryDetails{designatedTimestampIndex=" + index + '}', ev.details.toString()); + } + }); + } + + @Test + public void testResultEndDesignatedTimestampOutOfRange() throws Exception { + // a result has at most MAX_COLUMNS_PER_TABLE columns, and -1 is the only + // index that names none + TestUtils.assertMemoryLeak(() -> { + for (int index : new int[]{-2, QwpConstants.MAX_COLUMNS_PER_TABLE, Integer.MIN_VALUE, Integer.MAX_VALUE}) { + byte[] frame = QwpEgressFrames.resultEnd(7, 0, 5).i32(index).toFrame(); + assertDecodeFails("RESULT_END designated_timestamp out of range: " + index, frame, DESIGNATED_TIMESTAMP, false); + } + }); + } + @Test public void testResultEndRowCount() throws Exception { TestUtils.assertMemoryLeak(() -> { @@ -276,7 +330,8 @@ public void testResultEndRowCount() throws Exception { public void testResultEndRowCountThenStats() throws Exception { TestUtils.assertMemoryLeak(() -> { byte[] frame = QwpEgressFrames.resultEnd(7, 2, 50).varint(100).stats(1_500, 900_000, 300, 0, 0).toFrame(); - for (long flags : new long[]{QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS | QwpEgressMsgKind.QUERY_FLAG_STATS, ALL_FLAGS}) { + // the flags that add no RESULT_END trailer leave the decode alone + for (long flags : new long[]{QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS | QwpEgressMsgKind.QUERY_FLAG_STATS, ALL_FLAGS & ~DESIGNATED_TIMESTAMP}) { QueryEvent ev = decodeResultEnd(frame, flags); Assert.assertEquals(50, ev.totalRows); Assert.assertTrue(ev.details.hasRowCount()); @@ -288,6 +343,41 @@ public void testResultEndRowCountThenStats() throws Exception { }); } + @Test + public void testResultEndRowCountThenStatsThenDesignatedTimestamp() throws Exception { + TestUtils.assertMemoryLeak(() -> { + byte[] frame = QwpEgressFrames.resultEnd(7, 2, 50).varint(100).stats(1_500, 900_000, 300, 0, 0).i32(2).toFrame(); + for (long flags : new long[]{RESULT_END_TRAILER_FLAGS, ALL_FLAGS}) { + QueryEvent ev = decodeResultEnd(frame, flags); + Assert.assertEquals(50, ev.totalRows); + Assert.assertTrue(ev.details.hasRowCount()); + Assert.assertEquals(100, ev.details.getRowCount()); + assertStats(ev.details, 1_500, 900_000, 300, 0, false); + Assert.assertTrue(ev.details.hasDesignatedTimestampIndex()); + Assert.assertEquals(2, ev.details.getDesignatedTimestampIndex()); + Assert.assertEquals("QwpQueryDetails{rowCount=100, compileNanos=1500, executeNanos=900000, " + + "countNanos=300, clientWaitNanos=0, jitCompiled=false, designatedTimestampIndex=2}", ev.details.toString()); + } + + // the statistics, then the designated timestamp, without a row count + frame = QwpEgressFrames.resultEnd(7, 0, 5).stats(1, 2, 3, 4, 1).i32(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP).toFrame(); + QueryEvent ev = decodeResultEnd(frame, QwpEgressMsgKind.QUERY_FLAG_STATS | DESIGNATED_TIMESTAMP); + Assert.assertFalse(ev.details.hasRowCount()); + assertStats(ev.details, 1, 2, 3, 4, true); + Assert.assertEquals(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP, ev.details.getDesignatedTimestampIndex()); + Assert.assertEquals("QwpQueryDetails{compileNanos=1, executeNanos=2, countNanos=3, clientWaitNanos=4, " + + "jitCompiled=true, designatedTimestampIndex=-1}", ev.details.toString()); + + // the row count, then the designated timestamp, without statistics + frame = QwpEgressFrames.resultEnd(7, 0, 5).varint(9).i32(0).toFrame(); + ev = decodeResultEnd(frame, QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS | DESIGNATED_TIMESTAMP); + Assert.assertEquals(9, ev.details.getRowCount()); + Assert.assertFalse(ev.details.hasStats()); + Assert.assertEquals(0, ev.details.getDesignatedTimestampIndex()); + Assert.assertEquals("QwpQueryDetails{rowCount=9, designatedTimestampIndex=0}", ev.details.toString()); + }); + } + @Test public void testResultEndStats() throws Exception { TestUtils.assertMemoryLeak(() -> { @@ -325,8 +415,8 @@ public void testResultEndTruncatedAtEveryByte() throws Exception { appendField(body, fields, "total_rows", b -> b.varint(16_384)); appendField(body, fields, "row_count", b -> b.varint(1_000_000)); appendStatsFields(body, fields); - assertTruncatedAtEveryByte(body.toFrame(), fields, "RESULT_END", - QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS | QwpEgressMsgKind.QUERY_FLAG_STATS, false); + appendField(body, fields, "designated_timestamp", b -> b.i32(1)); + assertTruncatedAtEveryByte(body.toFrame(), fields, "RESULT_END", RESULT_END_TRAILER_FLAGS, false); }); } @@ -367,9 +457,9 @@ public void testResultEndVarintUsesAll64Bits() throws Exception { public void testResultEndWithoutFlagsIgnoresTrailers() throws Exception { TestUtils.assertMemoryLeak(() -> { byte[] baseline = QwpEgressFrames.resultEnd(7, 2, 30).toFrame(); - byte[] withTrailers = QwpEgressFrames.resultEnd(7, 2, 30).varint(100).stats(1, 2, 3, 4, 1).toFrame(); + byte[] withTrailers = QwpEgressFrames.resultEnd(7, 2, 30).varint(100).stats(1, 2, 3, 4, 1).i32(1).toFrame(); for (byte[] frame : new byte[][]{baseline, withTrailers}) { - for (long flags : new long[]{0, ALL_FLAGS & ~(QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS | QwpEgressMsgKind.QUERY_FLAG_STATS)}) { + for (long flags : new long[]{0, ALL_FLAGS & ~RESULT_END_TRAILER_FLAGS}) { QueryEvent ev = decodeResultEnd(frame, flags); Assert.assertEquals(QueryEvent.KIND_END, ev.kind); Assert.assertEquals(30, ev.totalRows); @@ -457,8 +547,16 @@ private static void assertTruncatedAtEveryByte( Assert.assertEquals(PRELUDE + fields.size(), frame.length); for (int len = PRELUDE; len < frame.length; len++) { String field = fields.get(len - PRELUDE); - boolean isByteField = "op_type".equals(field) || "stats_flags".equals(field); - String expected = frameName + " frame truncated " + (isByteField ? "before " + field : "mid " + field + " varint"); + String expected; + if ("op_type".equals(field) || "stats_flags".equals(field)) { + expected = frameName + " frame truncated before " + field; + } else if ("designated_timestamp".equals(field)) { + // a fixed-width i32: cut before its first byte, or inside it + boolean isFirstByte = !field.equals(fields.get(len - PRELUDE - 1)); + expected = frameName + " frame truncated " + (isFirstByte ? "before " : "mid ") + field; + } else { + expected = frameName + " frame truncated mid " + field + " varint"; + } assertDecodeFails(expected, Arrays.copyOf(frame, len), flags, isExecDone); } // the whole frame decodes diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryDetailsTest.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryDetailsTest.java index b3cf0965..520ecff9 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryDetailsTest.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryDetailsTest.java @@ -49,15 +49,19 @@ * request asked for and the handler receives them. The mock server models the * server's {@code QwpEgressUpgradeProcessor}: a 10-row table {@code x = 0..9} * streamed in batches of up to 3 rows, cut by the row window; trailers only - * for the flags the request carries; the bare message and the position of an - * error only under {@code QUERY_FLAG_ERROR_POSITION}. The questdb repo checks - * the same against a live server. + * for the flags the request carries, where {@code x} is the designated + * timestamp of a query that ends with {@code TIMESTAMP(x)} and of no other; + * the bare message and the position of an error only under + * {@code QUERY_FLAG_ERROR_POSITION}. The questdb repo checks the same against + * a live server. */ public class QwpQueryClientQueryDetailsTest { private static final int ALL_CAPABILITIES = QwpEgressMsgKind.CAP_QUERY_FLAGS | QwpEgressMsgKind.CAP_QUERY_DETAILS; private static final long CLIENT_WAIT_NANOS = 44; private static final long COMPILE_NANOS = 11; private static final long COUNT_NANOS = 33; + // a query of the model whose result designates x, column 0, as its timestamp + private static final String DESIGNATED_SQL = "SELECT x FROM t TIMESTAMP(x)"; private static final String ERROR_MESSAGE = "Invalid column: nope"; private static final int ERROR_POSITION = 7; private static final long EXECUTE_NANOS = 22; @@ -65,6 +69,52 @@ public class QwpQueryClientQueryDetailsTest { private static final long ROWS_AFFECTED = 5; private static final int TABLE_ROWS = 10; + @Test + public void testDesignatedTimestampReachesOnEnd() throws Exception { + TestUtils.assertMemoryLeak(() -> { + try (QwpEgressMockServer server = new QwpEgressMockServer(ALL_CAPABILITIES, QwpQueryClientQueryDetailsTest::model); + QwpQueryClient client = newClient(server, "")) { + client.connect(); + QwpQueryOptions options = new QwpQueryOptions().designatedTimestamp(true); + RecordingQueryHandler designated = new RecordingQueryHandler(); + client.execute(DESIGNATED_SQL, designated, options); + Assert.assertEquals(1, designated.endCount); + Assert.assertEquals(TABLE_ROWS, designated.values.size()); + Assert.assertTrue(designated.hasDesignatedTimestampIndex); + Assert.assertEquals(0, designated.designatedTimestampIndex); + Assert.assertFalse(designated.hasRowCount); + Assert.assertFalse(designated.hasStats); + Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP, server.getRequests().get(0).queryFlags); + + // a result without a designated timestamp reports that it has none + RecordingQueryHandler none = new RecordingQueryHandler(); + client.execute("SELECT x FROM t", none, options); + Assert.assertTrue(none.hasDesignatedTimestampIndex); + Assert.assertEquals(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP, none.designatedTimestampIndex); + + // it follows the row count and the statistics, whatever the row window + RecordingQueryHandler windowed = new RecordingQueryHandler(); + client.execute(DESIGNATED_SQL, windowed, new QwpQueryOptions() + .designatedTimestamp(true).countRows(true).stats(true).skipRows(2).maxRows(3)); + Assert.assertEquals(Arrays.asList(2L, 3L, 4L), windowed.values); + Assert.assertEquals(TABLE_ROWS, windowed.rowCount); + Assert.assertTrue(windowed.hasStats); + Assert.assertEquals(COMPILE_NANOS, windowed.compileNanos); + Assert.assertTrue(windowed.hasDesignatedTimestampIndex); + Assert.assertEquals(0, windowed.designatedTimestampIndex); + + // a statement reports none + RecordingQueryHandler insert = new RecordingQueryHandler(); + client.execute("INSERT INTO t VALUES (1)", insert, new QwpQueryOptions().designatedTimestamp(true).stats(true)); + Assert.assertEquals(1, insert.execDoneCount); + Assert.assertTrue(insert.hasStats); + Assert.assertFalse(insert.hasDesignatedTimestampIndex); + Assert.assertEquals(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP, insert.designatedTimestampIndex); + server.assertNoFailure(); + } + }); + } + @Test public void testDetailsAbsentWithoutCapability() throws Exception { // the client leaves out what the server cannot report, and the server @@ -74,10 +124,11 @@ public void testDetailsAbsentWithoutCapability() throws Exception { QwpQueryClientQueryDetailsTest::model); QwpQueryClient client = newClient(server, "")) { client.connect(); - QwpQueryOptions options = new QwpQueryOptions().countRows(true).stats(true).errorPosition(true); + QwpQueryOptions options = new QwpQueryOptions().countRows(true).stats(true).errorPosition(true) + .designatedTimestamp(true); RecordingQueryHandler select = new RecordingQueryHandler(); - client.execute("SELECT x FROM t", select, options); + client.execute(DESIGNATED_SQL, select, options); Assert.assertEquals(1, select.endCount); Assert.assertEquals(TABLE_ROWS, select.totalRows); select.assertNoDetails(); @@ -157,13 +208,15 @@ public void testDetailsDoNotLeakToTheNextQuery() throws Exception { try (QwpEgressMockServer server = new QwpEgressMockServer(ALL_CAPABILITIES, QwpQueryClientQueryDetailsTest::model); QwpQueryClient client = newClient(server, "")) { client.connect(); - QwpQueryOptions options = new QwpQueryOptions().countRows(true).stats(true).errorPosition(true).maxRows(2); + QwpQueryOptions options = new QwpQueryOptions().countRows(true).stats(true).errorPosition(true) + .designatedTimestamp(true).maxRows(2); for (int i = 0; i < 2; i++) { RecordingQueryHandler detailed = new RecordingQueryHandler(); - client.execute("SELECT x FROM t", detailed, options); + client.execute(DESIGNATED_SQL, detailed, options); Assert.assertEquals(Arrays.asList(0L, 1L), detailed.values); Assert.assertEquals(TABLE_ROWS, detailed.rowCount); Assert.assertTrue(detailed.hasStats); + Assert.assertEquals(0, detailed.designatedTimestampIndex); RecordingQueryHandler plain = new RecordingQueryHandler(); client.execute("SELECT x FROM t", plain); @@ -220,12 +273,14 @@ public void testFailoverChecksTheNewServerAgain() throws Exception { try (QwpQueryClient client = QwpQueryClient.fromConfig(config)) { client.connect(); RecordingQueryHandler handler = new RecordingQueryHandler(); - client.execute("SELECT x FROM t", handler, new QwpQueryOptions().stats(true).countRows(true)); + client.execute("SELECT x FROM t", handler, new QwpQueryOptions().stats(true).countRows(true) + .designatedTimestamp(true)); Assert.assertEquals(1, handler.failoverResetCount); Assert.assertEquals(1, handler.endCount); Assert.assertEquals(TABLE_ROWS, handler.values.size()); handler.assertNoDetails(); - Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_STATS | QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS, + Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_STATS | QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS + | QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP, dying.getRequests().get(0).queryFlags); Assert.assertFalse(old.getRequests().get(0).hasQueryFlags); } @@ -401,6 +456,7 @@ public void testMissingTrailerIsTransportFailure() throws Exception { {"SELECT x FROM t", new QwpQueryOptions().countRows(true), "RESULT_END frame truncated mid row_count varint"}, {"SELECT x FROM t", new QwpQueryOptions().stats(true), "RESULT_END frame truncated mid compile_ns varint"}, {"INSERT INTO t VALUES (1)", new QwpQueryOptions().stats(true), "EXEC_DONE frame truncated mid compile_ns varint"}, + {DESIGNATED_SQL, new QwpQueryOptions().designatedTimestamp(true), "RESULT_END frame truncated before designated_timestamp"}, }; for (Object[] c : cases) { TestUtils.assertMemoryLeak(() -> { @@ -521,8 +577,10 @@ private static byte[][] model(QwpEgressFrames.QueryRequest r) { /** * Answers {@code r} the way the server does, with the trailers of * {@code trailerFlags}: a {@code SELECT} streams the row window of the - * 10-row table, an {@code INSERT} reports {@value #ROWS_AFFECTED} rows, and - * anything else fails at position {@value #ERROR_POSITION}. + * 10-row table, and designates {@code x} as its timestamp when it is + * {@value #DESIGNATED_SQL}, an {@code INSERT} reports + * {@value #ROWS_AFFECTED} rows, and anything else fails at position + * {@value #ERROR_POSITION}. */ private static byte[][] model(QwpEgressFrames.QueryRequest r, long trailerFlags) { List frames = new ArrayList<>(); @@ -548,6 +606,9 @@ private static byte[][] model(QwpEgressFrames.QueryRequest r, long trailerFlags) if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_STATS) != 0) { end0.stats(COMPILE_NANOS, EXECUTE_NANOS, COUNT_NANOS, CLIENT_WAIT_NANOS, QwpEgressMsgKind.STATS_FLAG_JIT_COMPILED); } + if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP) != 0) { + end0.i32(r.sql.equals(DESIGNATED_SQL) ? 0 : QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP); + } frames.add(end0.toFrame()); } else if (r.sql.startsWith("INSERT")) { QwpEgressFrames.Body done = QwpEgressFrames.execDone(r.requestId, OP_INSERT, ROWS_AFFECTED); diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryFlagsTest.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryFlagsTest.java index 41e7ad9f..87ab51a7 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryFlagsTest.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryFlagsTest.java @@ -90,7 +90,8 @@ public void onError(byte status, String message) { @Test public void testDetailOptionsDroppedWithoutCapability() throws Exception { // the query runs without what the server cannot report - QwpQueryOptions options = new QwpQueryOptions().errorPosition(true).stats(true).countRows(true).resetSymbolDict(true); + QwpQueryOptions options = new QwpQueryOptions().errorPosition(true).stats(true).countRows(true) + .designatedTimestamp(true).resetSymbolDict(true); QwpEgressFrames.QueryRequest r = executeOnce(QwpEgressMsgKind.CAP_QUERY_FLAGS, options); Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_RESET_DICT, r.queryFlags); Assert.assertEquals(0, r.trailingBytes); @@ -111,6 +112,7 @@ public void testEachBooleanOptionSendsItsFlag() throws Exception { {new QwpQueryOptions().errorPosition(true), QwpEgressMsgKind.QUERY_FLAG_ERROR_POSITION}, {new QwpQueryOptions().stats(true), QwpEgressMsgKind.QUERY_FLAG_STATS}, {new QwpQueryOptions().countRows(true), QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS}, + {new QwpQueryOptions().designatedTimestamp(true), QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP}, {new QwpQueryOptions().resetSymbolDict(true), QwpEgressMsgKind.QUERY_FLAG_RESET_DICT}, }; for (Object[] c : cases) { @@ -125,16 +127,17 @@ public void testEachBooleanOptionSendsItsFlag() throws Exception { @Test public void testEveryOptionOnTheWire() throws Exception { QwpQueryOptions options = new QwpQueryOptions() - .resetSymbolDict(true).errorPosition(true).stats(true).countRows(true) + .resetSymbolDict(true).errorPosition(true).stats(true).countRows(true).designatedTimestamp(true) .skipRows(300).maxRows(16_384); QwpEgressFrames.QueryRequest r = executeOnce(ALL_CAPABILITIES, options); // every bit but 0x02, which per-query timeouts own - Assert.assertEquals(0x7D, r.queryFlags); + Assert.assertEquals(0xFD, r.queryFlags); Assert.assertEquals(300, r.skipRows); Assert.assertEquals(16_384, r.maxRows); Assert.assertEquals(0, r.trailingBytes); - // flags, skip_rows, max_rows: the last bytes of the request, in that order - byte[] tail = new QwpEgressFrames.Body().varint(0x7D).varint(300).varint(16_384).toBody(); + // flags, skip_rows, max_rows: the last bytes of the request, in that + // order; the designated timestamp's 0x80 makes the flags two bytes long + byte[] tail = new QwpEgressFrames.Body().varint(0xFD).varint(300).varint(16_384).toBody(); Assert.assertArrayEquals(tail, Arrays.copyOfRange(r.payload, r.payload.length - tail.length, r.payload.length)); } @@ -331,7 +334,8 @@ public void testWireBitsAreDistinctAndLeaveTimeoutBitsFree() { QwpEgressMsgKind.QUERY_FLAG_STATS, QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS, QwpEgressMsgKind.QUERY_FLAG_SKIP_ROWS, - QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS + QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS, + QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP ); } diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryOptionsTest.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryOptionsTest.java index 9d50134c..f05f0c98 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryOptionsTest.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryOptionsTest.java @@ -67,7 +67,7 @@ public void testDefaults() { QwpQueryOptions options = new QwpQueryOptions(); assertDefaults(options); Assert.assertEquals("QwpQueryOptions{skipRows=0, maxRows=9223372036854775807, countRows=false, " - + "stats=false, errorPosition=false, resetSymbolDict=false}", options.toString()); + + "stats=false, errorPosition=false, designatedTimestamp=false, resetSymbolDict=false}", options.toString()); } @Test @@ -112,12 +112,14 @@ public void testSetters() { Assert.assertTrue(options.isStatsRequested()); Assert.assertSame(options, options.errorPosition(true)); Assert.assertTrue(options.isErrorPositionRequested()); + Assert.assertSame(options, options.designatedTimestamp(true)); + Assert.assertTrue(options.isDesignatedTimestampRequested()); Assert.assertSame(options, options.resetSymbolDict(true)); Assert.assertTrue(options.isSymbolDictResetRequested()); Assert.assertEquals("QwpQueryOptions{skipRows=0, maxRows=9223372036854775807, countRows=true, " - + "stats=true, errorPosition=true, resetSymbolDict=true}", options.toString()); + + "stats=true, errorPosition=true, designatedTimestamp=true, resetSymbolDict=true}", options.toString()); - options.countRows(false).stats(false).errorPosition(false).resetSymbolDict(false); + options.countRows(false).stats(false).errorPosition(false).designatedTimestamp(false).resetSymbolDict(false); assertDefaults(options); } @@ -128,6 +130,7 @@ private static QwpQueryOptions allSet() { .countRows(true) .stats(true) .errorPosition(true) + .designatedTimestamp(true) .resetSymbolDict(true); } @@ -137,6 +140,7 @@ private static void assertAllSet(QwpQueryOptions options) { Assert.assertTrue(options.isRowCountRequested()); Assert.assertTrue(options.isStatsRequested()); Assert.assertTrue(options.isErrorPositionRequested()); + Assert.assertTrue(options.isDesignatedTimestampRequested()); Assert.assertTrue(options.isSymbolDictResetRequested()); } @@ -146,6 +150,7 @@ private static void assertDefaults(QwpQueryOptions options) { Assert.assertFalse(options.isRowCountRequested()); Assert.assertFalse(options.isStatsRequested()); Assert.assertFalse(options.isErrorPositionRequested()); + Assert.assertFalse(options.isDesignatedTimestampRequested()); Assert.assertFalse(options.isSymbolDictResetRequested()); } } diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/RecordingQueryHandler.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/RecordingQueryHandler.java index f286af46..e9477340 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/RecordingQueryHandler.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/RecordingQueryHandler.java @@ -26,6 +26,7 @@ import io.questdb.client.cutlass.qwp.client.QwpColumnBatch; import io.questdb.client.cutlass.qwp.client.QwpColumnBatchHandler; +import io.questdb.client.cutlass.qwp.client.QwpEgressMsgKind; import io.questdb.client.cutlass.qwp.client.QwpQueryDetails; import io.questdb.client.cutlass.qwp.client.QwpServerInfo; import org.junit.Assert; @@ -51,6 +52,7 @@ public class RecordingQueryHandler implements QwpColumnBatchHandler { public long clientWaitNanos; public long compileNanos; public long countNanos; + public int designatedTimestampIndex; public int endCount; public long endRequestId; public int errorCount; @@ -61,6 +63,7 @@ public class RecordingQueryHandler implements QwpColumnBatchHandler { public int execDoneCount; public long executeNanos; public int failoverResetCount; + public boolean hasDesignatedTimestampIndex; public boolean hasRowCount; public boolean hasStats; public boolean isJitCompiled; @@ -72,10 +75,12 @@ public class RecordingQueryHandler implements QwpColumnBatchHandler { private final List wrongOverloads = new CopyOnWriteArrayList<>(); /** - * Asserts that {@code details} carries neither a row count nor statistics: - * every getter returns its absent value. + * Asserts that {@code details} carries no row count, statistics or + * designated timestamp: every getter returns its absent value. */ public static void assertNoDetails(QwpQueryDetails details) { + Assert.assertFalse(details.hasDesignatedTimestampIndex()); + Assert.assertEquals(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP, details.getDesignatedTimestampIndex()); Assert.assertFalse(details.hasRowCount()); Assert.assertEquals(-1, details.getRowCount()); Assert.assertFalse(details.hasStats()); @@ -89,6 +94,8 @@ public static void assertNoDetails(QwpQueryDetails details) { public void assertNoDetails() { assertNoWrongOverloads(); + Assert.assertFalse("designated timestamp", hasDesignatedTimestampIndex); + Assert.assertEquals(QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP, designatedTimestampIndex); Assert.assertFalse("row count", hasRowCount); Assert.assertEquals(-1, rowCount); Assert.assertFalse("stats", hasStats); @@ -169,6 +176,8 @@ public void onFailoverReset(long requestId, QwpServerInfo newNode) { private void copy(QwpQueryDetails details) { Assert.assertNotNull("details must never be null", details); + hasDesignatedTimestampIndex = details.hasDesignatedTimestampIndex(); + designatedTimestampIndex = details.getDesignatedTimestampIndex(); hasRowCount = details.hasRowCount(); rowCount = details.getRowCount(); hasStats = details.hasStats(); From 81f95ff83fb2109da1ba363d413f07d5434d6012 Mon Sep 17 00:00:00 2001 From: glasstiger Date: Tue, 1 Dec 2026 01:47:48 +0000 Subject: [PATCH 2/2] feat(qwp): leave the bytes of BINARY values out of query results 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. --- README.md | 8 +- .../main/java/io/questdb/client/Query.java | 9 +- .../cutlass/qwp/client/QwpEgressMsgKind.java | 15 ++- .../cutlass/qwp/client/QwpQueryClient.java | 21 +-- .../cutlass/qwp/client/QwpQueryOptions.java | 50 +++++-- .../client/test/QuestDBQueryOptionsTest.java | 21 +++ .../cutlass/qwp/client/QwpEgressFrames.java | 42 ++++++ .../QwpQueryClientQueryDetailsTest.java | 123 +++++++++++++++--- .../client/QwpQueryClientQueryFlagsTest.java | 15 ++- .../qwp/client/QwpQueryOptionsTest.java | 14 +- 10 files changed, 263 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index e7259dc0..31256bc4 100644 --- a/README.md +++ b/README.md @@ -244,9 +244,10 @@ try (Query q = db.borrowQuery()) { `QwpQueryOptions` asks the server for one page of the result set, and for what the `/exec` HTTP endpoint reports besides the rows: the row count of the whole result set, execution statistics, the designated timestamp column, and the position of an error in the SQL text. The handler receives them through the detailed overloads of its callbacks, and a -failed `await()` throws a `QueryException` whose `getPosition()` carries the position. The options need a QuestDB server -that supports them; an older server fails a query that sets `skipRows` or `maxRows`, and runs the others without the -details. +failed `await()` throws a `QueryException` whose `getPosition()` carries the position. `omitBinaryValues` asks the +server to leave the bytes of BINARY values out, as `/exec` does: each non-NULL BINARY value then arrives empty, and a NULL +stays NULL. The options need a QuestDB server that supports them; an older server fails a query that sets `skipRows` or +`maxRows`, and runs the others without the details and with the BINARY values. ```java import io.questdb.client.cutlass.qwp.client.QwpQueryDetails; @@ -258,6 +259,7 @@ QwpQueryOptions page = new QwpQueryOptions() .countRows(true) // count the rows of the whole result set .stats(true) // report compile and execution times .designatedTimestamp(true) // report which column is the designated timestamp + .omitBinaryValues(true) // send BINARY values empty, without their bytes .errorPosition(true); // report where in the SQL text an error is QwpColumnBatchHandler pageHandler = new QwpColumnBatchHandler() { diff --git a/core/src/main/java/io/questdb/client/Query.java b/core/src/main/java/io/questdb/client/Query.java index 83175576..6e544ba1 100644 --- a/core/src/main/java/io/questdb/client/Query.java +++ b/core/src/main/java/io/questdb/client/Query.java @@ -106,11 +106,12 @@ public interface Query extends Closeable { /** * Sets the per-query options: a row window that pages through the result - * set, and what the server reports besides the rows -- the row count of the + * set, what the server reports besides the rows -- the row count of the * whole result set, execution statistics, the designated timestamp column - * and the error position. See {@link QwpQueryOptions}. The handle copies the - * values, so the instance can be reused right away; they apply to every - * {@link #submit()} until changed. + * and the error position -- and whether it leaves the bytes of BINARY values + * out. See {@link QwpQueryOptions}. The handle copies the values, so the + * instance can be reused right away; they apply to every {@link #submit()} + * until changed. * Each {@link #submit()} runs with the options set when it is called, so * changing them while a query is in flight affects only the next one. Pass * null to drop them. diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressMsgKind.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressMsgKind.java index 83187b1b..d8bf82ff 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressMsgKind.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpEgressMsgKind.java @@ -42,8 +42,9 @@ public final class QwpEgressMsgKind { * {@code SERVER_INFO.capabilities} bit: the server honours the query-details * flags of {@code QUERY_REQUEST.query_flags} -- {@link #QUERY_FLAG_ERROR_POSITION}, * {@link #QUERY_FLAG_STATS}, {@link #QUERY_FLAG_COUNT_ROWS}, - * {@link #QUERY_FLAG_SKIP_ROWS}, {@link #QUERY_FLAG_MAX_ROWS} and - * {@link #QUERY_FLAG_DESIGNATED_TIMESTAMP}. The client sends those bits only + * {@link #QUERY_FLAG_SKIP_ROWS}, {@link #QUERY_FLAG_MAX_ROWS}, + * {@link #QUERY_FLAG_DESIGNATED_TIMESTAMP} and + * {@link #QUERY_FLAG_OMIT_BINARY_VALUES}. The client sends those bits only * when this bit is set: a server without it ignores them and answers with * the baseline frames. Mirrors the server-side constant * {@code io.questdb.cutlass.qwp.codec.QwpEgressMsgKind#CAP_QUERY_DETAILS}. @@ -136,6 +137,16 @@ public final class QwpEgressMsgKind { * Sent only when the server advertised {@link #CAP_QUERY_DETAILS}. */ public static final int QUERY_FLAG_MAX_ROWS = 0x40; + /** + * {@code QUERY_REQUEST.query_flags} bit: leave the bytes of BINARY values + * out of the result, as the {@code /exec} HTTP endpoint does, which sends + * every BINARY value as {@code []}. Every {@code RESULT_BATCH} of the query + * then carries each non-NULL BINARY value as an empty one, zero bytes long, + * and a NULL as NULL, in the usual layout of the column. Statements that do + * not produce rows ignore it. Sent only when the server advertised + * {@link #CAP_QUERY_DETAILS}; a server without it sends the values. + */ + public static final int QUERY_FLAG_OMIT_BINARY_VALUES = 0x100; /** * {@code QUERY_REQUEST.query_flags} bit: reset the connection-scoped SYMBOL * dict before this query, scoping it to the query. Sent only when the server diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryClient.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryClient.java index 5c5bae36..92367a91 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryClient.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryClient.java @@ -103,10 +103,11 @@ *

* Per-query options: * {@link #execute(CharSequence, QwpBindSetter, QwpColumnBatchHandler, QwpQueryOptions)} - * pages through a result set with a row window, and asks the server for what - * the {@code /exec} HTTP endpoint reports besides the rows: the row count of - * the whole result set, execution statistics, the designated timestamp column - * and the error position. See {@link QwpQueryOptions}. + * pages through a result set with a row window, asks the server for what the + * {@code /exec} HTTP endpoint reports besides the rows: the row count of the + * whole result set, execution statistics, the designated timestamp column and + * the error position, and can ask it to leave the bytes of BINARY values out. + * See {@link QwpQueryOptions}. */ public class QwpQueryClient implements QuietCloseable { @@ -169,7 +170,8 @@ public class QwpQueryClient implements QuietCloseable { | QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS | QwpEgressMsgKind.QUERY_FLAG_SKIP_ROWS | QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS - | QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP; + | QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP + | QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES; // query_flags bits of the row window, which change what the server streams private static final int ROW_WINDOW_QUERY_FLAGS = QwpEgressMsgKind.QUERY_FLAG_SKIP_ROWS | QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS; @@ -821,13 +823,14 @@ public void execute(CharSequence sql, QwpBindSetter binds, QwpColumnBatchHandler /** * As {@link #execute(CharSequence, QwpBindSetter, QwpColumnBatchHandler)}, * with per-query {@code options}: a row window that pages through the - * result set, and what the server reports besides the rows -- the row count - * of the whole result set, execution statistics and the designated - * timestamp column, which reach + * result set, what the server reports besides the rows -- the row count of + * the whole result set, execution statistics and the designated timestamp + * column, which reach * {@link QwpColumnBatchHandler#onEnd(long, long, QwpQueryDetails)} and * {@link QwpColumnBatchHandler#onExecDone(long, short, long, QwpQueryDetails)}, * and the error position, which reaches - * {@link QwpColumnBatchHandler#onError(long, byte, String, int)}. The client + * {@link QwpColumnBatchHandler#onError(long, byte, String, int)} -- and + * whether the server leaves the bytes of BINARY values out. The client * reads {@code options} when the call starts; null runs the query without * options. *

diff --git a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java index b57f474f..b34acd67 100644 --- a/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java +++ b/core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpQueryOptions.java @@ -28,21 +28,22 @@ * Per-query options of * {@link QwpQueryClient#execute(CharSequence, QwpBindSetter, QwpColumnBatchHandler, QwpQueryOptions)} * and {@link io.questdb.client.Query#options(QwpQueryOptions)}: a row window - * that pages through the result set, and what the server reports besides the - * rows -- the row count of the whole result set, execution statistics, the - * designated timestamp column and the position of an error in the SQL text. A - * new instance has every option off, and a query run with it is the same on - * the wire as one run without options. + * that pages through the result set, what the server reports besides the rows + * -- the row count of the whole result set, execution statistics, the + * designated timestamp column and the position of an error in the SQL text -- + * and whether it leaves the bytes of BINARY values out. A new instance has + * every option off, and a query run with it is the same on the wire as one run + * without options. *

- * The row window, the row count, the statistics, the designated timestamp and - * the error position need a server that advertises + * The row window, the row count, the statistics, the designated timestamp, the + * error position and leaving out BINARY values need a server that advertises * {@link QwpEgressMsgKind#CAP_QUERY_DETAILS}. Against a server without it, the * client fails a query that sets a row window, since the server would stream - * every row, and runs a query that asks only for the reports without them: the - * handler then sees {@link QwpQueryDetails#hasRowCount()}, + * every row, and runs any other query without those options: the handler then + * sees {@link QwpQueryDetails#hasRowCount()}, * {@link QwpQueryDetails#hasStats()} and - * {@link QwpQueryDetails#hasDesignatedTimestampIndex()} false and the position - * {@link QwpEgressMsgKind#NO_ERROR_POSITION}. + * {@link QwpQueryDetails#hasDesignatedTimestampIndex()} false, the position + * {@link QwpEgressMsgKind#NO_ERROR_POSITION}, and BINARY values in full. *

* The client reads the options when the query starts, so one instance can be * reused for any number of queries, and changing it does not affect a query @@ -50,6 +51,7 @@ */ public final class QwpQueryOptions { + private boolean isBinaryValueOmissionRequested; private boolean isDesignatedTimestampRequested; private boolean isErrorPositionRequested; private boolean isRowCountRequested; @@ -65,6 +67,7 @@ public final class QwpQueryOptions { * @return this instance */ public QwpQueryOptions clear() { + isBinaryValueOmissionRequested = false; isDesignatedTimestampRequested = false; isErrorPositionRequested = false; isRowCountRequested = false; @@ -85,6 +88,7 @@ public QwpQueryOptions copyFrom(QwpQueryOptions other) { if (other == null) { return clear(); } + isBinaryValueOmissionRequested = other.isBinaryValueOmissionRequested; isDesignatedTimestampRequested = other.isDesignatedTimestampRequested; isErrorPositionRequested = other.isErrorPositionRequested; isRowCountRequested = other.isRowCountRequested; @@ -156,6 +160,10 @@ public long getSkipRows() { return skipRows; } + public boolean isBinaryValueOmissionRequested() { + return isBinaryValueOmissionRequested; + } + public boolean isDesignatedTimestampRequested() { return isDesignatedTimestampRequested; } @@ -195,6 +203,22 @@ public QwpQueryOptions maxRows(long rows) { return this; } + /** + * Asks the server to leave the bytes of BINARY values out of the result, as + * the {@code /exec} HTTP endpoint does, which sends every BINARY value as + * {@code []}. Every non-NULL BINARY value then reaches the handler empty, + * zero bytes long, and a NULL stays NULL; the other columns are unchanged. + * The server neither copies nor sends the bytes. A server that does not + * advertise {@link QwpEgressMsgKind#CAP_QUERY_DETAILS} sends the values in + * full. + * + * @return this instance + */ + public QwpQueryOptions omitBinaryValues(boolean isRequested) { + isBinaryValueOmissionRequested = isRequested; + return this; + } + /** * Asks the server to reset the connection-scoped SYMBOL dictionary before * the query, scoping the dictionary to its symbols. Needs a server that @@ -250,6 +274,7 @@ public String toString() { + ", stats=" + isStatsRequested + ", errorPosition=" + isErrorPositionRequested + ", designatedTimestamp=" + isDesignatedTimestampRequested + + ", omitBinaryValues=" + isBinaryValueOmissionRequested + ", resetSymbolDict=" + isSymbolDictResetRequested + '}'; } @@ -281,6 +306,9 @@ long toQueryFlags() { if (isDesignatedTimestampRequested) { flags |= QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP; } + if (isBinaryValueOmissionRequested) { + flags |= QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES; + } return flags; } } diff --git a/core/src/test/java/io/questdb/client/test/QuestDBQueryOptionsTest.java b/core/src/test/java/io/questdb/client/test/QuestDBQueryOptionsTest.java index 2047459e..57acb5db 100644 --- a/core/src/test/java/io/questdb/client/test/QuestDBQueryOptionsTest.java +++ b/core/src/test/java/io/questdb/client/test/QuestDBQueryOptionsTest.java @@ -141,6 +141,27 @@ public void testErrorPositionReachesQueryException() throws Exception { }); } + @Test + public void testOmitBinaryValuesReachesTheWire() throws Exception { + TestUtils.assertMemoryLeak(() -> { + try (QwpEgressMockServer server = new QwpEgressMockServer(ALL_CAPABILITIES, QuestDBQueryOptionsTest::model); + QuestDB db = connect(server); + Query q = db.borrowQuery()) { + RecordingQueryHandler handler = new RecordingQueryHandler(); + q.sql("SELECT x").options(new QwpQueryOptions().omitBinaryValues(true)).handler(handler).submit().await(); + handler.assertNoWrongOverloads(); + Assert.assertEquals(1, handler.endCount); + Assert.assertEquals(10, handler.values.size()); + Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES, server.getRequests().get(0).queryFlags); + + // the next query without the option sends no flags + q.options(null).submit().await(); + Assert.assertFalse(server.getRequests().get(1).hasQueryFlags); + server.assertNoFailure(); + } + }); + } + @Test public void testOptionsAreCopiedAndKeptAcrossSubmits() throws Exception { TestUtils.assertMemoryLeak(() -> { diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpEgressFrames.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpEgressFrames.java index 5ad80e27..e4ff1e50 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpEgressFrames.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpEgressFrames.java @@ -93,6 +93,48 @@ public static Body queryError(long requestId, byte status, String message) { return body(QwpEgressMsgKind.QUERY_ERROR, requestId).u8(status).u16(msg.length).bytes(msg); } + /** + * {@code RESULT_BATCH} carrying one BINARY column {@code b}, where a null + * value is NULL; the schema rides the first batch of a query only. + */ + public static byte[] resultBatchOfBinaries(long requestId, long batchSeq, byte[]... values) { + Body b = body(QwpEgressMsgKind.RESULT_BATCH, requestId) + .varint(batchSeq) + .varint(0) // table name length + .varint(values.length); + if (batchSeq == 0) { + b.varint(1).varint(1).u8('b').u8(QwpConstants.TYPE_BINARY); + } + byte[] nullBitmap = new byte[(values.length + 7) >>> 3]; + boolean hasNulls = false; + for (int row = 0; row < values.length; row++) { + if (values[row] == null) { + nullBitmap[row >>> 3] |= (byte) (1 << (row & 7)); + hasNulls = true; + } + } + if (hasNulls) { + b.u8(1).bytes(nullBitmap); + } else { + b.u8(0); + } + // an offset per non-NULL value after the leading zero, then their bytes + b.i32(0); + int offset = 0; + for (byte[] value : values) { + if (value != null) { + offset += value.length; + b.i32(offset); + } + } + for (byte[] value : values) { + if (value != null) { + b.bytes(value); + } + } + return b.toFrame(); + } + /** * {@code RESULT_BATCH} carrying one LONG column {@code x}; the schema rides * the first batch of a query only. diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryDetailsTest.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryDetailsTest.java index 520ecff9..d8ae7b98 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryDetailsTest.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryDetailsTest.java @@ -52,11 +52,16 @@ * for the flags the request carries, where {@code x} is the designated * timestamp of a query that ends with {@code TIMESTAMP(x)} and of no other; * the bare message and the position of an error only under - * {@code QUERY_FLAG_ERROR_POSITION}. The questdb repo checks the same against - * a live server. + * {@code QUERY_FLAG_ERROR_POSITION}; and a BINARY column whose non-NULL values + * go out empty under {@code QUERY_FLAG_OMIT_BINARY_VALUES}. The questdb repo + * checks the same against a live server. */ public class QwpQueryClientQueryDetailsTest { private static final int ALL_CAPABILITIES = QwpEgressMsgKind.CAP_QUERY_FLAGS | QwpEgressMsgKind.CAP_QUERY_DETAILS; + // a query of the model whose result is one BINARY column of BINARY_VALUES + private static final String BINARY_SQL = "SELECT b FROM blobs"; + // a NULL, an empty value and two values with bytes + private static final byte[][] BINARY_VALUES = {{1, 2, 3}, null, {}, {(byte) 0xFF}}; private static final long CLIENT_WAIT_NANOS = 44; private static final long COMPILE_NANOS = 11; private static final long COUNT_NANOS = 33; @@ -125,7 +130,7 @@ public void testDetailsAbsentWithoutCapability() throws Exception { QwpQueryClient client = newClient(server, "")) { client.connect(); QwpQueryOptions options = new QwpQueryOptions().countRows(true).stats(true).errorPosition(true) - .designatedTimestamp(true); + .designatedTimestamp(true).omitBinaryValues(true); RecordingQueryHandler select = new RecordingQueryHandler(); client.execute(DESIGNATED_SQL, select, options); @@ -133,6 +138,12 @@ public void testDetailsAbsentWithoutCapability() throws Exception { Assert.assertEquals(TABLE_ROWS, select.totalRows); select.assertNoDetails(); + // the BINARY values arrive in full + BinaryCollector binaries = new BinaryCollector(); + client.execute(BINARY_SQL, binaries, options); + binaries.assertBinaries(BINARY_VALUES); + binaries.assertNoDetails(); + RecordingQueryHandler insert = new RecordingQueryHandler(); client.execute("INSERT INTO t VALUES (1)", insert, options); Assert.assertEquals(1, insert.execDoneCount); @@ -274,13 +285,14 @@ public void testFailoverChecksTheNewServerAgain() throws Exception { client.connect(); RecordingQueryHandler handler = new RecordingQueryHandler(); client.execute("SELECT x FROM t", handler, new QwpQueryOptions().stats(true).countRows(true) - .designatedTimestamp(true)); + .designatedTimestamp(true).omitBinaryValues(true)); Assert.assertEquals(1, handler.failoverResetCount); Assert.assertEquals(1, handler.endCount); Assert.assertEquals(TABLE_ROWS, handler.values.size()); handler.assertNoDetails(); Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_STATS | QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS - | QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP, + | QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP + | QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES, dying.getRequests().get(0).queryFlags); Assert.assertFalse(old.getRequests().get(0).hasQueryFlags); } @@ -476,6 +488,42 @@ public void testMissingTrailerIsTransportFailure() throws Exception { } } + @Test + public void testOmittedBinaryValuesArriveEmpty() throws Exception { + // the server sends each non-NULL BINARY value of a query with the option + // empty, and a NULL as NULL: the handler tells the two apart + TestUtils.assertMemoryLeak(() -> { + try (QwpEgressMockServer server = new QwpEgressMockServer(ALL_CAPABILITIES, QwpQueryClientQueryDetailsTest::model); + QwpQueryClient client = newClient(server, "")) { + client.connect(); + BinaryCollector omitted = new BinaryCollector(); + client.execute(BINARY_SQL, omitted, new QwpQueryOptions().omitBinaryValues(true).countRows(true)); + Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES | QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS, + server.getRequests().get(0).queryFlags); + omitted.assertBinaries(new byte[0], null, new byte[0], new byte[0]); + Assert.assertEquals(1, omitted.endCount); + Assert.assertEquals(BINARY_VALUES.length, omitted.totalRows); + Assert.assertEquals(BINARY_VALUES.length, omitted.rowCount); + + // a query without the option gets the values in full + BinaryCollector full = new BinaryCollector(); + client.execute(BINARY_SQL, full, new QwpQueryOptions().countRows(true)); + Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS, server.getRequests().get(1).queryFlags); + full.assertBinaries(BINARY_VALUES); + Assert.assertEquals(BINARY_VALUES.length, full.rowCount); + + // a statement ignores the option + RecordingQueryHandler insert = new RecordingQueryHandler(); + client.execute("INSERT INTO t VALUES (1)", insert, new QwpQueryOptions().omitBinaryValues(true)); + Assert.assertEquals(1, insert.execDoneCount); + Assert.assertEquals(ROWS_AFFECTED, insert.rowsAffected); + insert.assertNoDetails(); + Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES, server.getRequests().get(2).queryFlags); + server.assertNoFailure(); + } + }); + } + @Test public void testReentrantExecuteWithOptionsRejected() throws Exception { // one query at a time: an execute() from inside a handler fails, its @@ -584,7 +632,16 @@ private static byte[][] model(QwpEgressFrames.QueryRequest r) { */ private static byte[][] model(QwpEgressFrames.QueryRequest r, long trailerFlags) { List frames = new ArrayList<>(); - if (r.sql.startsWith("SELECT")) { + if (r.sql.equals(BINARY_SQL)) { + // one batch, whose non-NULL values QUERY_FLAG_OMIT_BINARY_VALUES sends empty + boolean isOmitted = (r.queryFlags & QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES) != 0; + byte[][] values = new byte[BINARY_VALUES.length][]; + for (int i = 0; i < values.length; i++) { + values[i] = isOmitted && BINARY_VALUES[i] != null ? new byte[0] : BINARY_VALUES[i]; + } + frames.add(QwpEgressFrames.resultBatchOfBinaries(r.requestId, 0, values)); + frames.add(resultEnd(r, trailerFlags, 0, values.length, values.length)); + } else if (r.sql.startsWith("SELECT")) { long skip = r.skipRows < 0 ? 0 : r.skipRows; long max = r.maxRows < 0 ? Long.MAX_VALUE : r.maxRows; long first = Math.min(skip, TABLE_ROWS); @@ -599,17 +656,7 @@ private static byte[][] model(QwpEgressFrames.QueryRequest r, long trailerFlags) } frames.add(QwpEgressFrames.resultBatchOfLongs(r.requestId, seq++, values)); } while (x < end); - QwpEgressFrames.Body end0 = QwpEgressFrames.resultEnd(r.requestId, seq - 1, end - first); - if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS) != 0) { - end0.varint(TABLE_ROWS); - } - if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_STATS) != 0) { - end0.stats(COMPILE_NANOS, EXECUTE_NANOS, COUNT_NANOS, CLIENT_WAIT_NANOS, QwpEgressMsgKind.STATS_FLAG_JIT_COMPILED); - } - if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP) != 0) { - end0.i32(r.sql.equals(DESIGNATED_SQL) ? 0 : QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP); - } - frames.add(end0.toFrame()); + frames.add(resultEnd(r, trailerFlags, seq - 1, end - first, TABLE_ROWS)); } else if (r.sql.startsWith("INSERT")) { QwpEgressFrames.Body done = QwpEgressFrames.execDone(r.requestId, OP_INSERT, ROWS_AFFECTED); if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_STATS) != 0) { @@ -629,4 +676,46 @@ private static byte[][] model(QwpEgressFrames.QueryRequest r, long trailerFlags) private static QwpQueryClient newClient(QwpEgressMockServer server, String extraConfig) { return QwpQueryClient.fromConfig("ws::addr=" + server.getAddress() + ";auth_timeout_ms=2000;" + extraConfig); } + + /** + * The {@code RESULT_END} of {@code r}, with the trailers of + * {@code trailerFlags}: {@code rowCount} is the size of the whole result. + */ + private static byte[] resultEnd(QwpEgressFrames.QueryRequest r, long trailerFlags, long finalSeq, long totalRows, long rowCount) { + QwpEgressFrames.Body end = QwpEgressFrames.resultEnd(r.requestId, finalSeq, totalRows); + if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS) != 0) { + end.varint(rowCount); + } + if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_STATS) != 0) { + end.stats(COMPILE_NANOS, EXECUTE_NANOS, COUNT_NANOS, CLIENT_WAIT_NANOS, QwpEgressMsgKind.STATS_FLAG_JIT_COMPILED); + } + if ((trailerFlags & QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP) != 0) { + end.i32(r.sql.equals(DESIGNATED_SQL) ? 0 : QwpEgressMsgKind.NO_DESIGNATED_TIMESTAMP); + } + return end.toFrame(); + } + + /** + * Collects the values of a single BINARY column, a NULL as null, besides + * what {@link RecordingQueryHandler} records of the query's end. + */ + private static final class BinaryCollector extends RecordingQueryHandler { + final List binaries = new ArrayList<>(); + + @Override + public void onBatch(QwpColumnBatch batch) { + for (int row = 0; row < batch.getRowCount(); row++) { + byte[] value = batch.getBinary(0, row); + Assert.assertEquals("row " + row, value == null, batch.isNull(0, row)); + binaries.add(value); + } + } + + void assertBinaries(byte[]... expected) { + Assert.assertEquals(expected.length, binaries.size()); + for (int row = 0; row < expected.length; row++) { + Assert.assertArrayEquals("row " + row, expected[row], binaries.get(row)); + } + } + } } diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryFlagsTest.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryFlagsTest.java index 87ab51a7..3bc1f5a4 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryFlagsTest.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryClientQueryFlagsTest.java @@ -91,7 +91,7 @@ public void onError(byte status, String message) { public void testDetailOptionsDroppedWithoutCapability() throws Exception { // the query runs without what the server cannot report QwpQueryOptions options = new QwpQueryOptions().errorPosition(true).stats(true).countRows(true) - .designatedTimestamp(true).resetSymbolDict(true); + .designatedTimestamp(true).omitBinaryValues(true).resetSymbolDict(true); QwpEgressFrames.QueryRequest r = executeOnce(QwpEgressMsgKind.CAP_QUERY_FLAGS, options); Assert.assertEquals(QwpEgressMsgKind.QUERY_FLAG_RESET_DICT, r.queryFlags); Assert.assertEquals(0, r.trailingBytes); @@ -113,6 +113,7 @@ public void testEachBooleanOptionSendsItsFlag() throws Exception { {new QwpQueryOptions().stats(true), QwpEgressMsgKind.QUERY_FLAG_STATS}, {new QwpQueryOptions().countRows(true), QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS}, {new QwpQueryOptions().designatedTimestamp(true), QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP}, + {new QwpQueryOptions().omitBinaryValues(true), QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES}, {new QwpQueryOptions().resetSymbolDict(true), QwpEgressMsgKind.QUERY_FLAG_RESET_DICT}, }; for (Object[] c : cases) { @@ -128,16 +129,17 @@ public void testEachBooleanOptionSendsItsFlag() throws Exception { public void testEveryOptionOnTheWire() throws Exception { QwpQueryOptions options = new QwpQueryOptions() .resetSymbolDict(true).errorPosition(true).stats(true).countRows(true).designatedTimestamp(true) - .skipRows(300).maxRows(16_384); + .omitBinaryValues(true).skipRows(300).maxRows(16_384); QwpEgressFrames.QueryRequest r = executeOnce(ALL_CAPABILITIES, options); // every bit but 0x02, which per-query timeouts own - Assert.assertEquals(0xFD, r.queryFlags); + Assert.assertEquals(0x1FD, r.queryFlags); Assert.assertEquals(300, r.skipRows); Assert.assertEquals(16_384, r.maxRows); Assert.assertEquals(0, r.trailingBytes); // flags, skip_rows, max_rows: the last bytes of the request, in that - // order; the designated timestamp's 0x80 makes the flags two bytes long - byte[] tail = new QwpEgressFrames.Body().varint(0xFD).varint(300).varint(16_384).toBody(); + // order; the bits from 0x80 up make the flags two bytes long + byte[] tail = new QwpEgressFrames.Body().varint(0x1FD).varint(300).varint(16_384).toBody(); + Assert.assertArrayEquals(new byte[]{(byte) 0xFD, 0x03}, Arrays.copyOf(tail, 2)); Assert.assertArrayEquals(tail, Arrays.copyOfRange(r.payload, r.payload.length - tail.length, r.payload.length)); } @@ -335,7 +337,8 @@ public void testWireBitsAreDistinctAndLeaveTimeoutBitsFree() { QwpEgressMsgKind.QUERY_FLAG_COUNT_ROWS, QwpEgressMsgKind.QUERY_FLAG_SKIP_ROWS, QwpEgressMsgKind.QUERY_FLAG_MAX_ROWS, - QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP + QwpEgressMsgKind.QUERY_FLAG_DESIGNATED_TIMESTAMP, + QwpEgressMsgKind.QUERY_FLAG_OMIT_BINARY_VALUES ); } diff --git a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryOptionsTest.java b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryOptionsTest.java index f05f0c98..034aa32e 100644 --- a/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryOptionsTest.java +++ b/core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpQueryOptionsTest.java @@ -67,7 +67,8 @@ public void testDefaults() { QwpQueryOptions options = new QwpQueryOptions(); assertDefaults(options); Assert.assertEquals("QwpQueryOptions{skipRows=0, maxRows=9223372036854775807, countRows=false, " - + "stats=false, errorPosition=false, designatedTimestamp=false, resetSymbolDict=false}", options.toString()); + + "stats=false, errorPosition=false, designatedTimestamp=false, omitBinaryValues=false, " + + "resetSymbolDict=false}", options.toString()); } @Test @@ -114,12 +115,16 @@ public void testSetters() { Assert.assertTrue(options.isErrorPositionRequested()); Assert.assertSame(options, options.designatedTimestamp(true)); Assert.assertTrue(options.isDesignatedTimestampRequested()); + Assert.assertSame(options, options.omitBinaryValues(true)); + Assert.assertTrue(options.isBinaryValueOmissionRequested()); Assert.assertSame(options, options.resetSymbolDict(true)); Assert.assertTrue(options.isSymbolDictResetRequested()); Assert.assertEquals("QwpQueryOptions{skipRows=0, maxRows=9223372036854775807, countRows=true, " - + "stats=true, errorPosition=true, designatedTimestamp=true, resetSymbolDict=true}", options.toString()); + + "stats=true, errorPosition=true, designatedTimestamp=true, omitBinaryValues=true, " + + "resetSymbolDict=true}", options.toString()); - options.countRows(false).stats(false).errorPosition(false).designatedTimestamp(false).resetSymbolDict(false); + options.countRows(false).stats(false).errorPosition(false).designatedTimestamp(false) + .omitBinaryValues(false).resetSymbolDict(false); assertDefaults(options); } @@ -131,6 +136,7 @@ private static QwpQueryOptions allSet() { .stats(true) .errorPosition(true) .designatedTimestamp(true) + .omitBinaryValues(true) .resetSymbolDict(true); } @@ -141,6 +147,7 @@ private static void assertAllSet(QwpQueryOptions options) { Assert.assertTrue(options.isStatsRequested()); Assert.assertTrue(options.isErrorPositionRequested()); Assert.assertTrue(options.isDesignatedTimestampRequested()); + Assert.assertTrue(options.isBinaryValueOmissionRequested()); Assert.assertTrue(options.isSymbolDictResetRequested()); } @@ -151,6 +158,7 @@ private static void assertDefaults(QwpQueryOptions options) { Assert.assertFalse(options.isStatsRequested()); Assert.assertFalse(options.isErrorPositionRequested()); Assert.assertFalse(options.isDesignatedTimestampRequested()); + Assert.assertFalse(options.isBinaryValueOmissionRequested()); Assert.assertFalse(options.isSymbolDictResetRequested()); } }