【问题标题】:Cassandra: List all tables in keyspace based on restriction such as LIKE or CONTAINS?Cassandra:根据 LIKE 或 CONTAINS 等限制列出键空间中的所有表?
【发布时间】:2018-04-06 14:45:10
【问题描述】:

每个键空间有很多表,因此我想根据限制条件过滤表。我尝试了这个查询,但它并没有真正给出我想要的结果:

SELECT table_name FROM system_schema.tables 
WHERE keyspace_name = 'test' 
and table_name >= 'test_001_%';

显示的输出是:

'table_name'
---------------------
 'test_001_metadata'    
 'test_001_time1'    
 'test_001_time2'    
 'test_001_time3'    
 'test_001_time4'    
 'test_002_metadata'    
 'test_002_time1'    
 'test_002_time2'
 'test_002_time3'

我真正想要的是: 显示的输出是:

'table_name'
---------------------
 'test_001_metadata'    
 'test_001_time1'    
 'test_001_time2'    
 'test_001_time3'    
 'test_001_time4'   

另一种方法是通过在 table_name 上创建二级索引来使用 LIKE 关键字。但是我有点怀疑它是否会导致问题,因为它是一个系统表。另一个问题是,聚簇列是否真的支持二级索引?

【问题讨论】:

  • 虽然我不确定,但如果前面的查询有效,那么这也应该有效,SELECT table_name FROM system_schema.tables WHERE keyspace_name = 'test' and table_name >= 'test_001_%' and table_name <='test_002_%';

标签: cassandra cassandra-3.0


【解决方案1】:

删除前一个索引后,在table_name 列上创建一个模式为包含模式的SASI 索引并尝试查询为

SELECT table_name FROM system_schema.tables 
WHERE keyspace_name = 'test' 
and table_name LIKE '%test_001_%';

用包含模式创建SASI索引的命令如下:

CREATE CUSTOM INDEX ON system_schema.tables(table_name) 
USING 'org.apache.cassandra.index.sasi.SASIIndex' 
WITH OPTIONS = {'analyzer_class': 'org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer', 
'case_sensitive': 'false', 'tokenization_normalize_uppercase': 'true', 'mode': 'CONTAINS'} 

对于第二个问题,您不能对属于 PRIMARY KEY 的任何内容创建二级索引。

【讨论】:

    猜你喜欢
    • 2013-09-13
    • 1970-01-01
    • 2014-09-23
    • 2014-01-14
    • 2023-03-27
    • 2014-04-18
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多