class OrangeLib::CassandraHandler

Public Class Methods

new(host, key_space) click to toggle source

Initialize a connection to cassandra @param [String] host ip address of the cassandra host @param [String] key_space the key_space for connection to cassandra host @return [Session] Cassandra session. @example

@__cassandra_handler ||= HMS::CassandraHandler.new('localhost', 'halo_test')
# File lib/orange_lib/cassandra_handler.rb, line 12
def initialize(host, key_space)
  cluster = Cassandra.cluster(hosts: [host])
  @session  = cluster.connect(key_space)
end

Public Instance Methods

execute(sql_string) click to toggle source

Execute a sql statement. @param [String] sql_string the sql statement you would like to execute @return [Cassandra::Result] @example

cassandra_handler ||= HMS::CassandraHandler.new('localhost', 'halo_test')
sql = "SELECT count(*) FROM data WHERE uid in ('#{items_list}')"
result = cassandra_handler.execute(sql)
result.rows.each do |row|
num_rows = row["count"]

end

# File lib/orange_lib/cassandra_handler.rb, line 27
def execute(sql_string)
  @session.execute(sql_string)
end