Skip to content

Commit

Permalink
Merge branch 'aqua_13_1_acu70514_binary_string_encoding'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Spataro committed Dec 27, 2012
2 parents 9cca2b9 + af323af commit c57718d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pkg
*.rbc
.redcar
.idea
doc/
.yardoc/
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PATH
cassandra (0.12.1)
json
rake
simple_uuid (>= 0.1.0)
simple_uuid (>= 0.2.0)
thrift_client (>= 0.7.0)

GEM
Expand All @@ -19,16 +19,16 @@ GEM
rubyforge (>= 2.0.4)
eventmachine (0.12.10)
gemcutter (0.7.0)
json (1.5.3)
json (1.7.5)
json_pure (1.5.3)
rake (0.9.2)
rdoc (3.8)
rubyforge (2.0.4)
json_pure (>= 1.1.7)
simple_uuid (0.2.0)
thrift (0.7.0)
thrift_client (0.7.0)
thrift (~> 0.7.0)
simple_uuid (0.3.0)
thrift (0.8.0)
thrift_client (0.8.2)
thrift (~> 0.8.0)

PLATFORMS
ruby
Expand Down
4 changes: 2 additions & 2 deletions lib/cassandra/columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def _standard_insert_mutation(column_family, column_name, value, timestamp, ttl
CassandraThrift::Mutation.new(
:column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
:column => CassandraThrift::Column.new(
:name => column_name_class(column_family).new(column_name).to_s,
:value => value,
:name => Cassandra::Helpers.convert_to_string_with_encoding(column_name_class(column_family).new(column_name)),
:value => Cassandra::Helpers.convert_to_string_with_encoding(value),
:timestamp => timestamp,
:ttl => ttl
)
Expand Down
19 changes: 18 additions & 1 deletion lib/cassandra/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
class Cassandra
module Helpers
# TODO Aqua remove this helper and its callers when thrift 0.9.1
# is released with bugfixes about BINARY strings
def self.convert_to_string_with_encoding(object)
case object
when SimpleUUID::UUID
# Due to a bug in Thrift 0.9.0, we must pretend like
# UUID byte-vectors (BINARY encoded Strings) are
# UTF-8 encoded, otherwise thrift tries to transcode
# to UTF-8 which is not kosher.
object.to_s.force_encoding(Encoding::UTF_8)
else
# All other strings can be passed with natural encoding
# (UTF-8, or any encoding that can be transcoded to it).
object.to_s
end
end

def extract_and_validate_params(column_family, keys, args, options)
options = options.dup
column_family = column_family.to_s
Expand Down Expand Up @@ -34,7 +51,7 @@ def s_map(el, klass)
when Array then el.map { |i| s_map(i, klass) }
when NilClass then nil
else
klass.new(el).to_s
Cassandra::Helpers.convert_to_string_with_encoding(klass.new(el))
end
end
end
Expand Down

0 comments on commit c57718d

Please sign in to comment.