【问题标题】:inserting from erlang into cassandra从erlang插入cassandra
【发布时间】:2011-09-16 09:22:23
【问题描述】:

我正在尝试从 Erlang R14B02(通过 thrift 0.6.1)向 cassandra 0.7.6 中插入一些东西

我正在做以下事情:

  1. 读取记录定义

    rr(cassandra_types).

  2. 连接到 cassandra

    {ok, C}=thrift_client_util:new("localhost", 9160, cassandra_thrift,[{strict_read, false}, {strict_write, false}, {framed, true}])。

  3. 尝试插入一个值(timestamp=1, 2=Quorum)

    Reply1 = thrift_client:call(C, 'insert', ["existing_keyspace", "new_key",#columnPath{column_family = "existing_column_family", column = "existing_column"}, "new_value",1,2])。

但是 nr3 给了我一个 bad_args 错误(1 和 2 完美地工作)。什么是正确的论点?

【问题讨论】:

  • Ups,我忘记了,抱歉,已编辑

标签: erlang cassandra thrift


【解决方案1】:

关于不受支持的语言的 API 信息主要在其Cassandra Thrift API documentation 中。

在 Cassandra 0.7 中,您不为大多数操作提供键空间,因此 insert 只需要 [Key, ColumnPath, Column, ConsistencyLevel]。在尝试插入之前,您需要致电 set_keyspace。 erlang中的插入将是

Reply1 = thrift_client:call(C, 'insert',
                            [SomeKey,
                             #columnPath{column_family = "existing_column_family",
                                         column = "existing_column"},
                             #column{name="existing_column",
                                     value="new_value",timestamp=1},
                             ?cassandra_ConsistencyLevel_QUORUM]).

我认为您的示例缺少插入的行键。

顺便说一句,请确保您始终更新 C 的值 - 它在每次 thrift_client 调用后都会更改。

?cassandra_ConsistencyLevel_QUORUM 是内存中的 2。

【讨论】:

  • I'm still getting bad_Args... 在您的通话中,列名被给出了两次,对吗?我的行键是“new_key”
  • 如果有人遇到同样的问题,这对我有用:{C22,_} = thrift_client:call(C21,'insert',["test_key",#columnParent{column_family=" exiting_CF"},#column{name="exiting_Column",value="new_val",timestamp=1},2])。
  • 顺便说一句。 erlang/thrift/cassandra 的最佳文档是为 erlang 生成的代码。至少你可以看看你有什么功能。
【解决方案2】:

这可能会有所帮助,尽管没有特定于 erlang 的代码:http://wiki.apache.org/cassandra/ThriftExamples

【讨论】:

    猜你喜欢
    • 2012-05-17
    • 1970-01-01
    • 2012-10-24
    • 2018-03-11
    • 2016-07-06
    • 2014-11-23
    • 2011-07-24
    • 2011-07-03
    • 1970-01-01
    相关资源
    最近更新 更多