Java Code Examples for com.datastax.driver.core.TableMetadata#getName()
The following examples show how to use
com.datastax.driver.core.TableMetadata#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraUtils.java From sstable-tools with Apache License 2.0 | 6 votes |
public static Cluster loadTablesFromRemote(String host, int port, String cfidOverrides) throws IOException { Map<String, UUID> cfs = parseOverrides(cfidOverrides); Cluster.Builder builder = Cluster.builder().addContactPoints(host).withPort(port); Cluster cluster = builder.build(); Metadata metadata = cluster.getMetadata(); IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner()); if (DatabaseDescriptor.getPartitioner() == null) DatabaseDescriptor.setPartitionerUnsafe(partitioner); for (com.datastax.driver.core.KeyspaceMetadata ksm : metadata.getKeyspaces()) { if (!ksm.getName().equals("system")) { for (TableMetadata tm : ksm.getTables()) { String name = ksm.getName()+"."+tm.getName(); try { CassandraUtils.tableFromCQL( new ByteArrayInputStream(tm.asCQLQuery().getBytes()), cfs.get(name) != null ? cfs.get(name) : tm.getId()); } catch(SyntaxException e) { // ignore tables that we cant parse (probably dse) logger.debug("Ignoring table " + name + " due to syntax exception " + e.getMessage()); } } } } return cluster; }
Example 2
Source File: SchemaUpgradeIT.java From glowroot with Apache License 2.0 | 6 votes |
private static void restore(String keyspace) throws Exception { String cqlsh = "cassandra/apache-cassandra-" + CassandraWrapper.CASSANDRA_VERSION + "/bin/cqlsh"; if (System.getProperty("os.name").startsWith("Windows")) { cqlsh += ".bat"; } String backupFolder = "src/test/resources/backup-0.9.1/"; Cluster cluster = Clusters.newCluster(); for (TableMetadata table : cluster.getMetadata().getKeyspace(keyspace).getTables()) { // limiting MAXBATCHSIZE to avoid "Batch too large" errors ProcessBuilder processBuilder = new ProcessBuilder(cqlsh, "-e", "copy " + keyspace + "." + table.getName() + " from '" + backupFolder + table.getName() + ".csv' with NULL='NULL.NULL.NULL.NULL' and" + " NUMPROCESSES = 1 and MAXBATCHSIZE = 1"); processBuilder.redirectErrorStream(true); Process process = processBuilder.start(); ConsoleOutputPipe consoleOutputPipe = new ConsoleOutputPipe(process.getInputStream(), System.out); ExecutorService consolePipeExecutorService = Executors.newSingleThreadExecutor(); consolePipeExecutorService.submit(consoleOutputPipe); process.waitFor(); } }
Example 3
Source File: SchemaUpgradeIT.java From glowroot with Apache License 2.0 | 6 votes |
@SuppressWarnings("unused") private static void backup(String keyspace) throws Exception { String cqlsh = "cassandra/apache-cassandra-" + CassandraWrapper.CASSANDRA_VERSION + "/bin/cqlsh"; if (System.getProperty("os.name").startsWith("Windows")) { cqlsh += ".bat"; } String backupFolder = "src/test/resources/backup-0.9.1/"; Cluster cluster = Clusters.newCluster(); ExecutorService executor = Executors.newSingleThreadExecutor(); for (TableMetadata table : cluster.getMetadata().getKeyspace(keyspace).getTables()) { ProcessBuilder processBuilder = new ProcessBuilder(cqlsh, "-e", "copy " + keyspace + "." + table.getName() + " to '" + backupFolder + table.getName() + ".csv' with NULL='NULL.NULL.NULL.NULL' and" + " NUMPROCESSES = 1"); processBuilder.redirectErrorStream(true); Process process = processBuilder.start(); executor.submit(new ConsoleOutputPipe(process.getInputStream(), System.out)); process.waitFor(); } executor.shutdown(); cluster.close(); }
Example 4
Source File: CassandraSchema.java From calcite with Apache License 2.0 | 5 votes |
@Override protected Map<String, Table> getTableMap() { final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder(); for (TableMetadata table : getKeyspace().getTables()) { String tableName = table.getName(); builder.put(tableName, new CassandraTable(this, tableName)); for (MaterializedViewMetadata view : table.getViews()) { String viewName = view.getName(); builder.put(viewName, new CassandraTable(this, viewName, true)); } } return builder.build(); }
Example 5
Source File: SchemaHolder.java From debezium-incubator with Apache License 2.0 | 4 votes |
private static String getKeyName(String kafkaTopicPrefix, TableMetadata tm) { return kafkaTopicPrefix + "." + tm.getKeyspace().getName() + "." + tm.getName() + ".Key"; }
Example 6
Source File: SchemaHolder.java From debezium-incubator with Apache License 2.0 | 4 votes |
private static String getValueName(String kafkaTopicPrefix, TableMetadata tm) { return kafkaTopicPrefix + "." + tm.getKeyspace().getName() + "." + tm.getName() + ".Value"; }
Example 7
Source File: KeyspaceTable.java From debezium-incubator with Apache License 2.0 | 4 votes |
public KeyspaceTable(TableMetadata tableMetadata) { this.keyspace = tableMetadata.getKeyspace().getName(); this.table = tableMetadata.getName(); }
Example 8
Source File: SnapshotProcessor.java From debezium-incubator with Apache License 2.0 | 4 votes |
private static String tableName(TableMetadata tm) { return tm.getKeyspace().getName() + "." + tm.getName(); }
Example 9
Source File: CassandraConnectorTableService.java From metacat with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public List<QualifiedName> listNames( @Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable ) { final String catalog = name.getCatalogName(); final String keyspace = name.getDatabaseName(); log.debug("Attempting to list table names in Cassandra keyspace {} for request {}", keyspace, context); try { final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new DatabaseNotFoundException(name); } // TODO: Should we include views? final List<QualifiedName> tableNames = Lists.newArrayList(); for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) { final String tableName = tableMetadata.getName(); if (prefix != null && !tableName.startsWith(prefix.getTableName())) { continue; } tableNames.add(QualifiedName.ofTable(catalog, keyspace, tableName)); } // Sort if (sort != null) { final Comparator<QualifiedName> tableNameComparator = Comparator.comparing(QualifiedName::getTableName); ConnectorUtils.sort(tableNames, sort, tableNameComparator); } // Paging final List<QualifiedName> paged = ConnectorUtils.paginate(tableNames, pageable); log.debug("Listed {} table names in Cassandra keyspace {} for request {}", paged.size(), keyspace, context); return paged; } catch (final DriverException de) { log.error(de.getMessage(), de); throw this.getExceptionMapper().toConnectorException(de, name); } }
Example 10
Source File: TableMetaDataToCellData.java From Explorer with Apache License 2.0 | 4 votes |
/** * Transform TableMetadata to CellData with TableName Value * @param value * @return CellData with Table value */ @Override public CellData transform(TableMetadata value) { return new CellData(value.getName()); }