Skip to content
This repository was archived by the owner on Mar 31, 2021. It is now read-only.

Commit 2a3ac84

Browse files
tbrugzarsen-es
authored andcommitted
Accept null 'columnNamePattern' on DatabaseMetaData.getColumns() - #11 (#12)
Issue #, if available: #11 Changed constructor of `DatabaseMetaDataImpl.ColumnMetadataStatement` to allow null on `columnNamePattern` parameter.
1 parent 93d9d7a commit 2a3ac84

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/com/amazon/opendistroforelasticsearch/jdbc/DatabaseMetaDataImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,9 @@ static class ColumnMetadataStatement extends PreparedStatementImpl {
12171217
ColumnMetadataStatement(ConnectionImpl connection, String tableNamePattern, String columnNamePattern, Logger log)
12181218
throws SQLException {
12191219
// TODO - once sql plugin supports PreparedStatement fully, do this through a preparedStatement with params
1220-
super(connection, "DESCRIBE TABLES LIKE " + tableNamePattern + " COLUMNS LIKE " + columnNamePattern, log);
1220+
super(connection, "DESCRIBE TABLES LIKE " + tableNamePattern +
1221+
(columnNamePattern != null ? (" COLUMNS LIKE " + columnNamePattern) : ""),
1222+
log);
12211223
}
12221224

12231225
static class ColumnMetadataResultSet extends ResultSetImpl {

src/test/java/com/amazon/opendistroforelasticsearch/jdbc/DatabaseMetaDataTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.amazon.opendistroforelasticsearch.jdbc;
1818

19+
import com.amazon.opendistroforelasticsearch.jdbc.DatabaseMetaDataImpl.ColumnMetadataStatement;
1920
import com.amazon.opendistroforelasticsearch.jdbc.config.ConnectionConfig;
2021
import com.amazon.opendistroforelasticsearch.jdbc.logging.NoOpLogger;
2122
import com.amazon.opendistroforelasticsearch.jdbc.protocol.ClusterMetadata;
@@ -367,6 +368,24 @@ void testGetSchemasWithInvalidPatterns() throws Exception {
367368
assertEmptySchemaResultSet(dbmd.getSchemas("mock-cluster", "some-schema"));
368369
assertEmptySchemaResultSet(dbmd.getSchemas(null, "some-schema"));
369370
}
371+
372+
@Test
373+
void testGetColumnsWithoutColumnNamePattern() throws Exception {
374+
Connection con = getMockConnection();
375+
376+
ColumnMetadataStatement stmt = new ColumnMetadataStatement((ConnectionImpl)con, "TABLE_%", null, NoOpLogger.INSTANCE);
377+
assertEquals("DESCRIBE TABLES LIKE TABLE_%", stmt.sql);
378+
assertDoesNotThrow(stmt::close);
379+
}
380+
381+
@Test
382+
void testGetColumnsWithColumnNamePattern() throws Exception {
383+
Connection con = getMockConnection();
384+
385+
ColumnMetadataStatement stmt = new ColumnMetadataStatement((ConnectionImpl)con, "TABLE_%", "COLUMN_%", NoOpLogger.INSTANCE);
386+
assertEquals("DESCRIBE TABLES LIKE TABLE_% COLUMNS LIKE COLUMN_%", stmt.sql);
387+
assertDoesNotThrow(stmt::close);
388+
}
370389

371390
private void assertValidSchemaResultSet(ResultSet rs) throws SQLException {
372391
getExpectedSchemaResultSet().assertMatches(rs);

0 commit comments

Comments
 (0)