質問

Getting

 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)

Schema:

{
  column_name: key, 
  validation_class: UTF8Type, 
  index_type: KEYS
}  where key is UUID generated 
as UUID key = UUIDGenerator.getInstance().generateRandomBasedUUID();

CLI Commands:

// 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}]; 
役に立ちましたか?

解決

If you are using CQL, it is best practice to create your column families with CQL too. It seems you've found a bug, since the resulting CQL schema is invalid (there are two columns called key):

CREATE TABLE newdata (
  key blob PRIMARY KEY,
  key text
);

However, if you want just one field that is indexed, you probably want the following schema:

CREATE TABLE newdata (
  key uuid PRIMARY KEY
);

Here, the primary key is of type UUID so a check is done that your key is a valid UUID. You can then insert with:

INSERT INTO newdata (key) VALUES (8768c481-a118-48b7-aed2-2903b917d045);

Then you can do lookups like:

SELECT * FROM newdata1 where key = 8768c481-a118-48b7-aed2-2903b917d045;

which will tell you if the UUID exists or not. You can add other columns later and retrieve them with the above SELECT query.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top