Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Bumped `commons-compress` dependency to latest (1.28.0) to address CVE-2024-25710 and CVE-2024-26308 (snowflakedb/snowflake-jdbc#2538)
- Add SLF4J bridge from shaded dependencies to `SFLogger` (snowflakedb/snowflake-jdbc#2543)
- Fixed proxy authentication when connecting to GCP (snowflakedb/snowflake-jdbc#2540)
- Fixed bug where called-provided schema was ignored in getStreams()

- v4.0.1
- Add /etc/os-release data to Minicore telemetry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2948,9 +2948,7 @@ public ResultSet getStreams(
return SnowflakeDatabaseMetaDataResultSet.getEmptyResultSet(GET_STREAMS, statement);
} else {
String schemaUnescaped = isExactSchema ? schemaPattern : unescapeChars(schemaPattern);
if (streamName == null || Wildcard.isWildcardPatternStr(streamName)) {
showStreamsCommand += " in schema \"" + catalogEscaped + "\".\"" + schemaUnescaped + "\"";
}
showStreamsCommand += " in schema \"" + catalogEscaped + "\".\"" + schemaUnescaped + "\"";
Comment thread
sfc-gh-dheyman marked this conversation as resolved.
}
}

Expand All @@ -2970,25 +2968,23 @@ public boolean next() throws SQLException {
// iterate throw the show streams result until we find an entry
// that matches the stream name
while (showObjectResultSet.next()) {
String name = showObjectResultSet.getString(2);
String databaseName = showObjectResultSet.getString(3);
String schemaName = showObjectResultSet.getString(4);
String owner = showObjectResultSet.getString(5);
String comment = showObjectResultSet.getString(6);
String tableName = showObjectResultSet.getString(7);
String sourceType = showObjectResultSet.getString(8);
String baseTables = showObjectResultSet.getString(9);
String type = showObjectResultSet.getString(10);
String stale = showObjectResultSet.getString(11);
String mode = showObjectResultSet.getString(12);
String name = showObjectResultSet.getString("name");
String databaseName = showObjectResultSet.getString("database_name");
String schemaName = showObjectResultSet.getString("schema_name");
String owner = showObjectResultSet.getString("owner");
String comment = showObjectResultSet.getString("comment");
String tableName = showObjectResultSet.getString("table_name");
String sourceType = showObjectResultSet.getString("source_type");
String baseTables = showObjectResultSet.getString("base_tables");
String type = showObjectResultSet.getString("type");
String stale = showObjectResultSet.getString("stale");
String mode = showObjectResultSet.getString("mode");

if ((compiledStreamNamePattern == null
|| compiledStreamNamePattern.matcher(streamName).matches())
|| compiledStreamNamePattern.matcher(name).matches())
Comment thread
sfc-gh-dheyman marked this conversation as resolved.
&& (compiledSchemaPattern == null
|| compiledSchemaPattern.matcher(schemaName).matches())
&& (compiledStreamNamePattern == null
|| compiledStreamNamePattern.matcher(streamName).matches())) {
logger.debug("Found a matched column:" + tableName + "." + streamName);
|| compiledSchemaPattern.matcher(schemaName).matches())) {
logger.debug("Found a matched stream:" + schemaName + "." + name);
nextRow[0] = name;
nextRow[1] = databaseName;
nextRow[2] = schemaName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
Expand All @@ -39,6 +40,12 @@ public class BaseJDBCTest extends AbstractDriverIT {
// Test UUID unique per session
static final String TEST_UUID = UUID.randomUUID().toString();

protected static Connection getConnectionWithWildcardsDisabled() throws SQLException {
Properties props = new Properties();
props.put("ENABLE_WILDCARDS_IN_SHOW_METADATA_COMMANDS", "false");
return getConnection(props);
}

protected interface MethodRaisesSQLException {
void run() throws SQLException;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.sql.DatabaseMetaData.procedureReturnsResult;
import static java.sql.ResultSetMetaData.columnNullableUnknown;
import static net.snowflake.client.TestUtil.escapeUnderscore;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
Expand Down Expand Up @@ -33,11 +32,12 @@
import net.snowflake.client.category.TestTags;
import net.snowflake.client.internal.jdbc.util.SnowflakeTypeHelper;
import net.snowflake.client.internal.jdbc.util.SnowflakeTypeUtil;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/** Database Metadata IT */
@Tag(TestTags.OTHERS)
@Tag(TestTags.DATABASE_META_DATA)
public class DatabaseMetaDataIT extends BaseJDBCWithSharedConnectionIT {
private static final Pattern VERSION_PATTERN =
Pattern.compile("^(\\d+)\\.(\\d+)(?:\\.\\d+)+\\s*.*");
Expand Down Expand Up @@ -123,36 +123,39 @@ public void testGetCatalogs() throws SQLException {

@Test
public void testGetSchemas() throws Throwable {
// CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX = false
DatabaseMetaData metaData = connection.getMetaData();
String currentSchema = connection.getSchema();
assertEquals("schema", metaData.getSchemaTerm());
Set<String> schemas = new HashSet<>();
try (ResultSet resultSet = metaData.getSchemas()) {
verifyResultSetMetaDataColumns(resultSet, DBMetadataResultSetMetadata.GET_SCHEMAS);
while (resultSet.next()) {
String schema = resultSet.getString(1);
if (currentSchema.equals(schema) || !TestUtil.isSchemaGeneratedInTests(schema)) {
schemas.add(schema);
try (Connection conn = getConnectionWithWildcardsDisabled()) {
// CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX = false
DatabaseMetaData metaData = conn.getMetaData();
String currentSchema = conn.getSchema();
assertEquals("schema", metaData.getSchemaTerm());
Set<String> schemas = new HashSet<>();
try (ResultSet resultSet = metaData.getSchemas()) {
verifyResultSetMetaDataColumns(resultSet, DBMetadataResultSetMetadata.GET_SCHEMAS);
while (resultSet.next()) {
String schema = resultSet.getString(1);
if (currentSchema.equals(schema) || !TestUtil.isSchemaGeneratedInTests(schema)) {
schemas.add(schema);
}
}
}
}
assertThat(schemas.size(), greaterThanOrEqualTo(1));
assertThat(schemas.size(), greaterThanOrEqualTo(1));

Set<String> schemasInDb = new HashSet<>();
try (ResultSet resultSet = metaData.getSchemas(connection.getCatalog(), "%")) {
while (resultSet.next()) {
String schema = resultSet.getString(1);
if (currentSchema.equals(schema) || !TestUtil.isSchemaGeneratedInTests(schema)) {
schemasInDb.add(schema);
Set<String> schemasInDb = new HashSet<>();
try (ResultSet resultSet = metaData.getSchemas(conn.getCatalog(), "%")) {
while (resultSet.next()) {
String schema = resultSet.getString(1);
if (currentSchema.equals(schema) || !TestUtil.isSchemaGeneratedInTests(schema)) {
schemasInDb.add(schema);
}
}
}
Assumptions.assumeFalse(
schemasInDb.isEmpty(), "Database " + conn.getCatalog() + " returned no schemas");
assertThat(schemas.size(), greaterThanOrEqualTo(schemasInDb.size()));
schemasInDb.forEach(schemaInDb -> assertThat(schemas, hasItem(schemaInDb)));
assertTrue(schemas.contains(currentSchema));
assertTrue(schemasInDb.contains(currentSchema));
}
assertThat(schemasInDb.size(), greaterThanOrEqualTo(1));
assertThat(schemas.size(), greaterThanOrEqualTo(schemasInDb.size()));
schemasInDb.forEach(schemaInDb -> assertThat(schemas, hasItem(schemaInDb)));
assertTrue(schemas.contains(currentSchema));
assertTrue(schemasInDb.contains(currentSchema));

// CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX = true
try (Connection connection = getConnection();
Expand Down Expand Up @@ -241,15 +244,16 @@ public void testGetTables() throws Throwable {

@Test
public void testGetPrimarykeys() throws Throwable {
try (Statement statement = connection.createStatement()) {
String database = connection.getCatalog();
String schema = connection.getSchema();
try (Connection conn = getConnectionWithWildcardsDisabled();
Statement statement = conn.createStatement()) {
String database = conn.getCatalog();
String schema = conn.getSchema();
final String targetTable = "T0";
try {
statement.execute(
"create or replace table " + targetTable + "(C1 int primary key, C2 string)");

DatabaseMetaData metaData = connection.getMetaData();
DatabaseMetaData metaData = conn.getMetaData();

try (ResultSet resultSet = metaData.getPrimaryKeys(database, schema, targetTable)) {
verifyResultSetMetaDataColumns(resultSet, DBMetadataResultSetMetadata.GET_PRIMARY_KEYS);
Expand Down Expand Up @@ -309,9 +313,10 @@ static void verifyResultSetMetaDataColumns(

@Test
public void testGetImportedKeys() throws Throwable {
try (Statement statement = connection.createStatement()) {
String database = connection.getCatalog();
String schema = connection.getSchema();
try (Connection conn = getConnectionWithWildcardsDisabled();
Statement statement = conn.createStatement()) {
String database = conn.getCatalog();
String schema = conn.getSchema();
final String targetTable1 = "T0";
final String targetTable2 = "T1";
try {
Expand All @@ -324,7 +329,7 @@ public void testGetImportedKeys() throws Throwable {
+ targetTable1
+ ")");

DatabaseMetaData metaData = connection.getMetaData();
DatabaseMetaData metaData = conn.getMetaData();

try (ResultSet resultSet = metaData.getImportedKeys(database, schema, targetTable2)) {
verifyResultSetMetaDataColumns(resultSet, DBMetadataResultSetMetadata.GET_FOREIGN_KEYS);
Expand Down Expand Up @@ -354,9 +359,10 @@ public void testGetImportedKeys() throws Throwable {

@Test
public void testGetExportedKeys() throws Throwable {
try (Statement statement = connection.createStatement()) {
String database = connection.getCatalog();
String schema = connection.getSchema();
try (Connection conn = getConnectionWithWildcardsDisabled();
Statement statement = conn.createStatement()) {
String database = conn.getCatalog();
String schema = conn.getSchema();
final String targetTable1 = "T0";
final String targetTable2 = "T1";
try {
Expand All @@ -369,7 +375,7 @@ public void testGetExportedKeys() throws Throwable {
+ targetTable1
+ ")");

DatabaseMetaData metaData = connection.getMetaData();
DatabaseMetaData metaData = conn.getMetaData();

try (ResultSet resultSet = metaData.getExportedKeys(database, schema, targetTable1)) {
verifyResultSetMetaDataColumns(resultSet, DBMetadataResultSetMetadata.GET_FOREIGN_KEYS);
Expand Down Expand Up @@ -400,9 +406,10 @@ public void testGetExportedKeys() throws Throwable {

@Test
public void testGetCrossReferences() throws Throwable {
try (Statement statement = connection.createStatement()) {
String database = connection.getCatalog();
String schema = connection.getSchema();
try (Connection conn = getConnectionWithWildcardsDisabled();
Statement statement = conn.createStatement()) {
String database = conn.getCatalog();
String schema = conn.getSchema();
final String targetTable1 = "T0";
final String targetTable2 = "T1";
try {
Expand All @@ -415,7 +422,7 @@ public void testGetCrossReferences() throws Throwable {
+ targetTable1
+ ")");

DatabaseMetaData metaData = connection.getMetaData();
DatabaseMetaData metaData = conn.getMetaData();

try (ResultSet resultSet =
metaData.getCrossReference(
Expand Down Expand Up @@ -448,16 +455,17 @@ public void testGetCrossReferences() throws Throwable {

@Test
public void testGetObjectsDoesNotExists() throws Throwable {
try (Statement statement = connection.createStatement()) {
String database = connection.getCatalog();
String schema = escapeUnderscore(connection.getSchema());
try (Connection conn = getConnectionWithWildcardsDisabled();
Statement statement = conn.createStatement()) {
String database = conn.getCatalog();
String schema = conn.getSchema();
final String targetTable = "T0";
final String targetView = "V0";
try {
statement.execute("create or replace table " + targetTable + "(C1 int)");
statement.execute("create or replace view " + targetView + " as select 1 as C");

DatabaseMetaData metaData = connection.getMetaData();
DatabaseMetaData metaData = conn.getMetaData();

// sanity check if getTables really works.
try (ResultSet resultSet = metaData.getTables(database, schema, "%", null)) {
Expand Down Expand Up @@ -601,17 +609,17 @@ public void testGetTablePrivileges() throws Exception {

@Test
public void testGetProcedures() throws SQLException {
try (Statement statement = connection.createStatement()) {
try (Connection conn = getConnectionWithWildcardsDisabled();
Statement statement = conn.createStatement()) {
try {
String database = connection.getCatalog();
String schema = connection.getSchema();
String database = conn.getCatalog();
String schema = conn.getSchema();

/* Create a procedure and put values into it */
statement.execute(PI_PROCEDURE);
DatabaseMetaData metaData = connection.getMetaData();
DatabaseMetaData metaData = conn.getMetaData();
/* Call getFunctionColumns on FUNC111 and since there's no parameter name, get all rows back */
try (ResultSet resultSet =
metaData.getProcedures(database, escapeUnderscore(schema), "GETPI")) {
try (ResultSet resultSet = metaData.getProcedures(database, schema, "GETPI")) {
verifyResultSetMetaDataColumns(resultSet, DBMetadataResultSetMetadata.GET_PROCEDURES);
resultSet.next();
assertEquals("GETPI", resultSet.getString("PROCEDURE_NAME"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.jupiter.api.Test;

/** Database Metadata IT */
@Tag(TestTags.OTHERS)
@Tag(TestTags.DATABASE_META_DATA)
public class DatabaseMetaDataInternalIT extends BaseJDBCTest {
private Connection connection;
private Statement statement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* tests still is not applicable. If it is applicable, move tests to DatabaseMetaDataIT so that both
* the latest and oldest supported driver run the tests.
*/
@Tag(TestTags.OTHERS)
@Tag(TestTags.DATABASE_META_DATA)
public class DatabaseMetaDataInternalLatestIT extends BaseJDBCTest {

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1652,17 +1652,18 @@ public void testGetColumns() throws Throwable {
public void testGetStreams() throws SQLException {
final String targetStream = "S0";
final String targetTable = "T0";
try (Statement statement = connection.createStatement()) {
String database = connection.getCatalog();
String schema = connection.getSchema();
String owner = connection.unwrap(SnowflakeConnectionImpl.class).getSFBaseSession().getRole();
try (Connection conn = getConnectionWithWildcardsDisabled();
Statement statement = conn.createStatement()) {
String database = conn.getCatalog();
String schema = conn.getSchema();
String owner = conn.unwrap(SnowflakeConnectionImpl.class).getSFBaseSession().getRole();
String tableName = database + "." + schema + "." + targetTable;

try {
statement.execute("create or replace table " + targetTable + "(C1 int)");
statement.execute("create or replace stream " + targetStream + " on table " + targetTable);

DatabaseMetaData metaData = connection.getMetaData();
DatabaseMetaData metaData = conn.getMetaData();

// match stream
try (ResultSet resultSet =
Expand Down Expand Up @@ -2616,9 +2617,7 @@ class WhenWildcardsDisabled {

@BeforeAll
void setUp() throws Exception {
Properties props = new Properties();
props.put("ENABLE_WILDCARDS_IN_SHOW_METADATA_COMMANDS", "false");
connection = getConnection(props);
connection = getConnectionWithWildcardsDisabled();
metaData = connection.getMetaData();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag(TestTags.RESULT_SET)
@Tag(TestTags.DATABASE_META_DATA)
public class DatabaseMetaDataResultSetLatestIT extends BaseJDBCTest {

@Test
Expand All @@ -42,7 +42,7 @@ public void testGetObjectNotSupported() throws SQLException {
/** Added in > 3.17.0 */
@Test
public void testObjectColumn() throws SQLException {
try (Connection connection = getConnection();
try (Connection connection = getConnectionWithWildcardsDisabled();
Statement statement = connection.createStatement()) {
statement.execute("ALTER SESSION SET ENABLE_STRUCTURED_TYPES_IN_FDN_TABLES = TRUE");
statement.execute(
Expand Down
Loading