我使用此代码将数据插入到cassandra数据库中,使用此代码:
mutator.addInsertion(key, columnfamily, HFactory
.createStringColumn(dataproperties.getObjectIDcolumnName(),
line.objectid));
mutator.addInsertion(key,columnfamily,
HFactory.createColumn(dataproperties.getNumtvaluecolomnname(), java.lang.Float.valueOf(value), StringSerializer.get(), FloatSerializer.get()));
numvalue colomn定义为FloatTYPE
我在代码执行方面没有错误,但是当我知道数据时Float值是错误的(我有这种值:C \ xb3 \ x00 \ x00,当我期望41.0) 正确插入字符串数据 如何从Hector正确插入数字数据以便进行正确的查询
谢谢。
答案 0 :(得分:0)
我认为您的列族定义中的问题,请尝试此
create column family columnfamily
with column_type = 'Standard'
and comparator = 'UTF8Type'
and default_validation_class = 'FloatType'
and key_validation_class = 'UTF8Type' ;
Insertion(key,columnfamily,
HFactory.createColumn(dataproperties.getNumtvaluecolomnname(),
java.lang.Float.valueOf(value), StringSerializer.get(),
me.prettyprint.cassandra.serializers.FloatSerializer.FloatSerializer.get()));
并获取数据
SliceQuery<String,String,byte[]> sliceQuery = HFactory.createSliceQuery(keyspace, se, se,BytesArraySerializer.get());
sliceQuery.setColumnFamily("columnfamily");
sliceQuery.setKey(key);
sliceQuery.setRange(null,null,true,10);
List<HColumn<String,byte[]>> hcolumns = sliceQuery.execute().get()
.getColumns();
for (HColumn<String, byte[]> hcolumn : hcolumns){
System.out.println("Name "+hcolumn.getName());
System.out.println("Value"+
FloatSerializer.get().fromBytes(hcolumn.getValue()));
}
FloatSerializer.get()。fromBytes(hcolumn.getValue())将值字节数组转换为float