diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java index 8c3eaa90680..221ddf88dcf 100644 --- a/solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java +++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java @@ -25,6 +25,8 @@ import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.request.LukeRequest; import org.apache.solr.client.solrj.response.LukeResponse; +import org.apache.solr.common.cloud.ClusterState; +import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.luke.FieldFlag; import java.io.IOException; @@ -46,12 +48,19 @@ class SolrSchema extends AbstractSchema { String zk = this.properties.getProperty("zk"); try(CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zk).build()) { cloudSolrClient.connect(); - Set collections = cloudSolrClient.getZkStateReader().getClusterState().getCollectionsMap().keySet(); + ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader(); + ClusterState clusterState = zkStateReader.getClusterState(); final ImmutableMap.Builder builder = ImmutableMap.builder(); - for (String collection : collections) { + + for (String collection : clusterState.getCollectionsMap().keySet()) { builder.put(collection, new SolrTable(this, collection)); } + + for (Map.Entry alias : zkStateReader.getAliases().getCollectionAliasMap().entrySet()) { + builder.put(alias.getKey(), new SolrTable(this, alias.getValue())); + } + return builder.build(); } catch (IOException e) { throw new RuntimeException(e); 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 69d236f7f93..9461725df8a 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,10 +25,10 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; 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 java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase.Slow; @@ -36,6 +36,7 @@ import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.cloud.AbstractDistribZkTestBase; import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.cloud.ZkStateReader; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -514,16 +515,20 @@ public class JdbcTest extends SolrCloudTestCase { assertFalse(rs.next()); } - List collections = new ArrayList<>(); - collections.addAll(cluster.getSolrClient().getZkStateReader().getClusterState().getCollectionsMap().keySet()); - Collections.sort(collections); + ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader(); + + SortedSet tables = new TreeSet<>(); + Set collections = zkStateReader.getClusterState().getCollectionsMap().keySet(); + Set aliases = zkStateReader.getAliases().getCollectionAliasMap().keySet(); + tables.addAll(collections); + tables.addAll(aliases); try(ResultSet rs = databaseMetaData.getTables(null, zkHost, "%", null)) { - for(String acollection : collections) { + for(String table : tables) { assertTrue(rs.next()); assertNull(rs.getString("tableCat")); assertEquals(zkHost, rs.getString("tableSchem")); - assertEquals(acollection, rs.getString("tableName")); + assertEquals(table, rs.getString("tableName")); assertEquals("TABLE", rs.getString("tableType")); assertNull(rs.getString("remarks")); }