如何检查Cassandra表是否存在 [英] How to check if a Cassandra table exists

查看:2744
本文介绍了如何检查Cassandra表是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法来检查是否在Cassandra中使用CQL(或API,也许使用com.datastax.driver)定义表(列族)?

Is there an easy way to check if table (column family) is defined in Cassandra using CQL (or API perhaps, using com.datastax.driver)?

现在我倾向于执行 SELECT 1 FROM table 并检查异常,但也许有更好的方法?

Right now I am leaning towards executing SELECT 1 FROM table and checking for exception but maybe there is a better way?

推荐答案

从1.1开始,您应该可以查询系统键空间, schema_columnfamilies 列族。如果您知道要检查哪个键空间,此CQL应列出键空间中的所有列族:

As of 1.1 you should be able to query the system keyspace, schema_columnfamilies column family. If you know which keyspace you want to check, this CQL should list all column families in a keyspace:

SELECT columnfamily_name
FROM schema_columnfamilies WHERE keyspace_name='myKeyspaceName';

描述此功能的报告如下: https://issues.apache.org/jira/browse/CASSANDRA-2477

The report describing this functionality is here: https://issues.apache.org/jira/browse/CASSANDRA-2477

虽然,他们确实注意到一些系统列名称已在1.1和1.2之间更改。

Although, they do note that some of the system column names have changed between 1.1 and 1.2. So you might have to mess around with it a little to get your desired results.

编辑20160523 - Cassandra 3.x更新:

请注意,对于Cassandra 3.0及以上版本,您需要对上述查询进行一些调整:

Note that for Cassandra 3.0 and up, you'll need to make a few adjustments to the above query:

SELECT table_name 
FROM system_schema.tables WHERE keyspace_name='myKeyspaceName';

这篇关于如何检查Cassandra表是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆