mirror of https://github.com/apache/lucene.git
Add collection alias support for Calcite
This commit is contained in:
parent
7a53e9a152
commit
5f65487658
|
@ -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<String> collections = cloudSolrClient.getZkStateReader().getClusterState().getCollectionsMap().keySet();
|
||||
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
|
||||
ClusterState clusterState = zkStateReader.getClusterState();
|
||||
|
||||
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
|
||||
for (String collection : collections) {
|
||||
|
||||
for (String collection : clusterState.getCollectionsMap().keySet()) {
|
||||
builder.put(collection, new SolrTable(this, collection));
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> alias : zkStateReader.getAliases().getCollectionAliasMap().entrySet()) {
|
||||
builder.put(alias.getKey(), new SolrTable(this, alias.getValue()));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -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<String> collections = new ArrayList<>();
|
||||
collections.addAll(cluster.getSolrClient().getZkStateReader().getClusterState().getCollectionsMap().keySet());
|
||||
Collections.sort(collections);
|
||||
ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
|
||||
|
||||
SortedSet<String> tables = new TreeSet<>();
|
||||
Set<String> collections = zkStateReader.getClusterState().getCollectionsMap().keySet();
|
||||
Set<String> 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"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue