Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(csharp/test/Drivers/Interop/Snowflake): Updated the metadata tests to work without the db name #1352

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions csharp/test/Drivers/Interop/Snowflake/DriverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ public DriverTests()
Dictionary<string, string> options = new Dictionary<string, string>();
_snowflakeDriver = SnowflakeTestingUtils.GetSnowflakeAdbcDriver(_testConfiguration, out parameters);

string databaseName = _testConfiguration.Metadata.Catalog;
ryan-syed marked this conversation as resolved.
Show resolved Hide resolved
string schemaName = _testConfiguration.Metadata.Schema;

parameters[SnowflakeParameters.DATABASE] = databaseName;
parameters[SnowflakeParameters.SCHEMA] = schemaName;

_database = _snowflakeDriver.Open(parameters);
_connection = _database.Connect(options);
}
Expand Down Expand Up @@ -212,7 +206,7 @@ public void CanGetObjectsTables(string tableNamePattern)
string tableName = _testConfiguration.Metadata.Table;

using IArrowArrayStream stream = _connection.GetObjects(
depth: AdbcConnection.GetObjectsDepth.All,
depth: AdbcConnection.GetObjectsDepth.Tables,
catalogPattern: databaseName,
dbSchemaPattern: schemaName,
tableNamePattern: tableNamePattern,
Expand All @@ -233,6 +227,7 @@ public void CanGetObjectsTables(string tableNamePattern)

AdbcTable table = tables.Where((table) => string.Equals(table.Name, tableName)).FirstOrDefault();
Assert.True(table != null, "table should not be null");
Assert.Equal("BASE TABLE", table.Type);
}

/// <summary>
Expand All @@ -258,18 +253,21 @@ public void CanGetObjectsAll()
using RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result;

List<AdbcCatalog> catalogs = GetObjectsParser.ParseCatalog(recordBatch, databaseName, schemaName);

List<AdbcColumn> columns = catalogs
AdbcTable table = catalogs
.Where(c => string.Equals(c.Name, databaseName))
.Select(c => c.DbSchemas)
.FirstOrDefault()
.Where(s => string.Equals(s.Name, schemaName))
.Select(s => s.Tables)
.FirstOrDefault()
.Where(t => string.Equals(t.Name, tableName))
.Select(t => t.Columns)
.FirstOrDefault();


Assert.True(table != null, "table should not be null");
Assert.Equal("BASE TABLE", table.Type);
List<AdbcColumn> columns = table.Columns;

Assert.True(columns != null, "Columns cannot be null");
Assert.Equal(_testConfiguration.Metadata.ExpectedColumnCount, columns.Count);

Expand Down
5 changes: 5 additions & 0 deletions go/adbc/driver/snowflake/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ func (c *cnxn) getDbSchemasMetadata(ctx context.Context, matchingCatalogNames []
var metadataRecords []internal.Metadata
query, queryArgs := prepareDbSchemasSQL(matchingCatalogNames, catalog, dbSchema)
rows, err := c.sqldb.QueryContext(ctx, query, queryArgs...)

if err != nil {
return nil, errToAdbcErr(adbc.StatusIO, err)
}
Expand All @@ -609,6 +610,7 @@ func (c *cnxn) getTablesMetadata(ctx context.Context, matchingCatalogNames []str
metadataRecords := make([]internal.Metadata, 0)
query, queryArgs := prepareTablesSQL(matchingCatalogNames, catalog, dbSchema, tableName, tableType)
rows, err := c.sqldb.QueryContext(ctx, query, queryArgs...)

if err != nil {
return nil, errToAdbcErr(adbc.StatusIO, err)
}
Expand All @@ -628,6 +630,7 @@ func (c *cnxn) getColumnsMetadata(ctx context.Context, matchingCatalogNames []st
metadataRecords := make([]internal.Metadata, 0)
query, queryArgs := prepareColumnsSQL(matchingCatalogNames, catalog, dbSchema, tableName, columnName, tableType)
rows, err := c.sqldb.QueryContext(ctx, query, queryArgs...)

if err != nil {
return nil, errToAdbcErr(adbc.StatusIO, err)
}
Expand Down Expand Up @@ -688,6 +691,7 @@ func prepareDbSchemasSQL(matchingCatalogNames []string, catalog *string, dbSchem

query = `SELECT CATALOG_NAME, SCHEMA_NAME FROM (` + query + `)`
conditions, queryArgs := prepareFilterConditions(adbc.ObjectDepthDBSchemas, catalog, dbSchema, nil, nil, make([]string, 0))

if conditions != "" {
query += " WHERE " + conditions
}
Expand Down Expand Up @@ -737,6 +741,7 @@ func prepareColumnsSQL(matchingCatalogNames []string, catalog *string, dbSchema
character_maximum_length, character_octet_length, datetime_precision, comment FROM (` + prefixQuery + `)`
ordering := ` ORDER BY table_catalog, table_schema, table_name, ordinal_position`
conditions, queryArgs := prepareFilterConditions(adbc.ObjectDepthColumns, catalog, dbSchema, tableName, columnName, tableType)

query := prefixQuery

if conditions != "" {
Expand Down
2 changes: 1 addition & 1 deletion go/adbc/driver/snowflake/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestPrepareDbSchemasSQLWithNoFilterOneCatalog(t *testing.T) {
(
SELECT * FROM "DEMO_DB".INFORMATION_SCHEMA.SCHEMATA
)`

actual, queryArgs := prepareDbSchemasSQL(catalogNames[:], &catalogPattern, &schemaPattern)

println("Query Args", queryArgs)
Expand Down Expand Up @@ -147,7 +148,6 @@ func TestPrepareDbSchemasSQL(t *testing.T) {
}

assert.True(t, areStringsEquivalent(catalogPattern+","+schemaPattern, strings.Join(stringqueryArgs, ",")), "The expected SCHEMA_NAME is not being generated")

assert.True(t, areStringsEquivalent(expected, actual), "The expected SQL query for DbSchemas is not being generated")
}

Expand Down
Loading