@Override public List<String> getCaseSensitiveTableNames(String caseInsensitiveSchemaName) throws SchemaNotFoundException { KeyspaceMetadata keyspace = getKeyspaceByCaseInsensitiveName(caseInsensitiveSchemaName); ImmutableList.Builder<String> builder = ImmutableList.builder(); for (TableMetadata table : keyspace.getTables()) { builder.add(table.getName()); } for (MaterializedViewMetadata materializedView : keyspace.getMaterializedViews()) { builder.add(materializedView.getName()); } return builder.build(); }
private static AbstractTableMetadata getTableMetadata(KeyspaceMetadata keyspace, String caseInsensitiveTableName) { List<AbstractTableMetadata> tables = Stream.concat( keyspace.getTables().stream(), keyspace.getMaterializedViews().stream()) .filter(table -> table.getName().equalsIgnoreCase(caseInsensitiveTableName)) .collect(toImmutableList()); if (tables.size() == 0) { throw new TableNotFoundException(new SchemaTableName(keyspace.getName(), caseInsensitiveTableName)); } else if (tables.size() == 1) { return tables.get(0); } String tableNames = tables.stream() .map(AbstractTableMetadata::getName) .sorted() .collect(joining(", ")); throw new PrestoException( NOT_SUPPORTED, format("More than one table has been found for the case insensitive table name: %s -> (%s)", caseInsensitiveTableName, tableNames)); }
assertThat(km.getTables().size() >= 2); assertThat(km.isVirtual()).isTrue(); assertThat(km.isDurableWrites()).isFalse();
public List<String> getTableNames(String keySpace) { Metadata clusterMetadata = cluster.getMetadata(); KeyspaceMetadata keyspaceMetadata = clusterMetadata.getKeyspace(keySpace); if (keyspaceMetadata == null) { return ImmutableList.of(); } return keyspaceMetadata.getTables().stream() .map(TableMetadata::getName) .collect(toList()); }
public List<String> getTableNames(String keySpace) { Metadata clusterMetadata = cluster.getMetadata(); KeyspaceMetadata keyspaceMetadata = clusterMetadata.getKeyspace(keySpace); if (keyspaceMetadata == null) { return ImmutableList.of(); } return keyspaceMetadata.getTables().stream() .map(TableMetadata::getName) .collect(toList()); }
/** * Drop tables that exist in the keyspace. * * @param dropUnused {@literal true} to drop unused tables. Table usage is determined by existing table mappings. */ public void dropTables(boolean dropUnused) { this.cassandraAdminOperations.getKeyspaceMetadata() // .getTables() // .stream() // .map(AbstractTableMetadata::getName) // .map(CqlIdentifier::of).filter(table -> dropUnused || this.mappingContext.usesTable(table)) // .forEach(this.cassandraAdminOperations::dropTable); }
private static void cleanDataWithNativeDriver(String keyspace, String... excludedTables) { HashSet<String> excludedTableList = new HashSet<>(Arrays.asList(excludedTables)); cluster.getMetadata().getKeyspace(keyspace).getTables().stream() .map(table -> table.getName()) .filter(tableName -> !excludedTableList.contains(tableName)) .map(tableName -> keyspace + "." + tableName) .forEach(CqlOperations.truncateTable(session)); }
private static void cleanDataWithNativeDriver(String keyspace, String... excludedTables) { HashSet<String> excludedTableList = new HashSet<>(Arrays.asList(excludedTables)); cluster.getMetadata().getKeyspace(keyspace).getTables().stream() .map(table -> table.getName()) .filter(tableName -> !excludedTableList.contains(tableName)) .map(tableName -> keyspace + "." + tableName) .forEach(CqlOperations.truncateTable(session)); }
private static void cleanDataWithNativeDriver(String keyspace, String... excludedTables) { HashSet<String> excludedTableList = new HashSet<>(Arrays.asList(excludedTables)); cluster.getMetadata().getKeyspace(keyspace).getTables().stream() .map(table -> table.getName()) .filter(tableName -> !excludedTableList.contains(tableName)) .map(tableName -> keyspace + "." + tableName) .forEach(CqlOperations.truncateTable(session)); }
@Override public List<String> getCaseSensitiveTableNames(String caseInsensitiveSchemaName) throws SchemaNotFoundException { KeyspaceMetadata keyspace = getKeyspaceByCaseInsensitiveName(caseInsensitiveSchemaName); ImmutableList.Builder<String> builder = ImmutableList.builder(); for (TableMetadata table : keyspace.getTables()) { builder.add(table.getName()); } for (MaterializedViewMetadata materializedView : keyspace.getMaterializedViews()) { builder.add(materializedView.getName()); } return builder.build(); }
@Override public List<String> getCaseSensitiveTableNames(String caseInsensitiveSchemaName) throws SchemaNotFoundException { KeyspaceMetadata keyspace = getKeyspaceByCaseInsensitiveName(caseInsensitiveSchemaName); ImmutableList.Builder<String> builder = ImmutableList.builder(); for (TableMetadata table : keyspace.getTables()) { builder.add(table.getName()); } for (MaterializedViewMetadata materializedView : keyspace.getMaterializedViews()) { builder.add(materializedView.getName()); } return builder.build(); }
private List<String> generateTableList() { List<String> tableList = new ArrayList<>(); for (TableMetadata tableMetadata : this.session.getCluster().getMetadata().getKeyspace(this.keyspace) .getTables()) { tableList.add(tableMetadata.getName()); } return tableList; }
public void refreshTablenames() { Collection<TableMetadata> tableMetadatas = session.getCluster().getMetadata() .getKeyspace(STREAMING.STREAMING_KEYSPACE_NAME).getTables(); tablenames = new HashMap<>(); for (TableMetadata tableMetadata : tableMetadatas) { Set<String> columns = new HashSet<>(); for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) { columns.add(columnMetadata.getName()); } tablenames.put(tableMetadata.getName(), columns.hashCode()); } }
/** * Get the list of tables in a Cassandra keyspaces. * @param catalog The name of the keyspace * @return The list of tables or empty if the keyspace does * not exist, or the not connected. */ public List<String> getTablesNames(String catalog){ List<String> result = new ArrayList<>(); //Retrieve database tables. if(clusterMetadata != null && clusterMetadata.getKeyspace(catalog) != null){ KeyspaceMetadata km = clusterMetadata.getKeyspace(catalog); for(TableMetadata tm : km.getTables()){ result.add(tm.getName()); } } return result; }
@Override public Observable<ResultSet> createTempTablesIfNotExists(final Set<Long> timestamps) { return Observable.fromCallable(() -> { Set<String> tables = timestamps.stream() .map(this::getTempTableName) .collect(Collectors.toSet()); // TODO This is an IO operation.. metadata.getKeyspace(session.getLoggedKeyspace()).getTables().stream() .map(AbstractTableMetadata::getName) .filter(t -> t.startsWith(TEMP_TABLE_NAME_PROTOTYPE)) .forEach(tables::remove); return tables; }) .flatMapIterable(s -> s) .zipWith(Observable.interval(300, TimeUnit.MILLISECONDS), (st, l) -> st) .concatMap(this::createTemporaryTable); }
@Override public Observable<ResultSet> createTempTablesIfNotExists(final Set<Long> timestamps) { return Observable.fromCallable(() -> { Set<String> tables = timestamps.stream() .map(this::getTempTableName) .collect(Collectors.toSet()); // TODO This is an IO operation.. metadata.getKeyspace(session.getLoggedKeyspace()).getTables().stream() .map(AbstractTableMetadata::getName) .filter(t -> t.startsWith(TEMP_TABLE_NAME_PROTOTYPE)) .forEach(tables::remove); return tables; }) .flatMapIterable(s -> s) .zipWith(Observable.interval(300, TimeUnit.MILLISECONDS), (st, l) -> st) .concatMap(this::createTemporaryTable); }
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; }
/** * Check whether the keyspace for this Fiji instance is empty. * * @return whether the keyspace is empty. */ public boolean keyspaceIsEmpty() { Preconditions.checkNotNull(getSession()); Preconditions.checkNotNull(getSession().getCluster()); Preconditions.checkNotNull(getSession().getCluster().getMetadata()); String keyspace = CassandraTableName.getKeyspace(mFijiURI); Preconditions.checkNotNull(getSession().getCluster().getMetadata().getKeyspace(keyspace)); Collection<TableMetadata> tables = getSession().getCluster().getMetadata().getKeyspace(keyspace).getTables(); return tables.isEmpty(); }
private String table(Session session, Table keyspaceTable, Type targetType) { String table = keyspaceTable.table(); if (table == null) { final String className = TypeHelper.toClass(targetType).getSimpleName(); for(TableMetadata metadata : session.getCluster().getMetadata().getKeyspace(keyspace(session, keyspaceTable)).getTables()) { if (DefaultPropertyNameMatcher.of(metadata.getName()).matches(className)) { return metadata.getName(); } } } else { return table; } throw new IllegalArgumentException("No table define on type " + targetType); }
@Override public void clearStorage() throws BackendException { if (this.storageConfig.get(DROP_ON_CLEAR)) { this.session.execute(dropKeyspace(this.keyspace)); } else if (this.exists()) { final Future<Seq<ResultSet>> result = Future.sequence( Iterator.ofAll(this.cluster.getMetadata().getKeyspace(this.keyspace).getTables()) .map(table -> Future.fromJavaFuture(this.session.executeAsync(truncate(this.keyspace, table.getName()))))); result.await(); } else { LOGGER.info("Keyspace {} does not exist in the cluster", this.keyspace); } }