我需要在Cassandra ColumnFamily中创建CompositeColumns。

每个列的值将存储类似以下内容的内容-

user-id   column1
123      (Column1-Value  Column1-SchemaName  LastModifiedDate)


与column2和其他列相同。所以我决定采用这样的方式-

以下是各栏的说明-

ByteType for Column-Value
UTF8Type for Column-SchemaName
DateType for LastModifiedDate


我像这样创建了以下专栏家庭-

create column family USER_DATA
with key_validation_class = 'UTF8Type'
and comparator = 'CompositeType(ByteType,UTF8Type,DateType)'
and default_validation_class = 'UTF8Type'
and gc_grace = 86400
and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];


让我知道这是创建上述列族的正确方法吗?

但是,一旦我尝试执行上面的列,我总是会收到以下错误。

[default@userks]     create column family USER_DATA
...         with key_validation_class = 'UTF8Type'
...         and comparator = 'CompositeType(ByteType,UTF8Type,DateType)'
...         and default_validation_class = 'UTF8Type'
...         and gc_grace = 86400
...         and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];

java.lang.RuntimeException: Unknown comparator 'CompositeType(ByteType,UTF8Type,DateType)'. Available functions: bytes, integer, long, int, lexicaluui
d, timeuuid, utf8, ascii, double, countercolumn.


有人可以帮我吗?

更新:-

我只是发现了该错误,我忘记在ByteType中添加额外的s

以下是ColumnFamily-

create column family USER_DATA
with key_validation_class = 'UTF8Type'
and comparator = 'CompositeType(BytesType,UTF8Type,DateType)'
and default_validation_class = 'UTF8Type'
and gc_grace = 86400
and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];


以下是我得到的错误。

[default@beprofileks]     create column family USER_DATA
...         with key_validation_class = 'UTF8Type'
...         and comparator = 'CompositeType(BytesType,UTF8Type,DateType)'
...         and default_validation_class = 'UTF8Type'
...         and gc_grace = 86400
...         and column_metadata = [ {column_name : 'lmd', validation_class : DateType}];

java.lang.RuntimeException: org.apache.cassandra.db.marshal.MarshalException: cannot parse 'lmd' as hex bytes

最佳答案

它应该是BytesType,而不是ByteType

CompositeType(BytesType,UTF8Type,DateType)


另一个问题是lmd对于比较器CompositeType(BytesType,UTF8Type,DateType)不是有效的列名。有效名称是例如aa00:string:2013-09-19

10-02 16:05