How to save binary blob data?

148 views
Skip to first unread message

John Smart

unread,
Aug 14, 2014, 8:48:22 PM8/14/14
to ceq...@googlegroups.com
I'm using MessagePack to marshal binary data, and I would like to persist it in Cassandra using Cequel:

require 'msgpack'

class KvIdx
  include Cequel::Record
  key :k, :text
  key :s, :text, order: :asc
  column :v, :blob
end

KvIdx.synchronize_schema

KvIdx.create!({
  :k => 'foo',
  :s => 'bar',
  :v => MessagePack.pack '1234'
})

Result:

Cql::QueryError: Invalid STRING constant (�1234) for v of type blob
    vendor/bundle/ruby/2.1.0/gems/cql-rb-2.0.1/lib/cql/client/client.rb:545:in `execute'
    vendor/bundle/ruby/2.1.0/gems/cequel-1.4.1/lib/cequel/metal/keyspace.rb:178:in `block in execute_with_consistency'

Matthew A. Brown

unread,
Aug 15, 2014, 8:46:34 AM8/15/14
to John Smart, ceq...@googlegroups.com
Odd. Cequel should cast the data to the correct Ruby object type for a blob column when you set the attribute. Can you paste the CQL that it generates?
--
You received this message because you are subscribed to the Google Groups "Cequel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cequel+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Smart

unread,
Aug 15, 2014, 4:57:52 PM8/15/14
to Matthew A. Brown, ceq...@googlegroups.com
figma-db[20711]: CQL (ERROR) INSERT INTO kv_idxes (k, s, v) VALUES ('foo', 'bar', '¤1234')

Matthew A. Brown

unread,
Aug 15, 2014, 7:58:10 PM8/15/14
to John Smart, ceq...@googlegroups.com
What happens if you do:

KvIdx.create!({
  :k => 'foo',
  :s => 'bar',
  :v => MessagePack.pack('1234').force_encoding('ASCII-8BIT')
})
Reply all
Reply to author
Forward
0 new messages