@Override public List<String> getCaseSensitiveSchemaNames() { ImmutableList.Builder<String> builder = ImmutableList.builder(); List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); for (KeyspaceMetadata meta : keyspaces) { builder.add(meta.getName()); } return builder.build(); }
private KeyspaceMetadata getKeyspaceByCaseInsensitiveName(String caseInsensitiveSchemaName) throws SchemaNotFoundException { List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); KeyspaceMetadata result = null; // Ensure that the error message is deterministic List<KeyspaceMetadata> sortedKeyspaces = Ordering.from(comparing(KeyspaceMetadata::getName)).immutableSortedCopy(keyspaces); for (KeyspaceMetadata keyspace : sortedKeyspaces) { if (keyspace.getName().equalsIgnoreCase(caseInsensitiveSchemaName)) { if (result != null) { throw new PrestoException( NOT_SUPPORTED, format("More than one keyspace has been found for the case insensitive schema name: %s -> (%s, %s)", caseInsensitiveSchemaName, result.getName(), keyspace.getName())); } result = keyspace; } } if (result == null) { throw new SchemaNotFoundException(caseInsensitiveSchemaName); } return result; }
/** * Get the list of keyspaces in Cassandra. * * @return The list of keyspaces or empty if not connected. */ public List<String> getKeyspacesNames() { List<String> result = new ArrayList<>(); if (clusterMetadata != null) { for (KeyspaceMetadata list : clusterMetadata.getKeyspaces()) { result.add(list.getName()); } } return result; }
private static void dropKeyspacesWithNativeDriver() { cluster.getMetadata().getKeyspaces().stream() .map(KeyspaceMetadata::getName) .filter(nonSystemKeyspaces()) .forEach(CqlOperations.dropKeyspace(session)); }
private static void dropKeyspacesWithNativeDriver() { cluster.getMetadata().getKeyspaces().stream() .map(KeyspaceMetadata::getName) .filter(nonSystemKeyspaces()) .forEach(CqlOperations.dropKeyspace(session)); }
private static void dropKeyspacesWithNativeDriver() { cluster.getMetadata().getKeyspaces().stream() .map(KeyspaceMetadata::getName) .filter(nonSystemKeyspaces()) .forEach(CqlOperations.dropKeyspace(session)); }
void updateSchema() { for (KeyspaceMetadata keyspaceMetadata : cluster.getMetadata().getKeyspaces()) { updateSchema(keyspaceMetadata); } }
public List<String> getDoradusKeyspaces() { List<String> keyspaces = new ArrayList<>(); List<KeyspaceMetadata> keyspaceList = m_cluster.getMetadata().getKeyspaces(); for (KeyspaceMetadata ksMetadata : keyspaceList) { if (ksMetadata.getTable(APPS_CQL_NAME) != null) { keyspaces.add(ksMetadata.getName()); } } return keyspaces; }
@Override public List<String> getCaseSensitiveSchemaNames() { ImmutableList.Builder<String> builder = ImmutableList.builder(); List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); for (KeyspaceMetadata meta : keyspaces) { builder.add(meta.getName()); } return builder.build(); }
@Override public List<String> getCaseSensitiveSchemaNames() { ImmutableList.Builder<String> builder = ImmutableList.builder(); List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); for (KeyspaceMetadata meta : keyspaces) { builder.add(meta.getName()); } return builder.build(); }
private void displayClusterInfo() { Metadata metadata = m_cluster.getMetadata(); m_logger.info("Connected to cluster with topography:"); RoundRobinPolicy policy = new RoundRobinPolicy(); for (Host host : metadata.getAllHosts()) { m_logger.info(" Host {}: datacenter: {}, rack: {}, distance: {}", new Object[]{host.getAddress(), host.getDatacenter(), host.getRack(), policy.distance(host)}); } m_logger.info("Database contains {} keyspaces", metadata.getKeyspaces().size()); } // displayClusterInfo
@Override public Collection<Tenant> getTenants() { checkState(); List<Tenant> tenants = new ArrayList<>(); List<KeyspaceMetadata> keyspaceList = m_cluster.getMetadata().getKeyspaces(); for (KeyspaceMetadata ksMetadata : keyspaceList) { if (ksMetadata.getTable(APPS_CQL_NAME) != null) { tenants.add(new Tenant(ksMetadata.getName())); } } return tenants; } // getTenants
private void displayClusterInfo() { Metadata metadata = m_cluster.getMetadata(); m_logger.info("Connected to cluster with topography:"); RoundRobinPolicy policy = new RoundRobinPolicy(); for (Host host : metadata.getAllHosts()) { m_logger.info(" Host {}: datacenter: {}, rack: {}, distance: {}", new Object[]{host.getAddress(), host.getDatacenter(), host.getRack(), policy.distance(host)}); } m_logger.info("Database contains {} keyspaces", metadata.getKeyspaces().size()); } // displayClusterInfo
public String[] c2_getTableList(String keyspace) { List<KeyspaceMetadata> lst = this.cluster.getMetadata().getKeyspaces(); String[] ss = new String[0]; for (KeyspaceMetadata km : lst) { if (km.getName().equals(keyspace)) { Collection<TableMetadata> lstTableMetadata = km.getTables(); ss = new String[lstTableMetadata.size()]; int i1 = 0; for (TableMetadata tm : lstTableMetadata) { ss[i1++] = tm.getName(); } break; } } return ss; }
/** * Obtain the existing keyspaces in cassandra. * * @param session The cassandra session. * @return A list of {@link com.stratio.crossdata.common.metadata.CatalogMetadata} . */ public static List<CatalogMetadata> getKeyspaces(Session session, String cluster) { List<CatalogMetadata> catalogMetadataList = new ArrayList<>(); List<KeyspaceMetadata> keyspaceMetadataList = session.getCluster().getMetadata().getKeyspaces(); for (KeyspaceMetadata keyspaceMetadata : keyspaceMetadataList) { //Catalogs CatalogName name = new CatalogName(keyspaceMetadata.getName()); Map<Selector, Selector> options = new HashMap<>(); Map<String, String> replicationOptions = new HashMap<>(); for (Map.Entry<String, String> entry : replicationOptions.entrySet()) { options.put(new StringSelector(entry.getKey()), new StringSelector(entry.getValue())); } //Tables Map<TableName, TableMetadata> tables = getTablesFromKeyspace(session, keyspaceMetadata, cluster); CatalogMetadata catalogMetadata = new CatalogMetadata(name, options, tables); catalogMetadataList.add(catalogMetadata); } return catalogMetadataList; }
private KeyspaceMetadata getKeyspaceByCaseInsensitiveName(String caseInsensitiveSchemaName) throws SchemaNotFoundException { List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); KeyspaceMetadata result = null; // Ensure that the error message is deterministic List<KeyspaceMetadata> sortedKeyspaces = Ordering.from(comparing(KeyspaceMetadata::getName)).immutableSortedCopy(keyspaces); for (KeyspaceMetadata keyspace : sortedKeyspaces) { if (keyspace.getName().equalsIgnoreCase(caseInsensitiveSchemaName)) { if (result != null) { throw new PrestoException( NOT_SUPPORTED, format("More than one keyspace has been found for the case insensitive schema name: %s -> (%s, %s)", caseInsensitiveSchemaName, result.getName(), keyspace.getName())); } result = keyspace; } } if (result == null) { throw new SchemaNotFoundException(caseInsensitiveSchemaName); } return result; }
private static void dropKeyspaces() { String host = DatabaseDescriptor.getRpcAddress().getHostName(); int port = DatabaseDescriptor.getNativeTransportPort(); try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint(host) .withPort(port).build(); com.datastax.driver.core.Session session = cluster.connect()) { List<String> keyspaces = new ArrayList<String>(); for (com.datastax.driver.core.KeyspaceMetadata keyspace : cluster.getMetadata().getKeyspaces()) { if (!isSystemKeyspaceName(keyspace.getName())) { keyspaces.add(keyspace.getName()); } } for (String keyspace : keyspaces) { session.execute("DROP KEYSPACE " + keyspace); } } }
private KeyspaceMetadata getKeyspaceByCaseInsensitiveName(String caseInsensitiveSchemaName) throws SchemaNotFoundException { List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); KeyspaceMetadata result = null; // Ensure that the error message is deterministic List<KeyspaceMetadata> sortedKeyspaces = Ordering.from(comparing(KeyspaceMetadata::getName)).immutableSortedCopy(keyspaces); for (KeyspaceMetadata keyspace : sortedKeyspaces) { if (keyspace.getName().equalsIgnoreCase(caseInsensitiveSchemaName)) { if (result != null) { throw new PrestoException( NOT_SUPPORTED, format("More than one keyspace has been found for the case insensitive schema name: %s -> (%s, %s)", caseInsensitiveSchemaName, result.getName(), keyspace.getName())); } result = keyspace; } } if (result == null) { throw new SchemaNotFoundException(caseInsensitiveSchemaName); } return result; }
private static void dropKeyspaces() { String host = DatabaseDescriptor.getRpcAddress().getHostName(); int port = DatabaseDescriptor.getNativeTransportPort(); try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint(host) .withPort(port).build(); com.datastax.driver.core.Session session = cluster.connect()) { List<String> keyspaces = new ArrayList<String>(); for (com.datastax.driver.core.KeyspaceMetadata keyspace : cluster.getMetadata().getKeyspaces()) { if (!isSystemKeyspaceName(keyspace.getName())) { keyspaces.add(keyspace.getName()); } } for (String keyspace : keyspaces) { session.execute("DROP KEYSPACE " + keyspace); } } }
public CassandraMetadataResultSet makeSchemas(CassandraStatement statement, String schemaPattern) throws SQLException { // TABLE_SCHEM String => schema name // TABLE_CATALOG String => catalog name (may be null) final ArrayList<MetadataRow> schemas = Lists.newArrayList(); List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces(); for(KeyspaceMetadata keyspace:keyspaces){ if ("%".equals(schemaPattern)) schemaPattern = null; if((schemaPattern==null?keyspace.getName():schemaPattern).equals(keyspace.getName())){ MetadataRow row = new MetadataRow().addEntry("TABLE_SCHEM", keyspace.getName()).addEntry("TABLE_CATALOG", statement.connection.getCatalog()); schemas.add(row); } } CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas)); return result; }