使用Astyanax查询前缀不工作的列 [英] Querying columns with prefix not working using Astyanax

查看:3364
本文介绍了使用Astyanax查询前缀不工作的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方案如下:


  • TimeStamp

  • 设备ID

  • 设备名称

  • 设备所有者

  • 设备位置

  • TimeStamp
  • Device ID
  • Device Name
  • Device Owner
  • Device location

我使用CQL创建了这个列族,并将主键定义为(TimeStamp,Device ID,Device Name)。通过一个可序列化对象,其中包含DeviceID,名称和字段名称的字段(存储设备所有者设备位置 )。我已经使用Astyanax插入了一些记录。

I have created this column family using CQL and defined the primary key as (TimeStamp,Device ID, Device Name). Through a serializable object that has fields for DeviceID, name and a field name (which stores either Device Owner or Device Location). I have inserted some records using Astyanax.

根据我的理解,一行的列是通过组合设备ID 设备名称和字段名称作为列名称,值为该特定字段的值。
因此,对于特定的时间戳和设备,列名将在模式(设备ID:设备名:...)中。

As per my understanding, the columns for a row are created by combining Device ID, Device Name and field name as column name and the value to be the value for that particular field. Thus for a particular timestamp and device, the column names would be in the pattern (Device ID:Device Name: ...).

所以我相信我们可以使用这两个字段作为前缀来获取特定时间设备组合的所有条目。

So I believe we can use these 2 fields as prefix to obtain all the entries for a particular time-device combination.

I我使用以下查询来获得结果:

I am using the following query to obtain the results:

  RowSliceQuery<String, ApBaseData> query = adu.keyspace
  .prepareQuery(columnFamily)
  .getKeySlice(timeStamp)
  .withColumnRange(new RangeBuilder()
   .setStart(deviceID+deviceName+"_\u00000")
   .setEnd(deviceID+deviceName+"_\uffff")
   .setLimit(batch_size)
   .build());

但是执行上面的查询我得到以下异常:

But on executing the above query I get the following Exception:


BadRequestException:[host = localhost(127.0.0.1):9160,latency = 6(6),attempts = 1] InvalidRequestException(为什么:没有足够的字节读取组件的值0)

BadRequestException: [host=localhost(127.0.0.1):9160, latency=6(6), attempts=1]InvalidRequestException(why:Not enough bytes to read value of component 0)

@abhi我可以在此列族中的数据如下:

@abhi The data I can have in this column family is as follows:

    stime    |  devName  | devId | Owner | Location
  1361260800 | dev:01:02 |   1   | 1234  |    1  
  1361260800 | dev:02:03 |   2   | 34    |    2
  1361260800 | dev:05:06 |   1   | 12    |    1
  1361260800 | dev:03:02 |   2   | 56    |    3

我使用的java seriazable java类是:

The java seriazable java class that I am using for this is:

public class BaseData implements Serializable {
    private static final long serialVersionUID = 1L;
    @Component(ordinal = 0)
    private String devName;
    @Component(ordinal = 1)
    private int devID;
    @Component(ordinal = 2)
    private String field;
}

按照上述类的结构,我可以看到列族中的列:
Columne名称:dev\:01\:02:1:location列值:00000001

Following the structure of the above class I can see columns in the column family as : Columne Name: dev\:01\:02:1:location Column Value: 00000001

FYI使用astyanax 1.56.31

FYI using astyanax 1.56.31

推荐答案

为了克服这个问题,我改变了我在表中存储数据的方式。而不是使用复合主键,我改变了模式,以便只有单个主键和动态列。所以,现在我有stime的主键,我的列名称是动态显式构建我的插入代码。例如。 dev\:01:\\:02:1:location与之前相同的方式,但这已经完全消除了序列化对象的需要。这已经解决了我的问题,现在。让我们看看以后会有什么问题。

To overcome this problem, I changed the way I was storing data in the table. Instead of using a composite primary key, I changed the schema so as to have only single primary key and dynamic columns. So, now I have primary key on stime and my column names are constructed dynamically explicitly by my insertion code. For eg. "dev\:01\:02:1:location" the same way they were before but this has completely eliminated the need of a serialized object. This has solved my problem as of now. Lets see what problems it poses later.

这篇关于使用Astyanax查询前缀不工作的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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