44using System ;
55using System . Collections . Generic ;
66using System . Globalization ;
7+ using System . Linq ;
78using System . Text ;
89using System . Text . Json ;
910using System . Threading ;
@@ -219,7 +220,7 @@ public virtual async Task<Response<LogsQueryResult>> QueryAsync(string workspace
219220 /// "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count",
220221 /// new DateTimeRange(TimeSpan.FromDays(1)));
221222 ///
222- /// Response<LogsBatchQueryResults > response = await client.QueryBatchAsync(batch);
223+ /// Response<LogsBatchQueryResultCollection > response = await client.QueryBatchAsync(batch);
223224 ///
224225 /// var count = response.Value.GetResult<int>(countQueryId).Single();
225226 /// var topEntries = response.Value.GetResult<MyLogEntryModel>(topQueryId);
@@ -233,8 +234,8 @@ public virtual async Task<Response<LogsQueryResult>> QueryAsync(string workspace
233234 /// </summary>
234235 /// <param name="batch">The batch of queries to send.</param>
235236 /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
236- /// <returns>The <see cref="LogsBatchQueryResults "/> containing the query identifier that has to be passed into <see cref="LogsBatchQueryResults .GetResult"/> to get the result.</returns>
237- public virtual Response < LogsBatchQueryResults > QueryBatch ( LogsBatchQuery batch , CancellationToken cancellationToken = default )
237+ /// <returns>The <see cref="LogsBatchQueryResultCollection "/> containing the query identifier that has to be passed into <see cref="LogsBatchQueryResultCollection .GetResult"/> to get the result.</returns>
238+ public virtual Response < LogsBatchQueryResultCollection > QueryBatch ( LogsBatchQuery batch , CancellationToken cancellationToken = default )
238239 {
239240 Argument . AssertNotNull ( batch , nameof ( batch ) ) ;
240241
@@ -243,7 +244,7 @@ public virtual Response<LogsBatchQueryResults> QueryBatch(LogsBatchQuery batch,
243244 try
244245 {
245246 var response = _queryClient . Batch ( new BatchRequest ( batch . Requests ) , cancellationToken ) ;
246- return response ;
247+ return ConvertBatchResponse ( batch , response ) ;
247248 }
248249 catch ( Exception e )
249250 {
@@ -272,7 +273,7 @@ public virtual Response<LogsBatchQueryResults> QueryBatch(LogsBatchQuery batch,
272273 /// "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count",
273274 /// new DateTimeRange(TimeSpan.FromDays(1)));
274275 ///
275- /// Response<LogsBatchQueryResults > response = await client.QueryBatchAsync(batch);
276+ /// Response<LogsBatchQueryResultCollection > response = await client.QueryBatchAsync(batch);
276277 ///
277278 /// var count = response.Value.GetResult<int>(countQueryId).Single();
278279 /// var topEntries = response.Value.GetResult<MyLogEntryModel>(topQueryId);
@@ -286,8 +287,8 @@ public virtual Response<LogsBatchQueryResults> QueryBatch(LogsBatchQuery batch,
286287 /// </summary>
287288 /// <param name="batch">The batch of Kusto queries to send.</param>
288289 /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
289- /// <returns>The <see cref="LogsBatchQueryResults "/> that allows retrieving query results.</returns>
290- public virtual async Task < Response < LogsBatchQueryResults > > QueryBatchAsync ( LogsBatchQuery batch , CancellationToken cancellationToken = default )
290+ /// <returns>The <see cref="LogsBatchQueryResultCollection "/> that allows retrieving query results.</returns>
291+ public virtual async Task < Response < LogsBatchQueryResultCollection > > QueryBatchAsync ( LogsBatchQuery batch , CancellationToken cancellationToken = default )
291292 {
292293 Argument . AssertNotNull ( batch , nameof ( batch ) ) ;
293294
@@ -296,7 +297,7 @@ public virtual async Task<Response<LogsBatchQueryResults>> QueryBatchAsync(LogsB
296297 try
297298 {
298299 var response = await _queryClient . BatchAsync ( new BatchRequest ( batch . Requests ) , cancellationToken ) . ConfigureAwait ( false ) ;
299- return response ;
300+ return ConvertBatchResponse ( batch , response ) ;
300301 }
301302 catch ( Exception e )
302303 {
@@ -305,6 +306,27 @@ public virtual async Task<Response<LogsBatchQueryResults>> QueryBatchAsync(LogsB
305306 }
306307 }
307308
309+ private static Response < LogsBatchQueryResultCollection > ConvertBatchResponse ( LogsBatchQuery batch , Response < BatchResponse > response )
310+ {
311+ List < LogsBatchQueryResult > batchResponses = new List < LogsBatchQueryResult > ( ) ;
312+ foreach ( var innerResponse in response . Value . Responses )
313+ {
314+ var body = innerResponse . Body ;
315+ body . Status = innerResponse . Status switch
316+ {
317+ >= 400 => LogsBatchQueryResultStatus . Failure ,
318+ _ when body . Error != null => LogsBatchQueryResultStatus . PartialFailure ,
319+ _ => LogsBatchQueryResultStatus . Success
320+ } ;
321+ body . Id = innerResponse . Id ;
322+ batchResponses . Add ( body ) ;
323+ }
324+
325+ return Response . FromValue (
326+ new LogsBatchQueryResultCollection ( batchResponses , batch ) ,
327+ response . GetRawResponse ( ) ) ;
328+ }
329+
308330 /// <summary>
309331 /// Create a Kusto query from an interpolated string. The interpolated values will be quoted and escaped as necessary.
310332 /// </summary>
@@ -499,6 +521,11 @@ await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellat
499521 JsonDocument . Parse ( message . Response . ContentStream , default ) ;
500522
501523 LogsQueryResult value = LogsQueryResult . DeserializeLogsQueryResult ( document . RootElement ) ;
524+ var responseError = value . Error ;
525+ if ( responseError != null && options ? . ThrowOnPartialErrors != false )
526+ {
527+ throw value . CreateExceptionForErrorResponse ( message . Response . Status ) ;
528+ }
502529 return Response . FromValue ( value , message . Response ) ;
503530 }
504531 default :
0 commit comments