卡桑德拉SSTableLoader无法解码值

时间:2013-12-17 01:36:06

标签: cassandra

通过生成sSTables然后使用sstableloader加载数据来进行批量加载。

在查询加载的表上的数据时,主键数据无法解码。我看到下面的错误。

选择查询时出错(除了主键列正在正确呈现):

Failed to decode value '\xe4\xedQ\x9aX\x8dF\xab\x86\xf1\r\xe4]\xc3\x14C' (for column 'first_name') as text: 'utf8' codec can't decode byte 0xe4 in position 0: invalid continuation byte Failed to decode value '$q\x9d\x94P\xb9Ni\x9d);\xd0\x1d33~' (for column 'first_name') as text: 'utf8' codec can't decode byte 0x9d in position 2: invalid start byte

生成SSTables的代码:

SSTableSimpleUnsortedWriter eventWriter = new SSTableSimpleUnsortedWriter(directory, partitioner, keySpace, tableName, UTF8Type.instance,null, 64); eventWriter.addColumn(compType.builder().add(ByteBufferUtil.bytes("first_name")).build(), ByteBufferUtil.bytes(entry.firstName), timestamp); eventWriter.addColumn(compType.builder().add(ByteBufferUtil.bytes("last_name")).build(), ByteBufferUtil.bytes(entry.lastName), timestamp); eventWriter.addColumn(compType.builder().add(ByteBufferUtil.bytes("country")).build(), ByteBufferUtil.bytes(entry.countryText), timestamp);

表格定义:

CREATE TABLE test4 ( first_name varchar PRIMARY KEY, country text, last_name text, ) WITH bloom_filter_fp_chance=0.010000 AND caching='KEYS_ONLY' AND comment='' AND dclocal_read_repair_chance=0.000000 AND gc_grace_seconds=864000 AND read_repair_chance=0.100000 AND replicate_on_write='true' AND populate_io_cache_on_flush='false' AND compaction={'class': 'SizeTieredCompactionStrategy'} AND compression={'sstable_compression': 'LZ4Compressor'};

如何正确解码PrimaryKey?

1 个答案:

答案 0 :(得分:0)

此问题已解决。

不需要以下声明。这意味着,不需要单独添加主键列。

eventWriter.addColumn(compType.builder()。add(ByteBufferUtil.bytes(“first_name”))。build(),ByteBufferUtil.bytes(entry.firstName),timestamp);

创建新行时会添加它。

eventWriter.newRow(ByteBufferUtil.bytes(entry.firstName));