iconara / cql-rb

Cassandra CQL 3 binary protocol driver for Ruby
106 stars 31 forks source link

v1.2.1: Encoding::CompatibilityError: ASCII-8BIT and UTF-8 #100

Closed adstage-david closed 10 years ago

adstage-david commented 10 years ago

Haven't upgrade to v2.0 yet, not sure if this still exists there, but I get the following UTF-8 related error when I have UTF-8 in a map:

Encoding::CompatibilityError: incompatible encodings: ASCII-8BIT and UTF-8
        org/jruby/RubyString.java:2601:in `concat'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/protocol/encoding.rb:58:in `write_short_bytes'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/protocol/type_converter.rb:326:in `varchar_to_bytes'
        org/jruby/RubyMethod.java:136:in `call'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/protocol/type_converter.rb:76:in `to_bytes'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/protocol/type_converter.rb:61:in `to_bytes'
        org/jruby/RubyHash.java:1339:in `each'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/protocol/type_converter.rb:60:in `to_bytes'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/protocol/requests/execute_request.rb:51:in `encode_body'
        org/jruby/RubyArray.java:1613:in `each'
        org/jruby/RubyEnumerable.java:977:in `each_with_index'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/protocol/requests/execute_request.rb:50:in `encode_body'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/protocol/requests/execute_request.rb:15:in `initialize'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/client/asynchronous_prepared_statement.rb:66:in `run'
        /home/david/.rvm/gems/jruby-1.7.12@metrics/gems/cql-rb-1.2.1/lib/cql/client/asynchronous_prepared_statement.rb:29:in `execute'

Seems related to #80, did a bit of digging and traced to a string being used instead of a byte buffer here:

https://github.com/iconara/cql-rb/blob/v1.2.1/lib/cql/protocol/type_converter.rb#L58

iconara commented 10 years ago

Thanks, I'll have a look. If you have a line of code, or a simple test case that helps.

iconara commented 10 years ago

I think I need an example schema and some data, I'm trying to figure out a way to trigger the error. You could also try using this branch and see if that fixes the problem.

I'll be a way for a few days, not sure if I will have time to release a new version until middle of next week.

adstage-david commented 10 years ago

Took a few tries to get a failing spec worked out, but switching to bytebuffers definitely fixes it. Made it into a pull request for you to easily pull it back in.

iconara commented 10 years ago

Fixed in v1.2.2