读取具有不同值类型的列 [英] Reading columns with different valuetypes

查看:136
本文介绍了读取具有不同值类型的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Long,String,String>表示键类型为long,列名为string,列值为string。当我使用QueryResult< ColumnSlice String,String>>我可以得到所有的列,但键是长的,所以必须有一个值为long类型的列。我有点困惑,看看类型安全是如何工作在这里(因为查询结果将得到一个列类型)。
此外,如果有一个值类型不是string的列,那么就会出现问题。

A SliceQuery< Long, String, String > says the keytype is long, column name is string and column value is string. When I execute the slice query using QueryResult < ColumnSlice< String, String > > I can get all the columns, but the key is long so there must be a column whose value is long type. It's a bit confusing for me to see how type safety works here(since query result will get a column type ). Also, if there is a column with value type other than string, then problem must arise.

如何获得一个可用于查询的通用slicequery不同值类型的列?

How to have a generic slicequery that can be used to query columns of different value types ?

PS:我是cassandra / hector的新用户。

P.S : I am new to cassandra/hector.

>

推荐答案

几乎。第一种类型是您指出的行键的类型,但行键不存储为列。行键存储在一些其他特殊的地方。这就是那些来自关系数据库世界(像我)的人的行为之一。

Almost. The first type is the type of the row key as you point out, but the row key is not stored as a column. The row key is stored off in some other special place. This is one of those gotcha's that folks coming from the relational DB world (like me) trip over.

至于如何管理不同类型的列值,有一个双管齐下的方法。首先,将值存储为字节数组,然后自己序列化。第二,你关闭列名称告诉你哪个列 - 因此哪个值类型 - 你正在处理。一旦你知道正确的类型,你可以使用适当的序列化器将字节值反序列化成正确类型的变量。对于你自己的复杂对象和特殊类型,你可以编写自己的序列化程序。

As for how to manage column values with different types, there's a two-pronged approach. First, you store the value as a byte array and serialize it yourself. Second, you key off of the column name to tell you which column - and therefore which value type - you're dealing with. Once you know the correct type you can use the appropriate Serializer to deserialize the byte value into a variable of the correct type. For your own complex objects and special types, you can write your own serializers.

这篇关于读取具有不同值类型的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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