1

我有以下功能来检查列族中是否存在行键。我使用以下命令从 SELECT 语句中获取结果。索引 = db.execute("SELECT * FROM #{$configuration} WHERE key = '#{index_config}'")

我应该如何处理索引结果说上面的 select 语句什么也没找到?

我曾经使用“return false if index.size == 0”,但它不起作用。index.size 为 1,尽管现在找到了行。

我尝试检查“如果 index[1].to_s.empty 则返回 false?” 但它也不起作用。

def self.index_config_exists?(config, keyspace, columnfamily)
index_config = "#{keyspace}_#{columnfamily}_#{config}_idx"
db = CassandraCQL::Database.new($cassandra_host, {:keyspace => $indexing})
indexes = db.execute("SELECT * FROM #{$configuration} WHERE key = '#{index_config}'")
db.disconnect!()

indexes.fetch {|index|
  # check if the index configuration not empty
  puts index.to_s
  puts index[0]
  puts index[1].class
  return false if index[1].to_s.empty?
}

return true

结尾

4

0 回答 0