diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java index 53f5c8dd25e..c96ea7c00ed 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java @@ -705,17 +705,29 @@ class DatabaseMetaDataImpl implements DatabaseMetaData { @Override public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException { - return this.connectionStatement.executeQuery("select TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS from _TABLES_"); + String tableCatCheck = ""; + if(catalog != null) { + tableCatCheck = "tableCat = '\" + catalog + \"' and"; + } + if(schemaPattern == null) { + schemaPattern = "%"; + } + if(tableNamePattern == null) { + tableNamePattern = "%"; + } + return this.connectionStatement.executeQuery("select tableCat, tableSchem, tableName, tableType, remarks from " + + "metadata.TABLES where " + tableCatCheck + " tableSchem like '" + schemaPattern + "' and tableName like '" + + tableNamePattern + "'"); } @Override public ResultSet getSchemas() throws SQLException { - return this.connectionStatement.executeQuery("select TABLE_SCHEM, TABLE_CATALOG from _SCHEMAS_"); + return this.connectionStatement.executeQuery("select distinct tableSchem, tableCat from metadata.TABLES"); } @Override public ResultSet getCatalogs() throws SQLException { - return this.connectionStatement.executeQuery("select TABLE_CAT from _CATALOGS_"); + return this.connectionStatement.executeQuery("select distinct tableCat from metadata.TABLES"); } @Override diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java index 445cd4299fb..24828e5694d 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java @@ -25,6 +25,9 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import java.sql.Types; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Properties; import org.apache.lucene.util.LuceneTestCase; @@ -466,11 +469,19 @@ public class JdbcTest extends AbstractFullDistribZkTestBase { // assertEquals(0, databaseMetaData.getDriverMajorVersion()); // assertEquals(0, databaseMetaData.getDriverMinorVersion()); - // TODO fix getCatalogs, getSchemas, and getTables - /* + try(ResultSet rs = databaseMetaData.getSchemas()) { + assertTrue(rs.next()); + assertEquals(zkServer.getZkAddress(), rs.getString("tableSchem")); + assertNull(rs.getString("tableCat")); + assertTrue(rs.next()); + assertEquals("metadata", rs.getString("tableSchem")); + assertNull(rs.getString("tableCat")); + assertFalse(rs.next()); + } + try(ResultSet rs = databaseMetaData.getCatalogs()) { assertTrue(rs.next()); - assertEquals(zkServer.getZkAddress(), rs.getString("TABLE_CAT")); + assertNull(rs.getString("tableCat")); assertFalse(rs.next()); } @@ -478,22 +489,17 @@ public class JdbcTest extends AbstractFullDistribZkTestBase { collections.addAll(cloudClient.getZkStateReader().getClusterState().getCollections()); Collections.sort(collections); - try(ResultSet rs = databaseMetaData.getSchemas()) { - assertFalse(rs.next()); - } - - try(ResultSet rs = databaseMetaData.getTables(zkServer.getZkAddress(), null, "%", null)) { + try(ResultSet rs = databaseMetaData.getTables(null, zkServer.getZkAddress(), "%", null)) { for(String acollection : collections) { assertTrue(rs.next()); - assertEquals(zkServer.getZkAddress(), rs.getString("TABLE_CAT")); - assertNull(rs.getString("TABLE_SCHEM")); - assertEquals(acollection, rs.getString("TABLE_NAME")); - assertEquals("TABLE", rs.getString("TABLE_TYPE")); - assertNull(rs.getString("REMARKS")); + assertNull(rs.getString("tableCat")); + assertEquals(zkServer.getZkAddress(), rs.getString("tableSchem")); + assertEquals(acollection, rs.getString("tableName")); + assertEquals("TABLE", rs.getString("tableType")); + assertNull(rs.getString("remarks")); } assertFalse(rs.next()); } - */ assertTrue(con.isReadOnly()); con.setReadOnly(true);