Skip to content

Commit 6444fd7

Browse files
dandandanliu915Dan Liu
andauthored
fix(csharp/src/Drivers): Make AdbcCommandTimeoutProperty to optional (#4197)
Previously, setting CommandTimeout required AdbcCommandTimeoutProperty to be set first, throwing InvalidOperationException if it was not, specifically in Snowflake's case. Now, AdbcCommandTimeoutProperty is nullable and CommandTimeout stores the value locally when no driver property is configured, only propagating to the driver via SetOption when the property is set. Fixed previous PR: #2312 Co-authored-by: Dan Liu <liudan7@microsoft.com>
1 parent 125fd83 commit 6444fd7

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

csharp/src/Client/AdbcCommand.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,12 @@ public override CommandType CommandType
129129

130130
/// <summary>
131131
/// Gets or sets the name of the command timeout property for the underlying ADBC driver.
132+
/// When set, <see cref="CommandTimeout"/> will propagate the value to the driver via this property.
133+
/// When not set, <see cref="CommandTimeout"/> only stores the value locally.
132134
/// </summary>
133-
public string AdbcCommandTimeoutProperty
135+
public string? AdbcCommandTimeoutProperty
134136
{
135-
get
136-
{
137-
if (string.IsNullOrEmpty(_commandTimeoutProperty))
138-
throw new InvalidOperationException("CommandTimeoutProperty is not set.");
139-
140-
return _commandTimeoutProperty!;
141-
}
137+
get => _commandTimeoutProperty;
142138
set => _commandTimeoutProperty = value;
143139
}
144140

@@ -147,9 +143,11 @@ public override int CommandTimeout
147143
get => _timeout;
148144
set
149145
{
150-
// ensures the property exists before setting the CommandTimeout value
151-
string property = AdbcCommandTimeoutProperty;
152-
_adbcStatement.SetOption(property, value.ToString(CultureInfo.InvariantCulture));
146+
// if the driver property is set, propagate the timeout value to the driver
147+
if (!string.IsNullOrEmpty(_commandTimeoutProperty))
148+
{
149+
_adbcStatement.SetOption(_commandTimeoutProperty!, value.ToString(CultureInfo.InvariantCulture));
150+
}
153151
_timeout = value;
154152
}
155153
}

csharp/test/Apache.Arrow.Adbc.Tests/Client/ClientTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,12 @@ internal void TestConnectionStringParsing(ConnectionStringExample connectionStri
221221

222222
if (!string.IsNullOrEmpty(connectionStringExample.CommandTimeoutProperty))
223223
{
224-
Assert.True(cmd.AdbcCommandTimeoutProperty == connectionStringExample.CommandTimeoutProperty);
225-
Assert.True(cmd.CommandTimeout == connectionStringExample.CommandTimeout);
224+
Assert.Equal(connectionStringExample.CommandTimeoutProperty, cmd.AdbcCommandTimeoutProperty);
225+
Assert.Equal(connectionStringExample.CommandTimeout, cmd.CommandTimeout);
226226
}
227227
else
228228
{
229-
Assert.Throws<InvalidOperationException>(() => cmd.AdbcCommandTimeoutProperty);
229+
Assert.Null(cmd.AdbcCommandTimeoutProperty);
230230
}
231231
}
232232
}

0 commit comments

Comments
 (0)