I’m having problems reading data from Cassandra using the Cassandra Gem….
Here is my code:
require 'cassandra'
@states = {}
@client = Cassandra.new('Logs', "10.1.1.11:9160")
@client.get_range(:PlaybackStates) do |ckey,bb|
@states[bb["State"].to_sym] = key
end
pp @states
I get this:
{:DrmInit=>"\x00\x00\x00(",
:Buffering=>"\x00\x00\x00x",
:PreBuffering=>"\x00\x00\x002",
:Debug=>"\x00\x00\x016",
:FullScreen=>"\x00\x00\x01\x90",
:Seek=>"\x00\x00\x00\x96",
:LoadManifest=>"\x00\x00\x00\x14",
:Play=>"\x00\x00\x00d"}
This is what I expected:
{:DrmInit=>[40],
:Buffering=>[120],
:PreBuffering=>[50],
:Debug=>[310],
:FullScreen=>[400],
:Seek=>[150],
:LoadManifest=>[20],
:Play=>[100]}
I can get this result by doing this in code:
require 'cassandra'
@states = {}
@client = Cassandra.new('Logs', "10.1.1.11:9160")
@client.get_range(:PlaybackStates) do |ckey,bb|
@states[bb["State"].to_sym] = ckey.unpack("N*") # unpacking the string with N*
end
pp @states
I also get binary representations of TimeStamp & Date fields……
Am I doing something wrong?? Why are the datatypes not being converted by the GEM??
The cassandra gem from Twitter does not understand datatypes other than UTF8 at the moment. As a result it will interpret native integers and other datatypes as strings.
I recommend using the cassandra-cql gem instead. It provides full support for mapping native Cassandra datatypes to native Ruby types.
https://github.com/kreynolds/cassandra-cql
http://rubygems.org/gems/cassandra-cql