HackPoint commented on code in PR #44783:
URL: https://github.com/apache/arrow/pull/44783#discussion_r1968073191


##########
csharp/src/Apache.Arrow.Flight.Sql/PreparedStatement.cs:
##########
@@ -0,0 +1,383 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Apache.Arrow.Flight.Sql.Client;
+using Arrow.Flight.Protocol.Sql;
+using Google.Protobuf;
+using Grpc.Core;
+
+namespace Apache.Arrow.Flight.Sql;
+
+public class PreparedStatement : IDisposable
+{
+    private readonly FlightSqlClient _client;
+    private readonly string _handle;
+    private Schema _datasetSchema;
+    private Schema _parameterSchema;
+    private RecordBatch? _recordsBatch;
+    private bool _isClosed;
+    public bool IsClosed => _isClosed;
+    public string Handle => _handle;
+    public RecordBatch? ParametersBatch => _recordsBatch;
+
+    /// <summary>
+    /// Initializes a new instance of the <see cref="PreparedStatement"/> 
class.
+    /// </summary>
+    /// <param name="client">The Flight SQL client used for executing SQL 
operations.</param>
+    /// <param name="handle">The handle representing the prepared 
statement.</param>
+    /// <param name="datasetSchema">The schema of the result dataset.</param>
+    /// <param name="parameterSchema">The schema of the parameters for this 
prepared statement.</param>
+    public PreparedStatement(FlightSqlClient client, string handle, Schema 
datasetSchema, Schema parameterSchema)
+    {
+        _client = client ?? throw new ArgumentNullException(nameof(client));
+        _handle = handle ?? throw new ArgumentNullException(nameof(handle));
+        _datasetSchema = datasetSchema ?? throw new 
ArgumentNullException(nameof(datasetSchema));
+        _parameterSchema = parameterSchema ?? throw new 
ArgumentNullException(nameof(parameterSchema));
+        _isClosed = false;
+    }
+
+    /// <summary>
+    /// Retrieves the schema associated with the prepared statement 
asynchronously.
+    /// </summary>
+    /// <param name="options">The options used to configure the Flight 
call.</param>
+    /// <returns>A task representing the asynchronous operation, which returns 
the schema of the result set.</returns>
+    /// <exception cref="InvalidOperationException">Thrown when the schema is 
empty or invalid.</exception>
+    public async Task<Schema> GetSchemaAsync(FlightCallOptions? options = 
default)
+    {
+        EnsureStatementIsNotClosed();
+
+        try
+        {
+            var command = new CommandPreparedStatementQuery
+            {
+                PreparedStatementHandle = ByteString.CopyFrom(_handle, 
Encoding.UTF8)
+            };
+            var descriptor = 
FlightDescriptor.CreateCommandDescriptor(command.PackAndSerialize());
+            var schema = await _client.GetSchemaAsync(descriptor, 
options).ConfigureAwait(false);
+            if (schema == null || !schema.FieldsList.Any())
+            {
+                throw new InvalidOperationException("Schema is empty or 
invalid.");
+            }
+            return schema;
+        }
+        catch (RpcException ex)
+        {
+            throw new InvalidOperationException("Failed to retrieve the schema 
for the prepared statement", ex);
+        }
+    }
+
+

Review Comment:
   don't the extra line, but removed one above.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to