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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions data/src/main/java/com/microsoft/azure/kusto/data/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,36 @@ public interface Client {
* @return A {@link Mono} emitting the result of the query as a JSON string.
*/
Mono<String> executeToJsonResultAsync(String database, String command, ClientRequestProperties properties);

/**
* Executes a query and returns a streaming V2 response that can be iterated row-by-row
* without loading the entire result set into memory.
* <p>
* The caller is responsible for closing the returned {@link KustoResponseDataSetV2} to release
* the underlying stream resources.
*
* @param database The name of the database.
* @param query The query to execute.
* @param properties Additional request properties (may be null).
* @param options Streaming query options controlling response handling.
* @return A {@link KustoResponseDataSetV2} for streaming row-by-row iteration.
* @throws DataServiceException If there is an error from the service.
* @throws DataClientException If there is an error on the client side.
* @see KustoStreamingQueryOptions
* @see StreamingDataTable
*/
KustoResponseDataSetV2 executeQuery(String database, String query, ClientRequestProperties properties, KustoStreamingQueryOptions options)
throws DataServiceException, DataClientException;

/**
* Executes a query asynchronously and returns a streaming V2 response.
*
* @param database The name of the database.
* @param query The query to execute.
* @param properties Additional request properties (may be null).
* @param options Streaming query options controlling response handling.
* @return A {@link Mono} emitting a {@link KustoResponseDataSetV2} for streaming iteration.
* @see KustoStreamingQueryOptions
*/
Mono<KustoResponseDataSetV2> executeQueryAsync(String database, String query, ClientRequestProperties properties, KustoStreamingQueryOptions options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;


import org.jetbrains.annotations.NotNull;

import com.azure.core.http.HttpClient;
Expand Down Expand Up @@ -148,6 +148,31 @@ public Mono<String> executeToJsonResultAsync(String database, String command, Cl
});
}

@Override
public KustoResponseDataSetV2 executeQuery(String database, String query, ClientRequestProperties properties, KustoStreamingQueryOptions options) {
return executeQueryAsync(database, query, properties, options).block();
}

@Override
public Mono<KustoResponseDataSetV2> executeQueryAsync(String database, String query, ClientRequestProperties properties,
KustoStreamingQueryOptions options) {
Ensure.argIsNotNull(options, "options");
return executeStreamingQueryAsync(database == null ? defaultDatabaseName : database, query, properties)
.map(inputStream -> {
try {
KustoResponseDataSetV2 dataSet = new KustoResponseDataSetV2(inputStream);
if (options.hasBatchRowCount()) {
dataSet.setDefaultBatchRowCount(options.getMaxBatchRowCount());
}
return dataSet;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
})
.onErrorMap(UncheckedIOException.class,
e -> new DataClientException(clusterUrl, "Failed to parse streaming query response: " + e.getMessage(), e));
}

private Mono<KustoOperationResult> executeAsync(String database, String command, ClientRequestProperties properties, CommandType commandType) {
return Mono.defer(() -> {
KustoRequest kr = new KustoRequest(command, database, properties, commandType);
Expand Down
25 changes: 25 additions & 0 deletions data/src/main/java/com/microsoft/azure/kusto/data/FrameType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.azure.kusto.data;

/**
* Enumerates the frame types in a Kusto V2 query response.
* <p>
* A V2 response is a JSON array of frames. The first frame is always a {@link #DataSetHeader}
* and the last is always a {@link #DataSetCompletion}. In between are table frames, either as
* single {@link #DataTable} frames (non-progressive) or as sequences of
* {@link #TableHeader}/{@link #TableFragment}/{@link #TableProgress}/{@link #TableCompletion}
* frames (progressive mode).
*
* @see <a href="https://learn.microsoft.com/en-us/kusto/api/rest/response-v2">V2 Response Format</a>
*/
public enum FrameType {
DataSetHeader,
DataTable,
TableHeader,
TableFragment,
TableProgress,
TableCompletion,
DataSetCompletion
}
Loading
Loading