【发布时间】:2014-03-27 23:10:23
【问题描述】:
Datastax Cassandra C#驱动中的timeuuid是什么C#类型?
我正在编写一个简单的用户跟踪服务,并希望访问最新的用户历史记录。我正在尝试创建一个与此创建语句等效的表:
CREATE TABLE IF NOT EXISTS user_history (
user_id text,
event_type text,
create_date timeuuid,
item_id text,
PRIMARY KEY ((user_id, event_type), create_date)
);
我做了以下课程:
[AllowFiltering]
[Table("user_history")]
public class UserHistory
{
[PartitionKey(1)]
[Column("user_id")]
public string UserID;
[PartitionKey(2)]
[Column("event_type")]
public string EventType;
[ClusteringKey(1)]
[Column("create_date")]
public DateTime CreateDate { get; set; }
[Column("item_id")]
public string ItemID;
}
我正在使用这条语句在 Cassandra 中创建表:
var table = Session.GetTable<UserHistory>();
table.CreateIfNotExists();
但这给了我下表:
CREATE TABLE user_history (
user_id text,
event_type text,
create_date timestamp,
item_id text,
PRIMARY KEY ((user_id, event_type), create_date)
)
如您所见,create_date 的类型是timestamp,而不是timeuuid。
我尝试使用Guid 而不是DateTime,但是当我打电话给.CreateIfNotExists() 时,这给了我一个uuid。
我应该使用Guid 而不是DateTime 作为CreateDate 并使用原始CQL3 显式创建表吗?我想这将允许我从/向 Cassandra 读写 timeuuid(使用 FluentCassandra 项目中的 GuidGenerator)?! (回想一下:我正在使用 Datastax 驱动程序)
【问题讨论】:
-
你感受到对 Cassandra 的爱了吗?
-
是的。到目前为止,我喜欢数据模型。我已将 CreateDate 更改为 Guid,并使用原始 CQL 而不是 table.CreateIfNotExists() 创建了表。工作正常。
标签: c# cassandra driver datastax