簡體   English   中英

Cassandra:根據限制(例如LIKE或CONTAINS)列出鍵空間中的所有表嗎?

[英]Cassandra: List all tables in keyspace based on restriction such as LIKE or CONTAINS?

每個鍵空間有很多表,因此我想根據限制條件過濾表。 我嘗試了此查詢,但實際上並沒有給出我想要的預期結果:

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關鍵字。 但是我有點懷疑是否會導致問題,因為它是系統表。 另一個問題是,群集列是否實際支持二級索引?

刪除先前的索引后,在table_name列上創建一個模式為包含在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任何內容上創建二級索引。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM