好的,我在这里变得疯狂。我无法用Cassandra解释许多行为,我甚至不确定它们是否相关。
我按如下方式创建了一个表(为简洁起见,未显示所有列):
create column family cachekey
with comparator = UTF8Type
and column_metadata =
[
{
column_name : accountNumber,
validation_class : UTF8Type
},
{
column_name : homeId,
validation_class : LongType
}
...
];
有些记录被添加到该表中(不是我)。现在,当我显示架构时,我不确定为什么我看不到我创建的列
[default@cachekeydata] show schema;
...
use cachekeydata;
create column family cachekey
with column_type = 'Standard'
and comparator = 'UTF8Type'
and default_validation_class = 'BytesType'
and key_validation_class = 'BytesType'
and read_repair_chance = 0.1
and dclocal_read_repair_chance = 0.0
and gc_grace = 864000
and min_compaction_threshold = 4
and max_compaction_threshold = 32
and replicate_on_write = true
and compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'
and caching = 'KEYS_ONLY'
and compression_options = {'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor'};
现在,让我感到困惑的是:当我从我的java代码中提取数据时,我在尝试检索long时获得了空指针异常,但在检索某些记录的字符串时却没有:
System.out.println("Mac=" + mac);
System.out.println(" cidx=<" + result.getStringValue("homeId",null) + ">");
System.out.println(" cidx=<" + result.getLongValue("homeId",null) + ">");
System.out.println(" cidx=<" + result.getColumnByName("homeId").getLongValue() + ">");
导致:
Mac=001DD67CFF46
cidx=<50190074>
cidx=<3832617404583655220>
cidx=<3832617404583655220>
Mac=001DCFE2122C
cidx=<3663580>
后跟NullPointerException。换句话说,result.getStringValue(“homeId”,null)返回3663580但是在Cassandra库代码中运行以下行时result.getLongValue(“homeId”,null)会导致NullPointerException:
LongSerializer.get().fromBytes(column.getValue());
最后,从cli控制台显示上述相同的两条记录并没有向我显示任何可疑内容:
[default@cachekeydata] get cachekey[utf8('001DD67CFF46')];
=> (column=accountNumber, value=30373833373132303730323036, timestamp=1361305382124)
=> (column=corp, value=3037383337, timestamp=1361305382124)
=> (column=homeId, value=3530313930303734, timestamp=1361305382124)
=> (column=zip, value=3130343732, timestamp=1361305382124)
Returned 4 results.
Elapsed time: 70 msec(s).
[default@cachekeydata] get cachekey[utf8('001DCFE2122C')];
=> (column=accountNumber, value=30373830383132333437323032, timestamp=1361305376659)
=> (column=corp, value=3037383038, timestamp=1361305376659)
=> (column=homeId, value=33363633353830, timestamp=1361305376659)
=> (column=zip, value=3036393033, timestamp=1361305376659)
Returned 4 results.
Elapsed time: 45 msec(s).
我的问题:
答案 0 :(得分:0)
不确定答案对任何人都有用,但预期长的数据会以字符串形式插入。这显然导致了我上面解释的至少两个问题: