如果在 CQL shell 中使用此代码,我将获得该键空间中表的所有名称。
DESCRIBE TABLES;
我想使用 检索相同的数据结果集 .下面是我的 Java 代码。
String query = "DESCRIBE TABLES;";
ResultSet rs = session.execute(query);
for(Row row : rs) {
System.out.println(row);
}
虽然 session 和集群早先被初始化为:
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
Session session = cluster.connect("keyspace_name");
或者我想知道在键空间中检索表名的 Java 代码。
最佳答案
系统表的架构在版本之间变化很大。最好依赖于将内置版本特定解析的驱动程序元数据。从 Java 驱动程序使用
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
Collection<TableMetadata> tables = cluster.getMetadata()
.getKeyspace("keyspace_name")
.getTables(); // TableMetadata has name in getName(), along with lots of other info
// to convert to list of the names
List<String> tableNames = tables.stream()
.map(tm -> tm.getName())
.collect(Collectors.toList());
关于cassandra - 如何使用 Java 在 Cassandra 中检索表名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42469341/