< Summary

Class:Azure.Analytics.Synapse.Spark.SparkSessionRestClient
Assembly:Azure.Analytics.Synapse.Spark
File(s):C:\Git\azure-sdk-for-net\sdk\synapse\Azure.Analytics.Synapse.Spark\src\Generated\SparkSessionRestClient.cs
Covered lines:67
Uncovered lines:231
Coverable lines:298
Total lines:647
Line coverage:22.4% (67 of 298)
Covered branches:11
Total branches:60
Branch coverage:18.3% (11 of 60)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-76.92%50%
CreateGetSparkSessionsRequest(...)-83.33%50%
GetSparkSessionsAsync()-87.5%50%
GetSparkSessions(...)-87.5%50%
CreateCreateSparkSessionRequest(...)-0%0%
CreateSparkSessionAsync()-0%0%
CreateSparkSession(...)-0%0%
CreateGetSparkSessionRequest(...)-93.33%50%
GetSparkSessionAsync()-87.5%50%
GetSparkSession(...)-87.5%50%
CreateCancelSparkSessionRequest(...)-0%100%
CancelSparkSessionAsync()-0%0%
CancelSparkSession(...)-0%0%
CreateResetSparkSessionTimeoutRequest(...)-0%100%
ResetSparkSessionTimeoutAsync()-0%0%
ResetSparkSessionTimeout(...)-0%0%
CreateGetSparkStatementsRequest(...)-0%100%
GetSparkStatementsAsync()-0%0%
GetSparkStatements(...)-0%0%
CreateCreateSparkStatementRequest(...)-0%100%
CreateSparkStatementAsync()-0%0%
CreateSparkStatement(...)-0%0%
CreateGetSparkStatementRequest(...)-0%100%
GetSparkStatementAsync()-0%0%
GetSparkStatement(...)-0%0%
CreateCancelSparkStatementRequest(...)-0%100%
CancelSparkStatementAsync()-0%0%
CancelSparkStatement(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\synapse\Azure.Analytics.Synapse.Spark\src\Generated\SparkSessionRestClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Analytics.Synapse.Spark.Models;
 14using Azure.Core;
 15using Azure.Core.Pipeline;
 16
 17namespace Azure.Analytics.Synapse.Spark
 18{
 19    internal partial class SparkSessionRestClient
 20    {
 21        private string endpoint;
 22        private string sparkPoolName;
 23        private string livyApiVersion;
 24        private ClientDiagnostics _clientDiagnostics;
 25        private HttpPipeline _pipeline;
 26
 27        /// <summary> Initializes a new instance of SparkSessionRestClient. </summary>
 28        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 29        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 30        /// <param name="endpoint"> The workspace development endpoint, for example https://myworkspace.dev.azuresynapse
 31        /// <param name="sparkPoolName"> Name of the spark pool. </param>
 32        /// <param name="livyApiVersion"> Valid api-version for the request. </param>
 33        /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/>, <paramref name="sparkPoolName"/>, or <
 834        public SparkSessionRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, strin
 35        {
 836            if (endpoint == null)
 37            {
 038                throw new ArgumentNullException(nameof(endpoint));
 39            }
 840            if (sparkPoolName == null)
 41            {
 042                throw new ArgumentNullException(nameof(sparkPoolName));
 43            }
 844            if (livyApiVersion == null)
 45            {
 046                throw new ArgumentNullException(nameof(livyApiVersion));
 47            }
 48
 849            this.endpoint = endpoint;
 850            this.sparkPoolName = sparkPoolName;
 851            this.livyApiVersion = livyApiVersion;
 852            _clientDiagnostics = clientDiagnostics;
 853            _pipeline = pipeline;
 854        }
 55
 56        internal HttpMessage CreateGetSparkSessionsRequest(int? @from, int? size, bool? detailed)
 57        {
 458            var message = _pipeline.CreateMessage();
 459            var request = message.Request;
 460            request.Method = RequestMethod.Get;
 461            var uri = new RawRequestUriBuilder();
 462            uri.AppendRaw(endpoint, false);
 463            uri.AppendRaw("/livyApi/versions/", false);
 464            uri.AppendRaw(livyApiVersion, false);
 465            uri.AppendRaw("/sparkPools/", false);
 466            uri.AppendRaw(sparkPoolName, false);
 467            uri.AppendPath("/sessions", false);
 468            if (@from != null)
 69            {
 070                uri.AppendQuery("from", @from.Value, true);
 71            }
 472            if (size != null)
 73            {
 074                uri.AppendQuery("size", size.Value, true);
 75            }
 476            if (detailed != null)
 77            {
 078                uri.AppendQuery("detailed", detailed.Value, true);
 79            }
 480            request.Uri = uri;
 481            return message;
 82        }
 83
 84        /// <summary> List all spark sessions which are running under a particular spark pool. </summary>
 85        /// <param name="from"> Optional param specifying which index the list should begin from. </param>
 86        /// <param name="size">
 87        /// Optional param specifying the size of the returned list.
 88        ///
 89        ///             By default it is 20 and that is the maximum.
 90        /// </param>
 91        /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l
 92        /// <param name="cancellationToken"> The cancellation token to use. </param>
 93        public async Task<Response<SparkSessionCollection>> GetSparkSessionsAsync(int? @from = null, int? size = null, b
 94        {
 295            using var message = CreateGetSparkSessionsRequest(@from, size, detailed);
 296            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 297            switch (message.Response.Status)
 98            {
 99                case 200:
 100                    {
 101                        SparkSessionCollection value = default;
 2102                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 2103                        value = SparkSessionCollection.DeserializeSparkSessionCollection(document.RootElement);
 2104                        return Response.FromValue(value, message.Response);
 105                    }
 106                default:
 0107                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 108            }
 2109        }
 110
 111        /// <summary> List all spark sessions which are running under a particular spark pool. </summary>
 112        /// <param name="from"> Optional param specifying which index the list should begin from. </param>
 113        /// <param name="size">
 114        /// Optional param specifying the size of the returned list.
 115        ///
 116        ///             By default it is 20 and that is the maximum.
 117        /// </param>
 118        /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l
 119        /// <param name="cancellationToken"> The cancellation token to use. </param>
 120        public Response<SparkSessionCollection> GetSparkSessions(int? @from = null, int? size = null, bool? detailed = n
 121        {
 2122            using var message = CreateGetSparkSessionsRequest(@from, size, detailed);
 2123            _pipeline.Send(message, cancellationToken);
 2124            switch (message.Response.Status)
 125            {
 126                case 200:
 127                    {
 128                        SparkSessionCollection value = default;
 2129                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2130                        value = SparkSessionCollection.DeserializeSparkSessionCollection(document.RootElement);
 2131                        return Response.FromValue(value, message.Response);
 132                    }
 133                default:
 0134                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 135            }
 2136        }
 137
 138        internal HttpMessage CreateCreateSparkSessionRequest(SparkSessionOptions sparkSessionOptions, bool? detailed)
 139        {
 0140            var message = _pipeline.CreateMessage();
 0141            var request = message.Request;
 0142            request.Method = RequestMethod.Post;
 0143            var uri = new RawRequestUriBuilder();
 0144            uri.AppendRaw(endpoint, false);
 0145            uri.AppendRaw("/livyApi/versions/", false);
 0146            uri.AppendRaw(livyApiVersion, false);
 0147            uri.AppendRaw("/sparkPools/", false);
 0148            uri.AppendRaw(sparkPoolName, false);
 0149            uri.AppendPath("/sessions", false);
 0150            if (detailed != null)
 151            {
 0152                uri.AppendQuery("detailed", detailed.Value, true);
 153            }
 0154            request.Uri = uri;
 0155            request.Headers.Add("Content-Type", "application/json");
 0156            var content = new Utf8JsonRequestContent();
 0157            content.JsonWriter.WriteObjectValue(sparkSessionOptions);
 0158            request.Content = content;
 0159            return message;
 160        }
 161
 162        /// <summary> Create new spark session. </summary>
 163        /// <param name="sparkSessionOptions"> Livy compatible batch job request payload. </param>
 164        /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l
 165        /// <param name="cancellationToken"> The cancellation token to use. </param>
 166        /// <exception cref="ArgumentNullException"> <paramref name="sparkSessionOptions"/> is null. </exception>
 167        public async Task<Response<SparkSession>> CreateSparkSessionAsync(SparkSessionOptions sparkSessionOptions, bool?
 168        {
 0169            if (sparkSessionOptions == null)
 170            {
 0171                throw new ArgumentNullException(nameof(sparkSessionOptions));
 172            }
 173
 0174            using var message = CreateCreateSparkSessionRequest(sparkSessionOptions, detailed);
 0175            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0176            switch (message.Response.Status)
 177            {
 178                case 200:
 179                    {
 180                        SparkSession value = default;
 0181                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0182                        value = SparkSession.DeserializeSparkSession(document.RootElement);
 0183                        return Response.FromValue(value, message.Response);
 184                    }
 185                default:
 0186                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 187            }
 0188        }
 189
 190        /// <summary> Create new spark session. </summary>
 191        /// <param name="sparkSessionOptions"> Livy compatible batch job request payload. </param>
 192        /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l
 193        /// <param name="cancellationToken"> The cancellation token to use. </param>
 194        /// <exception cref="ArgumentNullException"> <paramref name="sparkSessionOptions"/> is null. </exception>
 195        public Response<SparkSession> CreateSparkSession(SparkSessionOptions sparkSessionOptions, bool? detailed = null,
 196        {
 0197            if (sparkSessionOptions == null)
 198            {
 0199                throw new ArgumentNullException(nameof(sparkSessionOptions));
 200            }
 201
 0202            using var message = CreateCreateSparkSessionRequest(sparkSessionOptions, detailed);
 0203            _pipeline.Send(message, cancellationToken);
 0204            switch (message.Response.Status)
 205            {
 206                case 200:
 207                    {
 208                        SparkSession value = default;
 0209                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0210                        value = SparkSession.DeserializeSparkSession(document.RootElement);
 0211                        return Response.FromValue(value, message.Response);
 212                    }
 213                default:
 0214                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 215            }
 0216        }
 217
 218        internal HttpMessage CreateGetSparkSessionRequest(int sessionId, bool? detailed)
 219        {
 80220            var message = _pipeline.CreateMessage();
 80221            var request = message.Request;
 80222            request.Method = RequestMethod.Get;
 80223            var uri = new RawRequestUriBuilder();
 80224            uri.AppendRaw(endpoint, false);
 80225            uri.AppendRaw("/livyApi/versions/", false);
 80226            uri.AppendRaw(livyApiVersion, false);
 80227            uri.AppendRaw("/sparkPools/", false);
 80228            uri.AppendRaw(sparkPoolName, false);
 80229            uri.AppendPath("/sessions/", false);
 80230            uri.AppendPath(sessionId, true);
 80231            if (detailed != null)
 232            {
 0233                uri.AppendQuery("detailed", detailed.Value, true);
 234            }
 80235            request.Uri = uri;
 80236            return message;
 237        }
 238
 239        /// <summary> Gets a single spark session. </summary>
 240        /// <param name="sessionId"> Identifier for the session. </param>
 241        /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l
 242        /// <param name="cancellationToken"> The cancellation token to use. </param>
 243        public async Task<Response<SparkSession>> GetSparkSessionAsync(int sessionId, bool? detailed = null, Cancellatio
 244        {
 40245            using var message = CreateGetSparkSessionRequest(sessionId, detailed);
 40246            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 40247            switch (message.Response.Status)
 248            {
 249                case 200:
 250                    {
 251                        SparkSession value = default;
 40252                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 40253                        value = SparkSession.DeserializeSparkSession(document.RootElement);
 40254                        return Response.FromValue(value, message.Response);
 255                    }
 256                default:
 0257                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 258            }
 40259        }
 260
 261        /// <summary> Gets a single spark session. </summary>
 262        /// <param name="sessionId"> Identifier for the session. </param>
 263        /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l
 264        /// <param name="cancellationToken"> The cancellation token to use. </param>
 265        public Response<SparkSession> GetSparkSession(int sessionId, bool? detailed = null, CancellationToken cancellati
 266        {
 40267            using var message = CreateGetSparkSessionRequest(sessionId, detailed);
 40268            _pipeline.Send(message, cancellationToken);
 40269            switch (message.Response.Status)
 270            {
 271                case 200:
 272                    {
 273                        SparkSession value = default;
 40274                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 40275                        value = SparkSession.DeserializeSparkSession(document.RootElement);
 40276                        return Response.FromValue(value, message.Response);
 277                    }
 278                default:
 0279                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 280            }
 40281        }
 282
 283        internal HttpMessage CreateCancelSparkSessionRequest(int sessionId)
 284        {
 0285            var message = _pipeline.CreateMessage();
 0286            var request = message.Request;
 0287            request.Method = RequestMethod.Delete;
 0288            var uri = new RawRequestUriBuilder();
 0289            uri.AppendRaw(endpoint, false);
 0290            uri.AppendRaw("/livyApi/versions/", false);
 0291            uri.AppendRaw(livyApiVersion, false);
 0292            uri.AppendRaw("/sparkPools/", false);
 0293            uri.AppendRaw(sparkPoolName, false);
 0294            uri.AppendPath("/sessions/", false);
 0295            uri.AppendPath(sessionId, true);
 0296            request.Uri = uri;
 0297            return message;
 298        }
 299
 300        /// <summary> Cancels a running spark session. </summary>
 301        /// <param name="sessionId"> Identifier for the session. </param>
 302        /// <param name="cancellationToken"> The cancellation token to use. </param>
 303        public async Task<Response> CancelSparkSessionAsync(int sessionId, CancellationToken cancellationToken = default
 304        {
 0305            using var message = CreateCancelSparkSessionRequest(sessionId);
 0306            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0307            switch (message.Response.Status)
 308            {
 309                case 200:
 0310                    return message.Response;
 311                default:
 0312                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 313            }
 0314        }
 315
 316        /// <summary> Cancels a running spark session. </summary>
 317        /// <param name="sessionId"> Identifier for the session. </param>
 318        /// <param name="cancellationToken"> The cancellation token to use. </param>
 319        public Response CancelSparkSession(int sessionId, CancellationToken cancellationToken = default)
 320        {
 0321            using var message = CreateCancelSparkSessionRequest(sessionId);
 0322            _pipeline.Send(message, cancellationToken);
 0323            switch (message.Response.Status)
 324            {
 325                case 200:
 0326                    return message.Response;
 327                default:
 0328                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 329            }
 0330        }
 331
 332        internal HttpMessage CreateResetSparkSessionTimeoutRequest(int sessionId)
 333        {
 0334            var message = _pipeline.CreateMessage();
 0335            var request = message.Request;
 0336            request.Method = RequestMethod.Put;
 0337            var uri = new RawRequestUriBuilder();
 0338            uri.AppendRaw(endpoint, false);
 0339            uri.AppendRaw("/livyApi/versions/", false);
 0340            uri.AppendRaw(livyApiVersion, false);
 0341            uri.AppendRaw("/sparkPools/", false);
 0342            uri.AppendRaw(sparkPoolName, false);
 0343            uri.AppendPath("/sessions/", false);
 0344            uri.AppendPath(sessionId, true);
 0345            uri.AppendPath("/reset-timeout", false);
 0346            request.Uri = uri;
 0347            return message;
 348        }
 349
 350        /// <summary> Sends a keep alive call to the current session to reset the session timeout. </summary>
 351        /// <param name="sessionId"> Identifier for the session. </param>
 352        /// <param name="cancellationToken"> The cancellation token to use. </param>
 353        public async Task<Response> ResetSparkSessionTimeoutAsync(int sessionId, CancellationToken cancellationToken = d
 354        {
 0355            using var message = CreateResetSparkSessionTimeoutRequest(sessionId);
 0356            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0357            switch (message.Response.Status)
 358            {
 359                case 200:
 0360                    return message.Response;
 361                default:
 0362                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 363            }
 0364        }
 365
 366        /// <summary> Sends a keep alive call to the current session to reset the session timeout. </summary>
 367        /// <param name="sessionId"> Identifier for the session. </param>
 368        /// <param name="cancellationToken"> The cancellation token to use. </param>
 369        public Response ResetSparkSessionTimeout(int sessionId, CancellationToken cancellationToken = default)
 370        {
 0371            using var message = CreateResetSparkSessionTimeoutRequest(sessionId);
 0372            _pipeline.Send(message, cancellationToken);
 0373            switch (message.Response.Status)
 374            {
 375                case 200:
 0376                    return message.Response;
 377                default:
 0378                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 379            }
 0380        }
 381
 382        internal HttpMessage CreateGetSparkStatementsRequest(int sessionId)
 383        {
 0384            var message = _pipeline.CreateMessage();
 0385            var request = message.Request;
 0386            request.Method = RequestMethod.Get;
 0387            var uri = new RawRequestUriBuilder();
 0388            uri.AppendRaw(endpoint, false);
 0389            uri.AppendRaw("/livyApi/versions/", false);
 0390            uri.AppendRaw(livyApiVersion, false);
 0391            uri.AppendRaw("/sparkPools/", false);
 0392            uri.AppendRaw(sparkPoolName, false);
 0393            uri.AppendPath("/sessions/", false);
 0394            uri.AppendPath(sessionId, true);
 0395            uri.AppendPath("/statements", false);
 0396            request.Uri = uri;
 0397            return message;
 398        }
 399
 400        /// <summary> Gets a list of statements within a spark session. </summary>
 401        /// <param name="sessionId"> Identifier for the session. </param>
 402        /// <param name="cancellationToken"> The cancellation token to use. </param>
 403        public async Task<Response<SparkStatementCollection>> GetSparkStatementsAsync(int sessionId, CancellationToken c
 404        {
 0405            using var message = CreateGetSparkStatementsRequest(sessionId);
 0406            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0407            switch (message.Response.Status)
 408            {
 409                case 200:
 410                    {
 411                        SparkStatementCollection value = default;
 0412                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0413                        value = SparkStatementCollection.DeserializeSparkStatementCollection(document.RootElement);
 0414                        return Response.FromValue(value, message.Response);
 415                    }
 416                default:
 0417                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 418            }
 0419        }
 420
 421        /// <summary> Gets a list of statements within a spark session. </summary>
 422        /// <param name="sessionId"> Identifier for the session. </param>
 423        /// <param name="cancellationToken"> The cancellation token to use. </param>
 424        public Response<SparkStatementCollection> GetSparkStatements(int sessionId, CancellationToken cancellationToken 
 425        {
 0426            using var message = CreateGetSparkStatementsRequest(sessionId);
 0427            _pipeline.Send(message, cancellationToken);
 0428            switch (message.Response.Status)
 429            {
 430                case 200:
 431                    {
 432                        SparkStatementCollection value = default;
 0433                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0434                        value = SparkStatementCollection.DeserializeSparkStatementCollection(document.RootElement);
 0435                        return Response.FromValue(value, message.Response);
 436                    }
 437                default:
 0438                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 439            }
 0440        }
 441
 442        internal HttpMessage CreateCreateSparkStatementRequest(int sessionId, SparkStatementOptions sparkStatementOption
 443        {
 0444            var message = _pipeline.CreateMessage();
 0445            var request = message.Request;
 0446            request.Method = RequestMethod.Post;
 0447            var uri = new RawRequestUriBuilder();
 0448            uri.AppendRaw(endpoint, false);
 0449            uri.AppendRaw("/livyApi/versions/", false);
 0450            uri.AppendRaw(livyApiVersion, false);
 0451            uri.AppendRaw("/sparkPools/", false);
 0452            uri.AppendRaw(sparkPoolName, false);
 0453            uri.AppendPath("/sessions/", false);
 0454            uri.AppendPath(sessionId, true);
 0455            uri.AppendPath("/statements", false);
 0456            request.Uri = uri;
 0457            request.Headers.Add("Content-Type", "application/json");
 0458            var content = new Utf8JsonRequestContent();
 0459            content.JsonWriter.WriteObjectValue(sparkStatementOptions);
 0460            request.Content = content;
 0461            return message;
 462        }
 463
 464        /// <summary> Create statement within a spark session. </summary>
 465        /// <param name="sessionId"> Identifier for the session. </param>
 466        /// <param name="sparkStatementOptions"> Livy compatible batch job request payload. </param>
 467        /// <param name="cancellationToken"> The cancellation token to use. </param>
 468        /// <exception cref="ArgumentNullException"> <paramref name="sparkStatementOptions"/> is null. </exception>
 469        public async Task<Response<SparkStatement>> CreateSparkStatementAsync(int sessionId, SparkStatementOptions spark
 470        {
 0471            if (sparkStatementOptions == null)
 472            {
 0473                throw new ArgumentNullException(nameof(sparkStatementOptions));
 474            }
 475
 0476            using var message = CreateCreateSparkStatementRequest(sessionId, sparkStatementOptions);
 0477            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0478            switch (message.Response.Status)
 479            {
 480                case 200:
 481                    {
 482                        SparkStatement value = default;
 0483                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0484                        value = SparkStatement.DeserializeSparkStatement(document.RootElement);
 0485                        return Response.FromValue(value, message.Response);
 486                    }
 487                default:
 0488                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 489            }
 0490        }
 491
 492        /// <summary> Create statement within a spark session. </summary>
 493        /// <param name="sessionId"> Identifier for the session. </param>
 494        /// <param name="sparkStatementOptions"> Livy compatible batch job request payload. </param>
 495        /// <param name="cancellationToken"> The cancellation token to use. </param>
 496        /// <exception cref="ArgumentNullException"> <paramref name="sparkStatementOptions"/> is null. </exception>
 497        public Response<SparkStatement> CreateSparkStatement(int sessionId, SparkStatementOptions sparkStatementOptions,
 498        {
 0499            if (sparkStatementOptions == null)
 500            {
 0501                throw new ArgumentNullException(nameof(sparkStatementOptions));
 502            }
 503
 0504            using var message = CreateCreateSparkStatementRequest(sessionId, sparkStatementOptions);
 0505            _pipeline.Send(message, cancellationToken);
 0506            switch (message.Response.Status)
 507            {
 508                case 200:
 509                    {
 510                        SparkStatement value = default;
 0511                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0512                        value = SparkStatement.DeserializeSparkStatement(document.RootElement);
 0513                        return Response.FromValue(value, message.Response);
 514                    }
 515                default:
 0516                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 517            }
 0518        }
 519
 520        internal HttpMessage CreateGetSparkStatementRequest(int sessionId, int statementId)
 521        {
 0522            var message = _pipeline.CreateMessage();
 0523            var request = message.Request;
 0524            request.Method = RequestMethod.Get;
 0525            var uri = new RawRequestUriBuilder();
 0526            uri.AppendRaw(endpoint, false);
 0527            uri.AppendRaw("/livyApi/versions/", false);
 0528            uri.AppendRaw(livyApiVersion, false);
 0529            uri.AppendRaw("/sparkPools/", false);
 0530            uri.AppendRaw(sparkPoolName, false);
 0531            uri.AppendPath("/sessions/", false);
 0532            uri.AppendPath(sessionId, true);
 0533            uri.AppendPath("/statements/", false);
 0534            uri.AppendPath(statementId, true);
 0535            request.Uri = uri;
 0536            return message;
 537        }
 538
 539        /// <summary> Gets a single statement within a spark session. </summary>
 540        /// <param name="sessionId"> Identifier for the session. </param>
 541        /// <param name="statementId"> Identifier for the statement. </param>
 542        /// <param name="cancellationToken"> The cancellation token to use. </param>
 543        public async Task<Response<SparkStatement>> GetSparkStatementAsync(int sessionId, int statementId, CancellationT
 544        {
 0545            using var message = CreateGetSparkStatementRequest(sessionId, statementId);
 0546            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0547            switch (message.Response.Status)
 548            {
 549                case 200:
 550                    {
 551                        SparkStatement value = default;
 0552                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0553                        value = SparkStatement.DeserializeSparkStatement(document.RootElement);
 0554                        return Response.FromValue(value, message.Response);
 555                    }
 556                default:
 0557                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 558            }
 0559        }
 560
 561        /// <summary> Gets a single statement within a spark session. </summary>
 562        /// <param name="sessionId"> Identifier for the session. </param>
 563        /// <param name="statementId"> Identifier for the statement. </param>
 564        /// <param name="cancellationToken"> The cancellation token to use. </param>
 565        public Response<SparkStatement> GetSparkStatement(int sessionId, int statementId, CancellationToken cancellation
 566        {
 0567            using var message = CreateGetSparkStatementRequest(sessionId, statementId);
 0568            _pipeline.Send(message, cancellationToken);
 0569            switch (message.Response.Status)
 570            {
 571                case 200:
 572                    {
 573                        SparkStatement value = default;
 0574                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0575                        value = SparkStatement.DeserializeSparkStatement(document.RootElement);
 0576                        return Response.FromValue(value, message.Response);
 577                    }
 578                default:
 0579                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 580            }
 0581        }
 582
 583        internal HttpMessage CreateCancelSparkStatementRequest(int sessionId, int statementId)
 584        {
 0585            var message = _pipeline.CreateMessage();
 0586            var request = message.Request;
 0587            request.Method = RequestMethod.Post;
 0588            var uri = new RawRequestUriBuilder();
 0589            uri.AppendRaw(endpoint, false);
 0590            uri.AppendRaw("/livyApi/versions/", false);
 0591            uri.AppendRaw(livyApiVersion, false);
 0592            uri.AppendRaw("/sparkPools/", false);
 0593            uri.AppendRaw(sparkPoolName, false);
 0594            uri.AppendPath("/sessions/", false);
 0595            uri.AppendPath(sessionId, true);
 0596            uri.AppendPath("/statements/", false);
 0597            uri.AppendPath(statementId, true);
 0598            uri.AppendPath("/cancel", false);
 0599            request.Uri = uri;
 0600            return message;
 601        }
 602
 603        /// <summary> Kill a statement within a session. </summary>
 604        /// <param name="sessionId"> Identifier for the session. </param>
 605        /// <param name="statementId"> Identifier for the statement. </param>
 606        /// <param name="cancellationToken"> The cancellation token to use. </param>
 607        public async Task<Response<SparkStatementCancellationResult>> CancelSparkStatementAsync(int sessionId, int state
 608        {
 0609            using var message = CreateCancelSparkStatementRequest(sessionId, statementId);
 0610            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0611            switch (message.Response.Status)
 612            {
 613                case 200:
 614                    {
 615                        SparkStatementCancellationResult value = default;
 0616                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0617                        value = SparkStatementCancellationResult.DeserializeSparkStatementCancellationResult(document.Ro
 0618                        return Response.FromValue(value, message.Response);
 619                    }
 620                default:
 0621                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 622            }
 0623        }
 624
 625        /// <summary> Kill a statement within a session. </summary>
 626        /// <param name="sessionId"> Identifier for the session. </param>
 627        /// <param name="statementId"> Identifier for the statement. </param>
 628        /// <param name="cancellationToken"> The cancellation token to use. </param>
 629        public Response<SparkStatementCancellationResult> CancelSparkStatement(int sessionId, int statementId, Cancellat
 630        {
 0631            using var message = CreateCancelSparkStatementRequest(sessionId, statementId);
 0632            _pipeline.Send(message, cancellationToken);
 0633            switch (message.Response.Status)
 634            {
 635                case 200:
 636                    {
 637                        SparkStatementCancellationResult value = default;
 0638                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0639                        value = SparkStatementCancellationResult.DeserializeSparkStatementCancellationResult(document.Ro
 0640                        return Response.FromValue(value, message.Response);
 641                    }
 642                default:
 0643                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 644            }
 0645        }
 646    }
 647}