Astyanax getKey与复合键 [英] Astyanax getKey with compound key

查看:231
本文介绍了Astyanax getKey与复合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用复合主键运行以下代码。

I would like to run the following code with a compound primary key.

Column<String> result = keyspace.prepareQuery(CF_COUNTER1)
    .getKey(rowKey)
    .getColumn("Column1")
    .execute().getResult();
Long counterValue = result.getLongValue();

研究似乎表明它可以是一个代表一个键的字符串键)。 文档说,它的类型为 K ,唉,我不是很熟悉Java,不知道这是什么意思。它只是一个基本类型,很多东西继承自?如果是这样,我真的不知道为了处理复合键需要什么 getKey(K)

Research seems to show that it can be a string that represents a key (if it's not a compound primary key). The documentation says that it is of type K, alas, I am not very experience with Java, and have no idea what that means. Is it just a base type that lots of stuff inherits from? If so, I'm not really any closer to knowing what getKey(K) needs in order to handle a compound key (am I?).

推荐答案

您只需要编写一个适合数据模型中的列的类。

You just need to write a class that fits the columns in your data model. You can then give this class to Astyanax in your mutations or queries.

例如,如果你有一个像这样的数据模型

For example, if you had a data model like this

   CREATE TABLE fishblogs (
        userid varchar,
        when timestamp,
        fishtype varchar,
        blog varchar,
        image blob,
        PRIMARY KEY (userid, when, fishtype)
    );

您将创建如下类:

   public class FishBlog {
      @Component(ordinal = 0)
      public long when;
      @Component(ordinal = 1)
      public String fishtype;
      @Component(ordinal = 2)
      public String field;

      public FishBlog() {
      }
   }

fishtype 形成复合列键,并由 FishBlog 类表示。 Userid将是你的行/分区键,可以是简单的字符串类型。

When and fishtype form your composite column key and are represented by the FishBlog class. Userid would be your row/partition key and can be of the simple "string" type.

请查看这篇博客非常详细地解释了如何用复合键(我从这个例子中选择)插入数据。

Have a look at this blog explaining in great detail how to insert data with composite keys (where I took this example from).

希望帮助。

这篇关于Astyanax getKey与复合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆