You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by cu...@apache.org on 2025/05/27 18:34:32 UTC
(arrow-adbc) branch main updated: feat(csharp/src/Drivers/Databricks): Add configurable multiple catalog support (#2845)
This is an automated email from the ASF dual-hosted git repository.
curth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 4f6c6b348 feat(csharp/src/Drivers/Databricks): Add configurable multiple catalog support (#2845)
4f6c6b348 is described below
commit 4f6c6b34853af12c1b615dd58d53d330b0ec6305
Author: eric-wang-1990 <11...@users.noreply.github.com>
AuthorDate: Tue May 27 11:34:27 2025 -0700
feat(csharp/src/Drivers/Databricks): Add configurable multiple catalog support (#2845)
# Description
This PR adds support for configuring multiple catalog behavior in the C#
Databricks ADBC driver. It introduces a new connection parameter
`adbc.databricks.enable_multiple_catalog_support` that allows users to
control whether the driver should use multiple catalogs or restrict to a
default catalog.
## Proposed Changes
- Add new connection parameter
`adbc.databricks.enable_multiple_catalog_support` to control multiple
catalog behavior
- Implement parameter parsing with support for boolean values and string
values "1"/"0" for compatibility with tools like PowerBI
- Add tests to verify the behavior of metadata queries with different
parameter settings
## How is this tested?
Added unit tests that verify the behavior of metadata queries
(GetSchemas, GetTables) with different settings of the
`CanUseMultipleCatalogs` parameter. Tests confirm that when disabled,
only the default catalog is used, and when enabled, multiple catalogs
can be accessed.
```
---
.../src/Drivers/Databricks/DatabricksConnection.cs | 15 +++-
.../src/Drivers/Databricks/DatabricksParameters.cs | 6 ++
.../Drivers/Databricks/DatabricksConnectionTest.cs | 3 +
.../Databricks/DatabricksTestConfiguration.cs | 3 +
.../Databricks/DatabricksTestEnvironment.cs | 4 ++
csharp/test/Drivers/Databricks/StatementTests.cs | 83 ++++++++++++++++++++++
6 files changed, 113 insertions(+), 1 deletion(-)
diff --git a/csharp/src/Drivers/Databricks/DatabricksConnection.cs b/csharp/src/Drivers/Databricks/DatabricksConnection.cs
index 66b55e1aa..8ea8cd108 100644
--- a/csharp/src/Drivers/Databricks/DatabricksConnection.cs
+++ b/csharp/src/Drivers/Databricks/DatabricksConnection.cs
@@ -39,6 +39,7 @@ namespace Apache.Arrow.Adbc.Drivers.Databricks
{
private bool _applySSPWithQueries = false;
private bool _enableDirectResults = true;
+ private bool _enableMultipleCatalogSupport = true;
internal static TSparkGetDirectResults defaultGetDirectResults = new()
{
@@ -70,6 +71,18 @@ namespace Apache.Arrow.Adbc.Drivers.Databricks
private void ValidateProperties()
{
+ if (Properties.TryGetValue(DatabricksParameters.EnableMultipleCatalogSupport, out string? enableMultipleCatalogSupportStr))
+ {
+ if (bool.TryParse(enableMultipleCatalogSupportStr, out bool enableMultipleCatalogSupportValue))
+ {
+ _enableMultipleCatalogSupport = enableMultipleCatalogSupportValue;
+ }
+ else
+ {
+ throw new ArgumentException($"Parameter '{DatabricksParameters.EnableMultipleCatalogSupport}' value '{enableMultipleCatalogSupportStr}' could not be parsed. Valid values are 'true', 'false'.");
+ }
+ }
+
if (Properties.TryGetValue(DatabricksParameters.ApplySSPWithQueries, out string? applySSPWithQueriesStr))
{
if (bool.TryParse(applySSPWithQueriesStr, out bool applySSPWithQueriesValue))
@@ -316,7 +329,7 @@ namespace Apache.Arrow.Adbc.Drivers.Databricks
{
Client_protocol = TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V7,
Client_protocol_i64 = (long)TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V7,
- CanUseMultipleCatalogs = true,
+ CanUseMultipleCatalogs = _enableMultipleCatalogSupport,
};
// Set default namespace if available
diff --git a/csharp/src/Drivers/Databricks/DatabricksParameters.cs b/csharp/src/Drivers/Databricks/DatabricksParameters.cs
index c5155680d..463e9b211 100644
--- a/csharp/src/Drivers/Databricks/DatabricksParameters.cs
+++ b/csharp/src/Drivers/Databricks/DatabricksParameters.cs
@@ -148,6 +148,12 @@ namespace Apache.Arrow.Adbc.Drivers.Databricks
/// Default value is "sql" if not specified.
/// </summary>
public const string OAuthScope = "adbc.databricks.oauth.scope";
+
+ /// <summary>
+ /// Whether to use multiple catalogs.
+ /// Default value is true if not specified.
+ /// </summary>
+ public const string EnableMultipleCatalogSupport = "adbc.databricks.enable_multiple_catalog_support";
}
/// <summary>
diff --git a/csharp/test/Drivers/Databricks/DatabricksConnectionTest.cs b/csharp/test/Drivers/Databricks/DatabricksConnectionTest.cs
index 22a07f04a..85249512a 100644
--- a/csharp/test/Drivers/Databricks/DatabricksConnectionTest.cs
+++ b/csharp/test/Drivers/Databricks/DatabricksConnectionTest.cs
@@ -317,6 +317,9 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Databricks
Add(new(new() { [SparkParameters.Type] = SparkServerTypeConstants.Http, [SparkParameters.HostName] = "valid.server.com", [AdbcOptions.Username] = "user", [AdbcOptions.Password] = "myPassword", [DatabricksParameters.TemporarilyUnavailableRetry] = "invalid" }, typeof(ArgumentOutOfRangeException)));
Add(new(new() { [SparkParameters.Type] = SparkServerTypeConstants.Http, [SparkParameters.HostName] = "valid.server.com", [AdbcOptions.Username] = "user", [AdbcOptions.Password] = "myPassword", [DatabricksParameters.TemporarilyUnavailableRetryTimeout] = "invalid" }, typeof(ArgumentOutOfRangeException)));
Add(new(new() { [SparkParameters.Type] = SparkServerTypeConstants.Http, [SparkParameters.HostName] = "valid.server.com", [AdbcOptions.Username] = "user", [AdbcOptions.Password] = "myPassword", [DatabricksParameters.TemporarilyUnavailableRetryTimeout] = "-1" }, typeof(ArgumentOutOfRangeException)));
+
+ // Tests for EnableMultipleCatalogSupport parameter
+ Add(new(new() { [SparkParameters.Type] = SparkServerTypeConstants.Http, [SparkParameters.HostName] = "valid.server.com", [AdbcOptions.Username] = "user", [AdbcOptions.Password] = "myPassword", [DatabricksParameters.EnableMultipleCatalogSupport] = "notabool" }, typeof(ArgumentException)));
}
}
diff --git a/csharp/test/Drivers/Databricks/DatabricksTestConfiguration.cs b/csharp/test/Drivers/Databricks/DatabricksTestConfiguration.cs
index 05c3e4a11..ae1a4838e 100644
--- a/csharp/test/Drivers/Databricks/DatabricksTestConfiguration.cs
+++ b/csharp/test/Drivers/Databricks/DatabricksTestConfiguration.cs
@@ -33,5 +33,8 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Databricks
[JsonPropertyName("scope"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string OAuthScope { get; set; } = string.Empty;
+
+ [JsonPropertyName("enableMultipleCatalogSupport")]
+ public string EnableMultipleCatalogSupport { get; set; } = string.Empty;
}
}
diff --git a/csharp/test/Drivers/Databricks/DatabricksTestEnvironment.cs b/csharp/test/Drivers/Databricks/DatabricksTestEnvironment.cs
index ff46a21e1..a2a9ebbf5 100644
--- a/csharp/test/Drivers/Databricks/DatabricksTestEnvironment.cs
+++ b/csharp/test/Drivers/Databricks/DatabricksTestEnvironment.cs
@@ -141,6 +141,10 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Databricks
{
parameters.Add(ApacheParameters.QueryTimeoutSeconds, testConfiguration.QueryTimeoutSeconds!);
}
+ if (!string.IsNullOrEmpty(testConfiguration.EnableMultipleCatalogSupport))
+ {
+ parameters.Add(DatabricksParameters.EnableMultipleCatalogSupport, testConfiguration.EnableMultipleCatalogSupport!);
+ }
if (testConfiguration.HttpOptions != null)
{
if (testConfiguration.HttpOptions.Tls != null)
diff --git a/csharp/test/Drivers/Databricks/StatementTests.cs b/csharp/test/Drivers/Databricks/StatementTests.cs
index bb11db136..994ef6182 100644
--- a/csharp/test/Drivers/Databricks/StatementTests.cs
+++ b/csharp/test/Drivers/Databricks/StatementTests.cs
@@ -479,5 +479,88 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Databricks
Assert.True(batchCount > 1, "Should have read multiple batches");
OutputHelper?.WriteLine($"Successfully read {totalRows} rows in {batchCount} batches after 30 minute delay with {configName}");
}
+
+ [SkippableTheory]
+ [InlineData("true", true)] // Should allow multiple catalogs
+ [InlineData("false", false)] // Should only use default catalog
+ public async Task EnableMultipleCatalogSupportAffectsMetadataQueries(string enableMultipleCatalogSupport, bool shouldAllowMultipleCatalogs)
+ {
+ // Create a connection with the specified EnableMultipleCatalogSupport setting
+ var testConfig = (DatabricksTestConfiguration)TestConfiguration.Clone();
+ testConfig.EnableMultipleCatalogSupport = enableMultipleCatalogSupport;
+ using var connection = NewConnection(testConfig);
+
+ // Test each metadata query type
+ await TestMetadataQuery(connection, "GetSchemas", shouldAllowMultipleCatalogs);
+ await TestMetadataQuery(connection, "GetTables", shouldAllowMultipleCatalogs);
+ }
+
+ private async Task TestMetadataQuery(AdbcConnection connection, string queryType, bool shouldAllowMultipleCatalogs)
+ {
+ OutputHelper?.WriteLine($"Testing {queryType} with EnableMultipleCatalogSupport={shouldAllowMultipleCatalogs}");
+
+ var statement = connection.CreateStatement();
+ statement.SetOption(ApacheParameters.IsMetadataCommand, "true");
+
+ // Do not pass in catalog so it is set to null
+ // Use default as schema name, it is the default schema name
+ statement.SetOption(ApacheParameters.SchemaName, "default");
+ statement.SqlQuery = queryType;
+
+ QueryResult queryResult = await statement.ExecuteQueryAsync();
+ Assert.NotNull(queryResult.Stream);
+
+ int rowCount = 0;
+ HashSet<string> foundCatalogs = new HashSet<string>();
+ string? defaultCatalog = null;
+
+ while (queryResult.Stream != null)
+ {
+ RecordBatch? batch = await queryResult.Stream.ReadNextRecordBatchAsync();
+ if (batch == null) break;
+
+ rowCount += batch.Length;
+
+ // Check catalog values in each row
+ for (int i = 0; i < batch.Length; i++)
+ {
+ for (int j = 0; j < batch.ColumnCount; j++)
+ {
+ if (queryResult.Stream.Schema.FieldsList[j].Name.Equals("TABLE_CATALOG", StringComparison.OrdinalIgnoreCase) ||
+ queryResult.Stream.Schema.FieldsList[j].Name.Equals("TABLE_CAT", StringComparison.OrdinalIgnoreCase))
+ {
+ string? catalog = GetStringValue(batch.Column(j), i);
+ if (!string.IsNullOrEmpty(catalog))
+ {
+ foundCatalogs.Add(catalog);
+ // Store the first catalog we find as the default catalog
+ defaultCatalog ??= catalog;
+ }
+ }
+ }
+ }
+ }
+
+ OutputHelper?.WriteLine($"{queryType} returned {rowCount} rows, found {foundCatalogs.Count} different catalogs: {string.Join(", ", foundCatalogs)}");
+
+ // Verify behavior based on EnableMultipleCatalogSupport setting
+ if (!shouldAllowMultipleCatalogs)
+ {
+ // When EnableMultipleCatalogSupport is false, all results should be from the default catalog, so count should be one
+ Assert.True(foundCatalogs.Count == 1,
+ $"{queryType} should only return results from the default catalog when EnableMultipleCatalogSupport is false");
+ OutputHelper?.WriteLine($"All results are from default catalog: {defaultCatalog}");
+ }
+ else
+ {
+ // When EnableMultipleCatalogSupport is true, we may have results from multiple catalogs
+ Assert.True(foundCatalogs.Count > 1,
+ $"{queryType} should return results from at least one catalog when EnableMultipleCatalogSupport is true");
+ if (foundCatalogs.Count > 1)
+ {
+ OutputHelper?.WriteLine($"Found results from multiple catalogs: {string.Join(", ", foundCatalogs)}");
+ }
+ }
+ }
}
}