diff --git a/csharp/src/Apache.Arrow.Flight.Sql/Client/FlightSqlClient.cs b/csharp/src/Apache.Arrow.Flight.Sql/Client/FlightSqlClient.cs index 55c23f66f356b..54feb7ab6c8c2 100644 --- a/csharp/src/Apache.Arrow.Flight.Sql/Client/FlightSqlClient.cs +++ b/csharp/src/Apache.Arrow.Flight.Sql/Client/FlightSqlClient.cs @@ -39,10 +39,13 @@ public FlightSqlClient(FlightClient client) /// A transaction to associate this query with. /// RPC-layer hints for this call. /// The FlightInfo describing where to access the dataset. - public async Task ExecuteAsync(string query, Transaction? transaction = null, FlightCallOptions? options = default) + public async Task ExecuteAsync(string query, Transaction transaction = default, FlightCallOptions? options = null) { - transaction ??= Transaction.NoTransaction; - + if (transaction == default) + { + transaction = Transaction.NoTransaction; + } + if (string.IsNullOrEmpty(query)) { throw new ArgumentException($"Query cannot be null or empty: {nameof(query)}"); @@ -66,15 +69,18 @@ public async Task ExecuteAsync(string query, Transaction? transactio } /// - /// Executes an update query on the server. + /// Executes an update SQL command and returns the number of affected rows. /// /// The UTF8-encoded SQL query to be executed. /// A transaction to associate this query with. Defaults to no transaction if not provided. /// RPC-layer hints for this call. /// The number of rows affected by the operation. - public async Task ExecuteUpdateAsync(string query, Transaction? transaction = null, FlightCallOptions? options = default) + public async Task ExecuteUpdateAsync(string query, Transaction transaction = default, FlightCallOptions? options = null) { - transaction ??= Transaction.NoTransaction; + if (transaction == default) + { + transaction = Transaction.NoTransaction; + } if (string.IsNullOrEmpty(query)) { @@ -104,10 +110,7 @@ public async Task ExecuteUpdateAsync(string query, Transaction? transactio await foreach (var recordBatch in doGetResult.ConfigureAwait(false)) { - foreach (var rowCount in recordBatch.ExtractRowCount()) - { - affectedRows += rowCount; - } + affectedRows += recordBatch.ExtractRowCount(); } } @@ -170,9 +173,12 @@ public async IAsyncEnumerable DoActionAsync(FlightAction action, F /// A transaction to associate this query with /// Per-RPC options /// The SchemaResult describing the schema of the result set - public async Task GetExecuteSchemaAsync(string query, Transaction? transaction = null, FlightCallOptions? options = default) + public async Task GetExecuteSchemaAsync(string query, Transaction transaction = default, FlightCallOptions? options = null) { - transaction ??= Transaction.NoTransaction; + if (transaction == default) + { + transaction = Transaction.NoTransaction; + } if (string.IsNullOrEmpty(query)) throw new ArgumentException($"Query cannot be null or empty: {nameof(query)}"); @@ -897,12 +903,15 @@ public AsyncServerStreamingCall RollbackAsync(Transaction transact /// A transaction to associate this query with. /// RPC-layer hints for this call. /// The created prepared statement. - public async Task PrepareAsync(string query, Transaction? transaction = null, FlightCallOptions? options = default) + public async Task PrepareAsync(string query, Transaction transaction = default, FlightCallOptions? options = null) { if (string.IsNullOrEmpty(query)) throw new ArgumentException("Query cannot be null or empty", nameof(query)); - transaction ??= Transaction.NoTransaction; + if (transaction == default) + { + transaction = Transaction.NoTransaction; + } try { diff --git a/csharp/src/Apache.Arrow.Flight.Sql/FlightCallOptions.cs b/csharp/src/Apache.Arrow.Flight.Sql/FlightCallOptions.cs index d5b275b816a4f..17541b26e7393 100644 --- a/csharp/src/Apache.Arrow.Flight.Sql/FlightCallOptions.cs +++ b/csharp/src/Apache.Arrow.Flight.Sql/FlightCallOptions.cs @@ -26,22 +26,13 @@ public FlightCallOptions() { Timeout = TimeSpan.FromSeconds(-1); } + // Implement any necessary options for RPC calls public Metadata Headers { get; set; } = new(); - /// - /// Gets or sets a token to enable interactive user cancellation of long-running requests. - /// - public CancellationToken StopToken { get; set; } - /// /// Gets or sets the optional timeout for this call. /// Negative durations mean an implementation-defined default behavior will be used instead. /// public TimeSpan Timeout { get; set; } - - /// - /// Gets or sets an optional memory manager to control where to allocate incoming data. - /// - public MemoryManager? MemoryManager { get; set; } } diff --git a/csharp/src/Apache.Arrow.Flight.Sql/FlightExtensions.cs b/csharp/src/Apache.Arrow.Flight.Sql/FlightExtensions.cs index 1b9d3e84f25d0..a0936eb7f34e8 100644 --- a/csharp/src/Apache.Arrow.Flight.Sql/FlightExtensions.cs +++ b/csharp/src/Apache.Arrow.Flight.Sql/FlightExtensions.cs @@ -14,7 +14,6 @@ // limitations under the License. using System; -using System.Collections.Generic; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; @@ -23,59 +22,20 @@ namespace Apache.Arrow.Flight.Sql; internal static class FlightExtensions { public static byte[] PackAndSerialize(this IMessage command) => Any.Pack(command).ToByteArray(); - public static T ParseAndUnpack(this ByteString source) where T : IMessage, new() => Any.Parser.ParseFrom(source).Unpack(); - public static IEnumerable ExtractRowCount(this RecordBatch batch) - { - foreach (var array in batch.Arrays) - { - var values = ExtractValues(array); - foreach (var value in values) - { - yield return value switch - { - long l => l, - int i => i != 0 ? i : 0, - _ => 0L - }; - } - } - } - - private static IEnumerable ExtractValues(IArrowArray array) - { - return array switch - { - Int32Array int32Array => ExtractPrimitiveValues(int32Array), - Int64Array int64Array => ExtractPrimitiveValues(int64Array), - FloatArray floatArray => ExtractPrimitiveValues(floatArray), - BooleanArray booleanArray => ExtractBooleanValues(booleanArray), - StringArray stringArray => ExtractStringValues(stringArray), - _ => throw new NotSupportedException($"Array type {array.GetType().Name} is not supported.") - }; - } - - private static IEnumerable ExtractPrimitiveValues(PrimitiveArray array) where T : struct, IEquatable - { - for (int i = 0; i < array.Length; i++) - { - yield return array.IsNull(i) ? null : array.Values[i]; - } - } - - private static IEnumerable ExtractBooleanValues(BooleanArray array) - { - for (int i = 0; i < array.Length; i++) - { - yield return array.IsNull(i) ? null : array.Values[i]; - } - } - - private static IEnumerable ExtractStringValues(StringArray stringArray) + public static T ParseAndUnpack(this ByteString source) where T : IMessage, new() => + Any.Parser.ParseFrom(source).Unpack(); + + public static int ExtractRowCount(this RecordBatch batch) { - for (int i = 0; i < stringArray.Length; i++) + if (batch.ColumnCount == 0) return 0; + int length = batch.Column(0).Length; + foreach (var column in batch.Arrays) { - yield return stringArray.IsNull(i) ? null : stringArray.GetString(i); + if (column.Length != length) + throw new InvalidOperationException("Inconsistent column lengths in RecordBatch."); } + + return length; } } \ No newline at end of file diff --git a/csharp/src/Apache.Arrow.Flight.Sql/PreparedStatement.cs b/csharp/src/Apache.Arrow.Flight.Sql/PreparedStatement.cs index 0399e1636762a..673c74e4d5108 100644 --- a/csharp/src/Apache.Arrow.Flight.Sql/PreparedStatement.cs +++ b/csharp/src/Apache.Arrow.Flight.Sql/PreparedStatement.cs @@ -84,7 +84,6 @@ public async Task GetSchemaAsync(FlightCallOptions? options = default) } } - /// /// Closes the prepared statement asynchronously. /// diff --git a/csharp/src/Apache.Arrow.Flight.Sql/RecordBatchExtensions.cs b/csharp/src/Apache.Arrow.Flight.Sql/RecordBatchExtensions.cs deleted file mode 100644 index 5aecc084fd5f4..0000000000000 --- a/csharp/src/Apache.Arrow.Flight.Sql/RecordBatchExtensions.cs +++ /dev/null @@ -1,138 +0,0 @@ -// 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.IO; -using System.Linq; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; -using Apache.Arrow.Ipc; -using Google.Protobuf; -using Grpc.Core; - -namespace Apache.Arrow.Flight.Sql; - -public static class RecordBatchExtensions -{ - /// - /// Converts a RecordBatch into an asynchronous stream of FlightData. - /// - /// The RecordBatch to convert. - /// The FlightDescriptor describing the Flight data. - /// An asynchronous stream of FlightData objects. - public static async IAsyncEnumerable ToFlightDataStreamAsync(this RecordBatch recordBatch, - FlightDescriptor flightDescriptor) - { - if (recordBatch == null) - { - throw new ArgumentNullException(nameof(recordBatch)); - } - - // Use a memory stream to write the Arrow RecordBatch into FlightData format - using var memoryStream = new MemoryStream(); - var writer = new ArrowStreamWriter(memoryStream, recordBatch.Schema); - - // Write the RecordBatch to the stream - await writer.WriteRecordBatchAsync(recordBatch).ConfigureAwait(false); - await writer.WriteEndAsync().ConfigureAwait(false); - - // Reset the memory stream position - memoryStream.Position = 0; - - // Read back the data to create FlightData - var flightData = new FlightData(flightDescriptor, ByteString.CopyFrom(memoryStream.ToArray()), - ByteString.CopyFrom(memoryStream.ToArray())); - yield return flightData; - } - - /// - /// Converts a RecordBatch into an IAsyncStreamReader. - /// - /// The RecordBatch to convert. - /// The FlightDescriptor describing the Flight data. - /// An IAsyncStreamReader of FlightData. - public static IAsyncStreamReader ToFlightDataStream(this RecordBatch recordBatch, FlightDescriptor flightDescriptor) - { - if (recordBatch == null) throw new ArgumentNullException(nameof(recordBatch)); - if (flightDescriptor == null) throw new ArgumentNullException(nameof(flightDescriptor)); - - var channel = Channel.CreateUnbounded(); - - try - { - if (recordBatch.Schema == null || !recordBatch.Schema.FieldsList.Any()) - { - throw new InvalidOperationException("The record batch has an invalid or empty schema."); - } - - using var memoryStream = new MemoryStream(); - using var writer = new ArrowStreamWriter(memoryStream, recordBatch.Schema); - writer.WriteRecordBatch(recordBatch); - writer.WriteEnd(); - memoryStream.Position = 0; - var flightData = new FlightData(flightDescriptor, ByteString.CopyFrom(memoryStream.ToArray()), ByteString.Empty, ByteString.Empty); - if (flightData.DataBody.IsEmpty) - { - throw new InvalidOperationException( - "The generated FlightData is empty. Check the RecordBatch content."); - } - - channel.Writer.TryWrite(flightData); - } - finally - { - // Mark the channel as complete once done - channel.Writer.Complete(); - } - return new ChannelFlightDataReader(channel.Reader); - } - - /// - /// Custom IAsyncStreamReader implementation to read from a ChannelReader. - /// - private class ChannelFlightDataReader : IAsyncStreamReader - { - private readonly ChannelReader _channelReader; - - public ChannelFlightDataReader(ChannelReader channelReader) - { - _channelReader = channelReader ?? throw new ArgumentNullException(nameof(channelReader)); - Current = default!; - } - - public FlightData Current { get; private set; } - - public async Task MoveNext(CancellationToken cancellationToken) - { - if (await _channelReader.WaitToReadAsync(cancellationToken).ConfigureAwait(false)) - { - if (_channelReader.TryRead(out var flightData)) - { - Current = flightData; - return true; - } - } - - return false; - } - - public void Dispose() - { - // No additional cleanup is required here since we're not managing external resources. - } - } -} \ No newline at end of file diff --git a/csharp/src/Apache.Arrow.Flight.Sql/SchemaExtensions.cs b/csharp/src/Apache.Arrow.Flight.Sql/SchemaExtensions.cs index 146293ec118a3..e734736242ec5 100644 --- a/csharp/src/Apache.Arrow.Flight.Sql/SchemaExtensions.cs +++ b/csharp/src/Apache.Arrow.Flight.Sql/SchemaExtensions.cs @@ -26,15 +26,13 @@ public static class SchemaExtensions /// /// The byte array representing the serialized schema. /// The deserialized Schema object. - public static Schema DeserializeSchema(byte[] serializedSchema) + public static Schema DeserializeSchema(ReadOnlyMemory serializedSchema) { - if (serializedSchema == null || serializedSchema.Length == 0) + if (serializedSchema.IsEmpty) { - throw new ArgumentException("Invalid serialized schema"); + throw new ArgumentException("Invalid serialized schema", nameof(serializedSchema)); } - - using var stream = new MemoryStream(serializedSchema); - var reader = new ArrowStreamReader(stream); + using var reader = new ArrowStreamReader(serializedSchema); return reader.Schema; } diff --git a/csharp/src/Apache.Arrow.Flight.Sql/TableRef.cs b/csharp/src/Apache.Arrow.Flight.Sql/TableRef.cs index b4026ab348d0d..9c98e5ff1d1d0 100644 --- a/csharp/src/Apache.Arrow.Flight.Sql/TableRef.cs +++ b/csharp/src/Apache.Arrow.Flight.Sql/TableRef.cs @@ -13,11 +13,26 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; + namespace Apache.Arrow.Flight.Sql; public class TableRef { - public string? Catalog { get; set; } - public string DbSchema { get; set; } = null!; - public string Table { get; set; } = null!; + public string? Catalog { get; } + public string DbSchema { get; } + public string Table { get; } + + public TableRef(string dbSchema, string table) + { + DbSchema = dbSchema ?? throw new ArgumentNullException(nameof(dbSchema)); + Table = table ?? throw new ArgumentNullException(nameof(table)); + } + + public TableRef(string? catalog, string dbSchema, string table) + { + Catalog = catalog; + DbSchema = dbSchema ?? throw new ArgumentNullException(nameof(dbSchema)); + Table = table ?? throw new ArgumentNullException(nameof(table)); + } } diff --git a/csharp/src/Apache.Arrow.Flight.Sql/Transaction.cs b/csharp/src/Apache.Arrow.Flight.Sql/Transaction.cs index a85ea9ca6a77d..eee8de2ddb683 100644 --- a/csharp/src/Apache.Arrow.Flight.Sql/Transaction.cs +++ b/csharp/src/Apache.Arrow.Flight.Sql/Transaction.cs @@ -13,26 +13,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Google.Protobuf; - namespace Apache.Arrow.Flight.Sql; -public class Transaction +using Google.Protobuf; // Ensure you have the Protobuf dependency + +public readonly struct Transaction { private static readonly ByteString TransactionIdDefaultValue = ByteString.Empty; - private ByteString? _transactionId; - public ByteString TransactionId - { - get => _transactionId ?? TransactionIdDefaultValue; - set => _transactionId = ProtoPreconditions.CheckNotNull(value, nameof(value)); - } + private readonly ByteString _transactionId; + + public ByteString TransactionId => _transactionId ?? TransactionIdDefaultValue; public static readonly Transaction NoTransaction = new(TransactionIdDefaultValue); public Transaction(ByteString transactionId) { - TransactionId = transactionId; + _transactionId = ProtoPreconditions.CheckNotNull(transactionId, nameof(transactionId)); } public Transaction(string transactionId) @@ -40,9 +37,12 @@ public Transaction(string transactionId) _transactionId = ByteString.CopyFromUtf8(transactionId); } - public bool IsValid() => TransactionId.Length > 0; - public void ResetTransaction() - { - _transactionId = TransactionIdDefaultValue; - } + public bool IsValid() => _transactionId.Length > 0; + + public override bool Equals(object? obj) => obj is Transaction other && _transactionId.Equals(other._transactionId); + + public override int GetHashCode() => _transactionId.GetHashCode(); + + public static bool operator ==(Transaction left, Transaction right) => left.Equals(right); + public static bool operator !=(Transaction left, Transaction right) => !left.Equals(right); } diff --git a/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlClientTests.cs b/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlClientTests.cs index 92311171bc6bd..420f0dba8efec 100644 --- a/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlClientTests.cs +++ b/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlClientTests.cs @@ -73,7 +73,7 @@ public async Task BeginTransactionAsync() var transaction = await _flightSqlClient.BeginTransactionAsync(); // Assert - Assert.NotNull(transaction); + Assert.NotEqual(Transaction.NoTransaction, transaction); Assert.Equal(ByteString.CopyFromUtf8(expectedTransactionId), transaction.TransactionId); } @@ -89,7 +89,6 @@ public async Task RollbackTransactionAsync() var result = await streamCall.ResponseStream.ToListAsync(); // Assert - Assert.NotNull(transaction); Assert.Equal(result.FirstOrDefault()?.Body, transaction.TransactionId); } @@ -116,25 +115,27 @@ public async Task PreparedAsync() new Int32Array.Builder().Append(1).Build(), new StringArray.Builder().Append("John Doe").Build() }, 1); - + var flightHolder = new FlightHolder(flightDescriptor, schema, _testWebFactory.GetAddress()); flightHolder.AddBatch(new RecordBatchWithMetadata(recordBatch)); _flightStore.Flights.Add(flightDescriptor, flightHolder); - + var datasetSchemaBytes = SchemaExtensions.SerializeSchema(schema); var parameterSchemaBytes = SchemaExtensions.SerializeSchema(schema); - + var preparedStatementResponse = new ActionCreatePreparedStatementResult { PreparedStatementHandle = ByteString.CopyFromUtf8("prepared-handle"), DatasetSchema = ByteString.CopyFrom(datasetSchemaBytes), ParameterSchema = ByteString.CopyFrom(parameterSchemaBytes) }; - + // Act var preparedStatement = await _flightSqlClient.PrepareAsync(query, transaction); - var deserializedDatasetSchema = SchemaExtensions.DeserializeSchema(preparedStatementResponse.DatasetSchema.ToByteArray()); - var deserializedParameterSchema = SchemaExtensions.DeserializeSchema(preparedStatementResponse.ParameterSchema.ToByteArray()); + var deserializedDatasetSchema = + SchemaExtensions.DeserializeSchema(preparedStatementResponse.DatasetSchema.ToByteArray()); + var deserializedParameterSchema = + SchemaExtensions.DeserializeSchema(preparedStatementResponse.ParameterSchema.ToByteArray()); // Assert Assert.NotNull(preparedStatement); @@ -150,21 +151,20 @@ public async Task PreparedAsync() public async Task ExecuteUpdateAsync() { // Arrange - string query = "UPDATE test_table SET column1 = 'value' WHERE column2 = 'condition'"; + string query = "UPDATE test_table SET column1 = 'value'"; var transaction = new Transaction("sample-transaction-id"); var flightDescriptor = FlightDescriptor.CreateCommandDescriptor("test"); - + var schema = new Schema.Builder() .Field(f => f.Name("id").DataType(Int32Type.Default)) .Field(f => f.Name("name").DataType(StringType.Default)) .Build(); - var recordBatch = new RecordBatch(schema, new Array[] + var recordBatch = new RecordBatch(schema, new IArrowArray[] { - new Int32Array.Builder().Append(1).Build(), - new StringArray.Builder().Append("John Doe").Build() - }, 1); - + new Int32Array.Builder().AppendRange([1, 2, 3, 4, 5]).Build(), + new StringArray.Builder().AppendRange(["John Doe", "Jane Doe", "Alice", "Bob", "Charlie"]).Build() + }, 5); var flightHolder = new FlightHolder(flightDescriptor, recordBatch.Schema, _testWebFactory.GetAddress()); flightHolder.AddBatch(new RecordBatchWithMetadata(recordBatch)); @@ -174,7 +174,7 @@ public async Task ExecuteUpdateAsync() long affectedRows = await _flightSqlClient.ExecuteUpdateAsync(query, transaction); // Assert - Assert.Equal(1, affectedRows); + Assert.Equal(5, affectedRows); } [Fact] @@ -210,7 +210,7 @@ public async Task ExecuteAsync_ShouldReturnFlightInfo_WhenValidInputsAreProvided var flightHolder = new FlightHolder(flightDescriptor, recordBatch.Schema, _testWebFactory.GetAddress()); _flightStore.Flights.Add(flightDescriptor, flightHolder); - + // Act var flightInfo = await _flightSqlClient.ExecuteAsync(query, transaction); @@ -218,7 +218,7 @@ public async Task ExecuteAsync_ShouldReturnFlightInfo_WhenValidInputsAreProvided Assert.NotNull(flightInfo); Assert.IsType(flightInfo); } - + [Fact] public async Task ExecuteAsync_ShouldThrowArgumentException_WhenQueryIsEmpty() { @@ -230,7 +230,7 @@ public async Task ExecuteAsync_ShouldThrowArgumentException_WhenQueryIsEmpty() await Assert.ThrowsAsync(async () => await _flightSqlClient.ExecuteAsync(emptyQuery, transaction)); } - + [Fact] public async Task ExecuteAsync_ShouldReturnFlightInfo_WhenTransactionIsNoTransaction() { @@ -242,7 +242,7 @@ public async Task ExecuteAsync_ShouldReturnFlightInfo_WhenTransactionIsNoTransac var flightHolder = new FlightHolder(flightDescriptor, recordBatch.Schema, _testWebFactory.GetAddress()); _flightStore.Flights.Add(flightDescriptor, flightHolder); - + // Act var flightInfo = await _flightSqlClient.ExecuteAsync(query, transaction); @@ -251,7 +251,6 @@ public async Task ExecuteAsync_ShouldReturnFlightInfo_WhenTransactionIsNoTransac Assert.IsType(flightInfo); } - [Fact] public async Task GetFlightInfoAsync() { @@ -379,7 +378,7 @@ public async Task GetPrimaryKeysAsync() // Arrange var flightDescriptor = FlightDescriptor.CreateCommandDescriptor("test"); var recordBatch = _testUtils.CreateTestBatch(0, 100); - var tableRef = new TableRef { Catalog = "test-catalog", Table = "test-table", DbSchema = "test-schema" }; + var tableRef = new TableRef("test-catalog", "test-schema", "test-table"); var flightHolder = new FlightHolder(flightDescriptor, recordBatch.Schema, _testWebFactory.GetAddress()); _flightStore.Flights.Add(flightDescriptor, flightHolder); @@ -457,7 +456,6 @@ public async Task GetTablesAsync() Assert.Equal(expectedFlightInfo.Endpoints.Count, flightInfo.Endpoints.Count); } - [Fact] public async Task GetCatalogsSchemaAsync() { @@ -558,7 +556,7 @@ public async Task GetExportedKeysAsync() // Arrange var flightDescriptor = FlightDescriptor.CreateCommandDescriptor("test"); var recordBatch = _testUtils.CreateTestBatch(0, 100); - var tableRef = new TableRef { Catalog = "test-catalog", Table = "test-table", DbSchema = "test-schema" }; + var tableRef = new TableRef("test-catalog", "test-schema", "test-table"); var flightHolder = new FlightHolder(flightDescriptor, recordBatch.Schema, _testWebFactory.GetAddress()); _flightStore.Flights.Add(flightDescriptor, flightHolder); @@ -583,7 +581,7 @@ public async Task GetExportedKeysSchemaAsync() _flightStore.Flights.Add(flightDescriptor, flightHolder); // Act - var tableRef = new TableRef { Catalog = "test-catalog", Table = "test-table", DbSchema = "test-schema" }; + var tableRef = new TableRef("test-catalog", "test-schema", "test-table"); var schema = await _flightSqlClient.GetExportedKeysSchemaAsync(tableRef); // Assert @@ -603,7 +601,8 @@ public async Task GetImportedKeysAsync() _flightStore.Flights.Add(flightDescriptor, flightHolder); // Act - var flightInfo = await _flightSqlClient.GetImportedKeysAsync(new TableRef { Catalog = "test-catalog", Table = "test-table", DbSchema = "test-schema" }); + var flightInfo = + await _flightSqlClient.GetImportedKeysAsync(new TableRef("test-catalog", "test-schema", "test-table")); // Assert Assert.NotNull(flightInfo); @@ -646,8 +645,8 @@ public async Task GetCrossReferenceAsync() var recordBatch = _testUtils.CreateTestBatch(0, 100); var flightHolder = new FlightHolder(flightDescriptor, recordBatch.Schema, _testWebFactory.GetAddress()); _flightStore.Flights.Add(flightDescriptor, flightHolder); - var pkTableRef = new TableRef { Catalog = "PKCatalog", DbSchema = "PKSchema", Table = "PKTable" }; - var fkTableRef = new TableRef { Catalog = "FKCatalog", DbSchema = "FKSchema", Table = "FKTable" }; + var pkTableRef = new TableRef("PKCatalog", "PKSchema", "PKTable"); + var fkTableRef = new TableRef("FKCatalog", "FKSchema", "FKTable"); // Act var flightInfo = await _flightSqlClient.GetCrossReferenceAsync(pkTableRef, fkTableRef); @@ -826,7 +825,8 @@ public async Task CancelQueryAsync() var flightInfo = new FlightInfo(schema, flightDescriptor, new List(), 0, 0); // Adding the flight info to the flight store for testing - _flightStore.Flights.Add(flightDescriptor, new FlightHolder(flightDescriptor, schema, _testWebFactory.GetAddress())); + _flightStore.Flights.Add(flightDescriptor, + new FlightHolder(flightDescriptor, schema, _testWebFactory.GetAddress())); // Act var cancelStatus = await _flightSqlClient.CancelQueryAsync(flightInfo); @@ -852,4 +852,4 @@ private void CompareSchemas(Schema expectedSchema, Schema actualSchema) Assert.Equal(expectedField.Metadata, actualField.Metadata); } } -} +} \ No newline at end of file diff --git a/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlPreparedStatementTests.cs b/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlPreparedStatementTests.cs index 637e632640c9b..24647bf16e36d 100644 --- a/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlPreparedStatementTests.cs +++ b/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlPreparedStatementTests.cs @@ -69,7 +69,6 @@ private RecordBatch CreateParameterBatch() }, 3); } - [Fact] public async Task ExecuteAsync_ShouldReturnFlightInfo_WhenValidInputsAreProvided() { diff --git a/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlTestUtils.cs b/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlTestUtils.cs index e0f22d74bbaba..e32cc198aa3ee 100644 --- a/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlTestUtils.cs +++ b/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlTestUtils.cs @@ -43,7 +43,6 @@ public RecordBatch CreateTestBatch(int startValue, int length) return batchBuilder.Build(); } - public FlightInfo GivenStoreBatches(FlightDescriptor flightDescriptor, params RecordBatchWithMetadata[] batches) {