gpt4 book ai didi

ruby - Cassandra Ruby gem 获取列

转载 作者:太空宇宙 更新时间:2023-11-03 16:08:01 25 4
gpt4 key购买 nike

我从 ruby​​ gem 访问 cassandra。我想通过指定我想要的列来从 cassandra db 中检索数据。每当我运行这个

conn.get(:column_family, 'key1', [63,62])

我得到以下错误,

 TypeError: can't convert Array into String
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/gems/thrift-0.8.0/lib/thrift/transport/framed_transport.rb:84:in `write'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/gems/thrift-0.8.0/lib/thrift/protocol/binary_protocol.rb:112:in `write_string'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/gems/thrift-0.8.0/lib/thrift/client.rb:35:in `write'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/gems/thrift-0.8.0/lib/thrift/client.rb:35:in `send_message'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/bundler/gems/cassandra-7474449189f3/vendor/0.8/gen-rb/cassandra.rb:107:in `send_multiget_slice'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/bundler/gems/cassandra-7474449189f3/vendor/0.8/gen-rb/cassandra.rb:102:in `multiget_slice'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/bundler/gems/thrift_client-00893a3accc5/lib/thrift_client/abstract_thrift_client.rb:150:in `handled_proxy'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/bundler/gems/thrift_client-00893a3accc5/lib/thrift_client/abstract_thrift_client.rb:60:in `multiget_slice'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/bundler/gems/cassandra-7474449189f3/lib/cassandra/protocol.rb:64:in `_multiget'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/bundler/gems/cassandra-7474449189f3/lib/cassandra/cassandra.rb:619:in `multi_get'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/bundler/gems/cassandra-7474449189f3/lib/cassandra/cassandra.rb:592:in `get'
from (irb):5:in `block in irb_binding'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p180@spaghetti/gems/connection_pool-0.1.0/lib/connection_pool.rb:41:in `with'
from (irb):4
from /home/ubuntu/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'

python 包“pycassa”提供了指定要检索哪些列的选项。如何在 ruby 中做到这一点?

最佳答案

目前 .get().multi_get() 不接受列名列表。有一个 open issue for this on GitHub .作为解决方法,您可以改用 .get_columns()

conn.get_columns(:column_family, 'key1', [63,62])

这将返回一个值数组,其顺序与您为列名指定的顺序相同。或者,您可以使用 cassandra-cql gem:

handle.execute("select 63,62 from column_family where KEY = 'key1'").fetch

关于ruby - Cassandra Ruby gem 获取列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9568138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com