获得
cassandra error: cannot parse uuid as hex bytes`
java.sql.SQLSyntaxErrorException: cannot parse '8768c481-a118-48b7-aed2-2903b917d045' as hex bytes
at org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.doExecute(CassandraPreparedStatement.java:155)
at org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.execute(CassandraPreparedStatement.java:191)
at CassClass.main(CassClass.java:55)
架构:
{
column_name: key,
validation_class: UTF8Type,
index_type: KEYS
} where key is UUID generated
as UUID key = UUIDGenerator.getInstance().generateRandomBasedUUID();
CLI命令:
// Created column family with:
create column family newdata with comparator = UTF8Type;
// Then, updated the column family newdata with:
column_metadata =[{column_name: key, validation_class: UTF8Type, index_type: KEYS}];
答案 0 :(得分:1)
如果您使用的是CQL,最佳做法是使用CQL创建列族。您似乎发现了一个错误,因为生成的CQL架构无效(有两列名为key):
CREATE TABLE newdata (
key blob PRIMARY KEY,
key text
);
但是,如果您只想要索引一个字段,则可能需要以下架构:
CREATE TABLE newdata (
key uuid PRIMARY KEY
);
此处,主键的类型为UUID,因此检查您的密钥是否为有效的UUID。然后可以插入:
INSERT INTO newdata (key) VALUES (8768c481-a118-48b7-aed2-2903b917d045);
然后您可以执行以下查找:
SELECT * FROM newdata1 where key = 8768c481-a118-48b7-aed2-2903b917d045;
将告诉您UUID是否存在。您可以稍后添加其他列,并使用上述SELECT查询检索它们。