Skip to content

Commit

Permalink
Accept null 'columnNamePattern' on DatabaseMetaData.getColumns() - am…
Browse files Browse the repository at this point in the history
…azon-archives#11 (amazon-archives#12)

Issue #, if available: amazon-archives#11

Changed constructor of `DatabaseMetaDataImpl.ColumnMetadataStatement` to allow null on `columnNamePattern` parameter.
  • Loading branch information
tbrugz authored and arsen-es committed Jun 24, 2019
1 parent 93d9d7a commit 2a3ac84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,9 @@ static class ColumnMetadataStatement extends PreparedStatementImpl {
ColumnMetadataStatement(ConnectionImpl connection, String tableNamePattern, String columnNamePattern, Logger log)
throws SQLException {
// TODO - once sql plugin supports PreparedStatement fully, do this through a preparedStatement with params
super(connection, "DESCRIBE TABLES LIKE " + tableNamePattern + " COLUMNS LIKE " + columnNamePattern, log);
super(connection, "DESCRIBE TABLES LIKE " + tableNamePattern +
(columnNamePattern != null ? (" COLUMNS LIKE " + columnNamePattern) : ""),
log);
}

static class ColumnMetadataResultSet extends ResultSetImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.amazon.opendistroforelasticsearch.jdbc;

import com.amazon.opendistroforelasticsearch.jdbc.DatabaseMetaDataImpl.ColumnMetadataStatement;
import com.amazon.opendistroforelasticsearch.jdbc.config.ConnectionConfig;
import com.amazon.opendistroforelasticsearch.jdbc.logging.NoOpLogger;
import com.amazon.opendistroforelasticsearch.jdbc.protocol.ClusterMetadata;
Expand Down Expand Up @@ -367,6 +368,24 @@ void testGetSchemasWithInvalidPatterns() throws Exception {
assertEmptySchemaResultSet(dbmd.getSchemas("mock-cluster", "some-schema"));
assertEmptySchemaResultSet(dbmd.getSchemas(null, "some-schema"));
}

@Test
void testGetColumnsWithoutColumnNamePattern() throws Exception {
Connection con = getMockConnection();

ColumnMetadataStatement stmt = new ColumnMetadataStatement((ConnectionImpl)con, "TABLE_%", null, NoOpLogger.INSTANCE);
assertEquals("DESCRIBE TABLES LIKE TABLE_%", stmt.sql);
assertDoesNotThrow(stmt::close);
}

@Test
void testGetColumnsWithColumnNamePattern() throws Exception {
Connection con = getMockConnection();

ColumnMetadataStatement stmt = new ColumnMetadataStatement((ConnectionImpl)con, "TABLE_%", "COLUMN_%", NoOpLogger.INSTANCE);
assertEquals("DESCRIBE TABLES LIKE TABLE_% COLUMNS LIKE COLUMN_%", stmt.sql);
assertDoesNotThrow(stmt::close);
}

private void assertValidSchemaResultSet(ResultSet rs) throws SQLException {
getExpectedSchemaResultSet().assertMatches(rs);
Expand Down

0 comments on commit 2a3ac84

Please sign in to comment.