Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with blob on cassandra 2.0 CQL 3.1 #69

Open
psachs opened this issue Mar 4, 2014 · 0 comments
Open

Working with blob on cassandra 2.0 CQL 3.1 #69

psachs opened this issue Mar 4, 2014 · 0 comments

Comments

@psachs
Copy link

psachs commented Mar 4, 2014

When I try to INSERT data as blob the adapter fails due to an incompatibility which is described here:
http://www.datastax.com/documentation/cql/3.0/cql/cql_reference/blob_r.html

The method cast_to_cql in lib/cassandra-cql/statement.rb:112
the conversion ruby escape(obj.unpack('H*')[0]) produces a string containing a hex number. Cassandra 2.0 requires a hex number 0x... when inserting a blob.

The referenced method:

    def self.cast_to_cql(obj)
      if obj.kind_of?(Array)
        obj.map { |member| cast_to_cql(member) }
      elsif obj.kind_of?(Hash)
        obj
      elsif obj.kind_of?(Numeric)
        obj
      elsif obj.kind_of?(Date)
        obj.strftime('%Y-%m-%d')
      elsif obj.kind_of?(Time)
        (obj.to_f * 1000).to_i
      elsif obj.kind_of?(SimpleUUID::UUID)
        obj
      elsif obj.kind_of?(TrueClass) or obj.kind_of?(FalseClass)
        obj
      # There are corner cases where this is an invalid assumption but they are extremely rare.
      # The alternative is to make the user pack the data on their own .. let's not do that until we have to
      elsif obj.kind_of?(String) and Utility.binary_data?(obj)
        escape(obj.unpack('H*')[0])
      else
        RUBY_VERSION >= "1.9" ? escape(obj.to_s.dup.force_encoding('ASCII-8BIT')) : escape(obj.to_s.dup)
      end
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant