Skip to content
This repository was archived by the owner on Mar 31, 2021. It is now read-only.
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
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