From 4fa3bacb94c098749b39daaa7df5d4656a20fdc1 Mon Sep 17 00:00:00 2001 From: Ryan Syed Date: Fri, 24 Nov 2023 14:07:37 -0800 Subject: [PATCH 1/5] fix: fixed compilation error --- csharp/test/Drivers/Snowflake/DriverTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp/test/Drivers/Snowflake/DriverTests.cs b/csharp/test/Drivers/Snowflake/DriverTests.cs index 1d80ce2b59..9d1a7af128 100644 --- a/csharp/test/Drivers/Snowflake/DriverTests.cs +++ b/csharp/test/Drivers/Snowflake/DriverTests.cs @@ -330,9 +330,9 @@ public void CanGetObjectsAll() .FirstOrDefault(); Assert.True(columns != null, "Columns cannot be null"); - Assert.Equal(testConfiguration.Metadata.ExpectedColumnCount, columns.Count); + Assert.Equal(_testConfiguration.Metadata.ExpectedColumnCount, columns.Count); - if (testConfiguration.UseHighPrecision) + if (_testConfiguration.UseHighPrecision) { IEnumerable highPrecisionColumns = columns.Where(c => c.XdbcTypeName == "NUMBER"); From d3cbdf30e0613e34f8f48039918c285557a73e61 Mon Sep 17 00:00:00 2001 From: Ryan Syed Date: Mon, 27 Nov 2023 18:19:32 -0800 Subject: [PATCH 2/5] fix: made GetObjects case insensitive and added tests --- csharp/test/Drivers/Snowflake/DriverTests.cs | 170 +++++++------------ go/adbc/driver/snowflake/connection.go | 4 +- 2 files changed, 60 insertions(+), 114 deletions(-) diff --git a/csharp/test/Drivers/Snowflake/DriverTests.cs b/csharp/test/Drivers/Snowflake/DriverTests.cs index 9d1a7af128..e968a4acec 100644 --- a/csharp/test/Drivers/Snowflake/DriverTests.cs +++ b/csharp/test/Drivers/Snowflake/DriverTests.cs @@ -40,6 +40,41 @@ public class DriverTests : IDisposable readonly AdbcDatabase _database; readonly AdbcConnection _connection; + public static IEnumerable GetPatterns(string name) + { + yield return new object[] { name }; + yield return new object[] { $"{DriverTests.GetPartialNameForPatternMatch(name)}%" }; + yield return new object[] { $"{DriverTests.GetPartialNameForPatternMatch(name).ToLower()}%" }; + yield return new object[] { $"{DriverTests.GetPartialNameForPatternMatch(name).ToUpper()}%" }; + yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name)}%" }; + yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name).ToLower()}%" }; + yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name).ToUpper()}%" }; + } + + public static IEnumerable CatalogNamePatternData() + { + Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); + SnowflakeTestConfiguration testConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); + string databaseName = testConfiguration.Metadata.Catalog; + return GetPatterns(databaseName); + } + + public static IEnumerable DbSchemasNamePatternData() + { + Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); + SnowflakeTestConfiguration testConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); + string dbSchemaName = testConfiguration.Metadata.Schema; + return GetPatterns(dbSchemaName); + } + + public static IEnumerable TableNamePatternData() + { + Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); + SnowflakeTestConfiguration testConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); + string tableName = testConfiguration.Metadata.Table; + return GetPatterns(tableName); + } + public DriverTests() { Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); @@ -110,46 +145,19 @@ public void CanGetInfo() } } - /// - /// Validates if the driver can call GetObjects with GetObjectsDepth as Catalogs. - /// - [SkippableFact, Order(3)] - public void CanGetObjectsCatalogs() - { - string databaseName = _testConfiguration.Metadata.Catalog; - - using IArrowArrayStream stream = _connection.GetObjects( - depth: AdbcConnection.GetObjectsDepth.Catalogs, - catalogPattern: databaseName, - dbSchemaPattern: null, - tableNamePattern: null, - tableTypes: new List { "BASE TABLE", "VIEW" }, - columnNamePattern: null); - - using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result; - - List catalogs = GetObjectsParser.ParseCatalog(recordBatch, databaseName, null); - - AdbcCatalog catalog = catalogs.FirstOrDefault(); - - Assert.True(catalog != null, "catalog should not be null"); - Assert.Equal(databaseName, catalog.Name); - } - /// /// Validates if the driver can call GetObjects with GetObjectsDepth as Catalogs and CatalogName passed as a pattern. /// - [SkippableFact, Order(3)] - public void CanGetObjectsCatalogsWithPattern() + [SkippableTheory, Order(3)] + [MemberData(nameof(CatalogNamePatternData))] + public void CanGetObjectsCatalogs(string catalogPattern) { string databaseName = _testConfiguration.Metadata.Catalog; string schemaName = _testConfiguration.Metadata.Schema; - string partialDatabaseName = GetPartialNameForPatternMatch(databaseName); - using IArrowArrayStream stream = _connection.GetObjects( depth: AdbcConnection.GetObjectsDepth.Catalogs, - catalogPattern: $"{partialDatabaseName}%", + catalogPattern: catalogPattern, dbSchemaPattern: null, tableNamePattern: null, tableTypes: new List { "BASE TABLE", "VIEW" }, @@ -158,59 +166,26 @@ public void CanGetObjectsCatalogsWithPattern() using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result; List catalogs = GetObjectsParser.ParseCatalog(recordBatch, databaseName, null); - - AdbcCatalog catalog = catalogs.FirstOrDefault(); + AdbcCatalog catalog = catalogs.Where((catalog) => string.Equals(catalog.Name, databaseName)).FirstOrDefault(); Assert.True(catalog != null, "catalog should not be null"); - Assert.StartsWith(databaseName, catalog.Name); - } - - /// - /// Validates if the driver can call GetObjects with GetObjectsDepth as DbSchemas. - /// - [SkippableFact, Order(3)] - public void CanGetObjectsDbSchemas() - { - // need to add the database - string databaseName = _testConfiguration.Metadata.Catalog; - string schemaName = _testConfiguration.Metadata.Schema; - - using IArrowArrayStream stream = _connection.GetObjects( - depth: AdbcConnection.GetObjectsDepth.DbSchemas, - catalogPattern: databaseName, - dbSchemaPattern: schemaName, - tableNamePattern: null, - tableTypes: new List { "BASE TABLE", "VIEW" }, - columnNamePattern: null); - - using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result; - - List catalogs = GetObjectsParser.ParseCatalog(recordBatch, databaseName, schemaName); - - List dbSchemas = catalogs - .Select(s => s.DbSchemas) - .FirstOrDefault(); - AdbcDbSchema dbSchema = dbSchemas.FirstOrDefault(); - - Assert.True(dbSchema != null, "dbSchema should not be null"); - Assert.Equal(schemaName, dbSchema.Name); } /// /// Validates if the driver can call GetObjects with GetObjectsDepth as DbSchemas with DbSchemaName as a pattern. /// - [SkippableFact, Order(3)] - public void CanGetObjectsDbSchemasWithPattern() + [SkippableTheory, Order(3)] + [MemberData(nameof(DbSchemasNamePatternData))] + public void CanGetObjectsDbSchemas(string dbSchemaPattern) { // need to add the database string databaseName = _testConfiguration.Metadata.Catalog; string schemaName = _testConfiguration.Metadata.Schema; - string partialSchemaName = GetPartialNameForPatternMatch(schemaName); using IArrowArrayStream stream = _connection.GetObjects( depth: AdbcConnection.GetObjectsDepth.DbSchemas, catalogPattern: databaseName, - dbSchemaPattern: $"{partialSchemaName}%", + dbSchemaPattern: dbSchemaPattern, tableNamePattern: null, tableTypes: new List { "BASE TABLE", "VIEW" }, columnNamePattern: null); @@ -222,63 +197,28 @@ public void CanGetObjectsDbSchemasWithPattern() List dbSchemas = catalogs .Select(s => s.DbSchemas) .FirstOrDefault(); - AdbcDbSchema dbSchema = dbSchemas.FirstOrDefault(); + AdbcDbSchema dbSchema = dbSchemas.Where((dbSchema) => string.Equals(dbSchema.Name, schemaName)).FirstOrDefault(); Assert.True(dbSchema != null, "dbSchema should not be null"); - Assert.StartsWith(partialSchemaName, dbSchema.Name); - } - - /// - /// Validates if the driver can call GetObjects with GetObjectsDepth as Tables. - /// - [SkippableFact, Order(3)] - public void CanGetObjectsTables() - { - // need to add the database - string databaseName = _testConfiguration.Metadata.Catalog; - string schemaName = _testConfiguration.Metadata.Schema; - string tableName = _testConfiguration.Metadata.Table; - - using IArrowArrayStream stream = _connection.GetObjects( - depth: AdbcConnection.GetObjectsDepth.All, - catalogPattern: databaseName, - dbSchemaPattern: schemaName, - tableNamePattern: tableName, - tableTypes: new List { "BASE TABLE", "VIEW" }, - columnNamePattern: null); - - using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result; - - List catalogs = GetObjectsParser.ParseCatalog(recordBatch, databaseName, schemaName); - - List tables = catalogs - .Select(s => s.DbSchemas) - .FirstOrDefault() - .Select(t => t.Tables) - .FirstOrDefault(); - AdbcTable table = tables.FirstOrDefault(); - - Assert.True(table != null, "table should not be null"); - Assert.Equal(tableName, table.Name); } /// /// Validates if the driver can call GetObjects with GetObjectsDepth as Tables with TableName as a pattern. /// - [SkippableFact, Order(3)] - public void CanGetObjectsTablesWithPattern() + [SkippableTheory, Order(3)] + [MemberData(nameof(TableNamePatternData))] + public void CanGetObjectsTables(string tableNamePattern) { // need to add the database string databaseName = _testConfiguration.Metadata.Catalog; string schemaName = _testConfiguration.Metadata.Schema; string tableName = _testConfiguration.Metadata.Table; - string partialTableName = GetPartialNameForPatternMatch(tableName); using IArrowArrayStream stream = _connection.GetObjects( depth: AdbcConnection.GetObjectsDepth.All, catalogPattern: databaseName, dbSchemaPattern: schemaName, - tableNamePattern: $"{partialTableName}%", + tableNamePattern: tableNamePattern, tableTypes: new List { "BASE TABLE", "VIEW" }, columnNamePattern: null); @@ -291,10 +231,9 @@ public void CanGetObjectsTablesWithPattern() .FirstOrDefault() .Select(t => t.Tables) .FirstOrDefault(); - AdbcTable table = tables.FirstOrDefault(); + AdbcTable table = tables.Where((table) => string.Equals(table.Name, tableName)).FirstOrDefault(); Assert.True(table != null, "table should not be null"); - Assert.StartsWith(partialTableName, table.Name); } /// @@ -411,13 +350,20 @@ public void CanExecuteQuery() Tests.DriverTests.CanExecuteQuery(queryResult, _testConfiguration.ExpectedResultsCount); } - private string GetPartialNameForPatternMatch(string name) + private static string GetPartialNameForPatternMatch(string name) { if (string.IsNullOrEmpty(name) || name.Length == 1) return name; return name.Substring(0, name.Length / 2); } + private static string GetNameWithoutFirstChatacter(string name) + { + if (string.IsNullOrEmpty(name)) return name; + + return name.Substring(1); + } + public void Dispose() { _connection.Dispose(); diff --git a/go/adbc/driver/snowflake/connection.go b/go/adbc/driver/snowflake/connection.go index 1b2d72ef70..e96799933f 100644 --- a/go/adbc/driver/snowflake/connection.go +++ b/go/adbc/driver/snowflake/connection.go @@ -282,10 +282,10 @@ func (c *cnxn) getObjectsDbSchemas(ctx context.Context, depth adbc.ObjectDepth, conditions := make([]string, 0) if catalog != nil && *catalog != "" { - conditions = append(conditions, ` CATALOG_NAME LIKE '`+*catalog+`'`) + conditions = append(conditions, ` CATALOG_NAME ILIKE '`+*catalog+`'`) } if dbSchema != nil && *dbSchema != "" { - conditions = append(conditions, ` SCHEMA_NAME LIKE '`+*dbSchema+`'`) + conditions = append(conditions, ` SCHEMA_NAME ILIKE '`+*dbSchema+`'`) } cond := strings.Join(conditions, " AND ") From 59afbcb4708a40bac50f5e5b2fd5044ec2fbc45d Mon Sep 17 00:00:00 2001 From: Ryan Syed Date: Tue, 28 Nov 2023 11:56:50 -0800 Subject: [PATCH 3/5] fix: removed % for tests where _ is used for pattern match --- csharp/test/Drivers/Snowflake/DriverTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csharp/test/Drivers/Snowflake/DriverTests.cs b/csharp/test/Drivers/Snowflake/DriverTests.cs index e968a4acec..ea0171b745 100644 --- a/csharp/test/Drivers/Snowflake/DriverTests.cs +++ b/csharp/test/Drivers/Snowflake/DriverTests.cs @@ -46,9 +46,9 @@ public static IEnumerable GetPatterns(string name) yield return new object[] { $"{DriverTests.GetPartialNameForPatternMatch(name)}%" }; yield return new object[] { $"{DriverTests.GetPartialNameForPatternMatch(name).ToLower()}%" }; yield return new object[] { $"{DriverTests.GetPartialNameForPatternMatch(name).ToUpper()}%" }; - yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name)}%" }; - yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name).ToLower()}%" }; - yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name).ToUpper()}%" }; + yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name)}" }; + yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name).ToLower()}" }; + yield return new object[] { $"_{DriverTests.GetNameWithoutFirstChatacter(name).ToUpper()}" }; } public static IEnumerable CatalogNamePatternData() From 64e946726dc13fba6062e8f3db728f5ff1cecba5 Mon Sep 17 00:00:00 2001 From: Ryan Syed Date: Tue, 28 Nov 2023 15:48:18 -0800 Subject: [PATCH 4/5] fix: Moved TestConfiguration initialization to SnowflakeTestingUtils and added Skip capability for ValueTests TestConfiguration is now a part of SnowflakeTestingUtils, and can be used across the tests (no redundant reading the configuration) ValueTests were marked as Theory, changed them to SkippableTheory to skip the tests, if a XUnit.SkipException is thrown --- csharp/test/Drivers/Snowflake/DriverTests.cs | 11 ++++------ .../Snowflake/SnowflakeTestingUtils.cs | 9 ++++++++ csharp/test/Drivers/Snowflake/ValueTests.cs | 22 +++++++++---------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/csharp/test/Drivers/Snowflake/DriverTests.cs b/csharp/test/Drivers/Snowflake/DriverTests.cs index ea0171b745..ba83637009 100644 --- a/csharp/test/Drivers/Snowflake/DriverTests.cs +++ b/csharp/test/Drivers/Snowflake/DriverTests.cs @@ -54,31 +54,28 @@ public static IEnumerable GetPatterns(string name) public static IEnumerable CatalogNamePatternData() { Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); - SnowflakeTestConfiguration testConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); - string databaseName = testConfiguration.Metadata.Catalog; + string databaseName = SnowflakeTestingUtils.TestConfiguration?.Metadata.Catalog; return GetPatterns(databaseName); } public static IEnumerable DbSchemasNamePatternData() { Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); - SnowflakeTestConfiguration testConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); - string dbSchemaName = testConfiguration.Metadata.Schema; + string dbSchemaName = SnowflakeTestingUtils.TestConfiguration?.Metadata.Schema; return GetPatterns(dbSchemaName); } public static IEnumerable TableNamePatternData() { Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); - SnowflakeTestConfiguration testConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); - string tableName = testConfiguration.Metadata.Table; + string tableName = SnowflakeTestingUtils.TestConfiguration?.Metadata.Table; return GetPatterns(tableName); } public DriverTests() { Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); - _testConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); + _testConfiguration = SnowflakeTestingUtils.TestConfiguration; Dictionary parameters = new Dictionary(); Dictionary options = new Dictionary(); diff --git a/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs b/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs index 0da3eff777..0169b6bbad 100644 --- a/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs +++ b/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs @@ -20,6 +20,7 @@ using System.Linq; using System.Text; using Apache.Arrow.Adbc.C; +using Xunit; namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake { @@ -40,8 +41,16 @@ internal class SnowflakeParameters internal class SnowflakeTestingUtils { + internal static readonly SnowflakeTestConfiguration TestConfiguration; + internal const string SNOWFLAKE_TEST_CONFIG_VARIABLE = "SNOWFLAKE_TEST_CONFIG_FILE"; + static SnowflakeTestingUtils() + { + Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); + TestConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); + } + /// /// Gets a the Snowflake ADBC driver with settings from the /// . diff --git a/csharp/test/Drivers/Snowflake/ValueTests.cs b/csharp/test/Drivers/Snowflake/ValueTests.cs index 84b4af8466..511a46d1d6 100644 --- a/csharp/test/Drivers/Snowflake/ValueTests.cs +++ b/csharp/test/Drivers/Snowflake/ValueTests.cs @@ -41,7 +41,7 @@ public class ValueTests : IDisposable public ValueTests() { Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); - _snowflakeTestConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); + _snowflakeTestConfiguration = SnowflakeTestingUtils.TestConfiguration; Dictionary parameters = new Dictionary(); Dictionary options = new Dictionary(); AdbcDriver snowflakeDriver = SnowflakeTestingUtils.GetSnowflakeAdbcDriver(_snowflakeTestConfiguration, out parameters); @@ -55,7 +55,7 @@ public ValueTests() /// Validates if driver can send and receive specific Integer values correctly /// These Snowflake types are equivalent: NUMBER(38,0),INT,INTEGER,BIGINT,SMALLINT,TINYINT,BYTEINT /// - [Theory] + [SkippableTheory] [InlineData(-1)] [InlineData(0)] [InlineData(1)] @@ -69,7 +69,7 @@ public void TestIntegerSanity(int value) /// /// Validates if driver can handle the largest / smallest numbers /// - [Theory] + [SkippableTheory] [InlineData("99999999999999999999999999999999999999")] [InlineData("-99999999999999999999999999999999999999")] public void TestIntegerMinMax(string value) @@ -82,7 +82,7 @@ public void TestIntegerMinMax(string value) /// /// Validates if driver can handle smaller Number type correctly /// - [Theory] + [SkippableTheory] [InlineData(-1)] [InlineData(0)] [InlineData(1)] @@ -98,7 +98,7 @@ public void TestSmallNumberRange(int value) /// /// Validates if driver correctly errors out when the values exceed the column's limit /// - [Theory] + [SkippableTheory] [InlineData(-100)] [InlineData(100)] [InlineData(int.MaxValue)] @@ -113,7 +113,7 @@ public void TestSmallNumberRangeOverlimit(int value) /// /// Validates if driver can handle a large scale Number type correctly /// - [Theory] + [SkippableTheory] [InlineData("0")] [InlineData("-2.003")] [InlineData("4.85")] @@ -129,7 +129,7 @@ public void TestLargeScaleNumberRange(string value) /// /// Validates if driver can error handle when input goes beyond a large scale Number type /// - [Theory] + [SkippableTheory] [InlineData("-10")] [InlineData("10")] [InlineData("99999999999999999999999999999999999999")] @@ -144,7 +144,7 @@ public void TestLargeScaleNumberOverlimit(string value) /// /// Validates if driver can handle a small scale Number type correctly /// - [Theory] + [SkippableTheory] [InlineData("0")] [InlineData("4.85")] [InlineData("-999999999999999999999999999999999999.99")] @@ -159,7 +159,7 @@ public void TestSmallScaleNumberRange(string value) /// /// Validates if driver can error handle when an insert goes beyond a small scale Number type correctly /// - [Theory] + [SkippableTheory] [InlineData("-99999999999999999999999999999999999999")] [InlineData("99999999999999999999999999999999999999")] public void TestSmallScaleNumberOverlimit(string value) @@ -174,7 +174,7 @@ public void TestSmallScaleNumberOverlimit(string value) /// Tests that decimals are rounded as expected. /// Snowflake allows inserts of scales beyond the data type size, but storage of value will round it up or down /// - [Theory] + [SkippableTheory] [InlineData(2.467, 2.47)] [InlineData(-672.613, -672.61)] public void TestRoundingNumbers(decimal input, decimal output) @@ -192,7 +192,7 @@ public void TestRoundingNumbers(decimal input, decimal output) /// Validates if driver can handle floating point number type correctly /// These Snowflake types are equivalent: FLOAT,FLOAT4,FLOAT8,DOUBLE,DOUBLE PRECISION,REAL /// - [Theory] + [SkippableTheory] [InlineData(0)] [InlineData(0.2)] [InlineData(15e-03)] From d84d8227b5c7814257cecd47ab340ff2158a3d16 Mon Sep 17 00:00:00 2001 From: Ryan Syed Date: Fri, 1 Dec 2023 13:41:40 -0800 Subject: [PATCH 5/5] fix: Removed unecessary Skip checks and some refactoring Refactoring includes being able to match the exact catalog, schema, and table names when wild cards are involved in the name indentifiers of the GetObjects patterns For example: A pattern name like FOO_BAR will match against FOO1BAR and FOOABAR. Similarly FOO%BAR will match with foohellobar, FOObyeBAR etc.. Therefore it is essential to filter out the returned matches with the expected name identifiers. Similar checks would have to be added by authors using the Driver when calling the GetObjects API. --- csharp/test/Drivers/Snowflake/DriverTests.cs | 33 +++++++++++-------- .../Snowflake/SnowflakeTestingUtils.cs | 19 +++++++---- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/csharp/test/Drivers/Snowflake/DriverTests.cs b/csharp/test/Drivers/Snowflake/DriverTests.cs index ba83637009..ea3574fca2 100644 --- a/csharp/test/Drivers/Snowflake/DriverTests.cs +++ b/csharp/test/Drivers/Snowflake/DriverTests.cs @@ -39,9 +39,12 @@ public class DriverTests : IDisposable readonly AdbcDriver _snowflakeDriver; readonly AdbcDatabase _database; readonly AdbcConnection _connection; + readonly List _tableTypes; public static IEnumerable GetPatterns(string name) { + if (string.IsNullOrEmpty(name)) yield break; + yield return new object[] { name }; yield return new object[] { $"{DriverTests.GetPartialNameForPatternMatch(name)}%" }; yield return new object[] { $"{DriverTests.GetPartialNameForPatternMatch(name).ToLower()}%" }; @@ -53,21 +56,18 @@ public static IEnumerable GetPatterns(string name) public static IEnumerable CatalogNamePatternData() { - Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); string databaseName = SnowflakeTestingUtils.TestConfiguration?.Metadata.Catalog; return GetPatterns(databaseName); } public static IEnumerable DbSchemasNamePatternData() { - Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); string dbSchemaName = SnowflakeTestingUtils.TestConfiguration?.Metadata.Schema; return GetPatterns(dbSchemaName); } public static IEnumerable TableNamePatternData() { - Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); string tableName = SnowflakeTestingUtils.TestConfiguration?.Metadata.Table; return GetPatterns(tableName); } @@ -77,6 +77,7 @@ public DriverTests() Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); _testConfiguration = SnowflakeTestingUtils.TestConfiguration; + _tableTypes = new List { "BASE TABLE", "VIEW" }; Dictionary parameters = new Dictionary(); Dictionary options = new Dictionary(); _snowflakeDriver = SnowflakeTestingUtils.GetSnowflakeAdbcDriver(_testConfiguration, out parameters); @@ -157,7 +158,7 @@ public void CanGetObjectsCatalogs(string catalogPattern) catalogPattern: catalogPattern, dbSchemaPattern: null, tableNamePattern: null, - tableTypes: new List { "BASE TABLE", "VIEW" }, + tableTypes: _tableTypes, columnNamePattern: null); using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result; @@ -184,7 +185,7 @@ public void CanGetObjectsDbSchemas(string dbSchemaPattern) catalogPattern: databaseName, dbSchemaPattern: dbSchemaPattern, tableNamePattern: null, - tableTypes: new List { "BASE TABLE", "VIEW" }, + tableTypes: _tableTypes, columnNamePattern: null); using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result; @@ -192,7 +193,8 @@ public void CanGetObjectsDbSchemas(string dbSchemaPattern) List catalogs = GetObjectsParser.ParseCatalog(recordBatch, databaseName, schemaName); List dbSchemas = catalogs - .Select(s => s.DbSchemas) + .Where(c => string.Equals(c.Name, databaseName)) + .Select(c => c.DbSchemas) .FirstOrDefault(); AdbcDbSchema dbSchema = dbSchemas.Where((dbSchema) => string.Equals(dbSchema.Name, schemaName)).FirstOrDefault(); @@ -216,7 +218,7 @@ public void CanGetObjectsTables(string tableNamePattern) catalogPattern: databaseName, dbSchemaPattern: schemaName, tableNamePattern: tableNamePattern, - tableTypes: new List { "BASE TABLE", "VIEW" }, + tableTypes: _tableTypes, columnNamePattern: null); using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result; @@ -224,9 +226,11 @@ public void CanGetObjectsTables(string tableNamePattern) List catalogs = GetObjectsParser.ParseCatalog(recordBatch, databaseName, schemaName); List tables = catalogs - .Select(s => s.DbSchemas) + .Where(c => string.Equals(c.Name, databaseName)) + .Select(c => c.DbSchemas) .FirstOrDefault() - .Select(t => t.Tables) + .Where(s => string.Equals(s.Name, schemaName)) + .Select(s => s.Tables) .FirstOrDefault(); AdbcTable table = tables.Where((table) => string.Equals(table.Name, tableName)).FirstOrDefault(); @@ -250,7 +254,7 @@ public void CanGetObjectsAll() catalogPattern: databaseName, dbSchemaPattern: schemaName, tableNamePattern: tableName, - tableTypes: new List { "BASE TABLE", "VIEW" }, + tableTypes: _tableTypes, columnNamePattern: columnName); using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result; @@ -258,11 +262,14 @@ public void CanGetObjectsAll() List catalogs = GetObjectsParser.ParseCatalog(recordBatch, databaseName, schemaName); List columns = catalogs - .Select(s => s.DbSchemas) + .Where(c => string.Equals(c.Name, databaseName)) + .Select(c => c.DbSchemas) .FirstOrDefault() - .Select(t => t.Tables) + .Where(s => string.Equals(s.Name, schemaName)) + .Select(s => s.Tables) .FirstOrDefault() - .Select(c => c.Columns) + .Where(t => string.Equals(t.Name, tableName)) + .Select(t => t.Columns) .FirstOrDefault(); Assert.True(columns != null, "Columns cannot be null"); diff --git a/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs b/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs index 0169b6bbad..18fcafb65f 100644 --- a/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs +++ b/csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs @@ -15,6 +15,7 @@ * limitations under the License. */ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -47,8 +48,14 @@ internal class SnowflakeTestingUtils static SnowflakeTestingUtils() { - Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE)); - TestConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); + try + { + TestConfiguration = Utils.LoadTestConfiguration(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE); + } + catch (InvalidOperationException ex) + { + Console.WriteLine(ex.Message); + } } /// @@ -75,12 +82,12 @@ out Dictionary parameters { SnowflakeParameters.USE_HIGH_PRECISION, testConfiguration.UseHighPrecision.ToString().ToLowerInvariant() } }; - if(!string.IsNullOrWhiteSpace(testConfiguration.Host)) + if (!string.IsNullOrWhiteSpace(testConfiguration.Host)) { parameters[SnowflakeParameters.HOST] = testConfiguration.Host; } - if(!string.IsNullOrWhiteSpace(testConfiguration.Database)) + if (!string.IsNullOrWhiteSpace(testConfiguration.Database)) { parameters[SnowflakeParameters.DATABASE] = testConfiguration.Database; } @@ -129,9 +136,9 @@ internal static string[] GetQueries(SnowflakeTestConfiguration testConfiguration { string modifiedLine = line; - foreach(string key in placeholderValues.Keys) + foreach (string key in placeholderValues.Keys) { - if(modifiedLine.Contains(key)) + if (modifiedLine.Contains(key)) modifiedLine = modifiedLine.Replace(key, placeholderValues[key]); }