Datetime 与卡桑德拉一起使用日期
我刚刚开始我的冒险与卡桑德拉数据库。我已经学了一些基础知识,但我仍然不明白如何在卡桑德拉处理日期 例如,在MySQL中,我们有一个字段的datetime类型,我们可以查询(例如)创建日期小于2010-01-01的所有字段。此外,我们可以按创建日期字段对结果进行排序 我们如何用卡桑德拉实现同样的目标?如何定义相应的列族以及如何查询(CQL)它以获得相同的结果?您可以使用type在列族中定义DateType类型的列。您应该认真阅读这篇文章,它有如何进行范围查询的描述和示例(即creationdate<2010-01-01)。对于订购,您可以参考,但这可能已经包含在cassandra客户端中。您可能需要查看cassandra来执行查询 这是一个关于如何使用hector客户端在cassandra中执行查询的片段Datetime 与卡桑德拉一起使用日期,datetime,date,cassandra,Datetime,Date,Cassandra,我刚刚开始我的冒险与卡桑德拉数据库。我已经学了一些基础知识,但我仍然不明白如何在卡桑德拉处理日期 例如,在MySQL中,我们有一个字段的datetime类型,我们可以查询(例如)创建日期小于2010-01-01的所有字段。此外,我们可以按创建日期字段对结果进行排序 我们如何用卡桑德拉实现同样的目标?如何定义相应的列族以及如何查询(CQL)它以获得相同的结果?您可以使用type在列族中定义DateType类型的列。您应该认真阅读这篇文章,它有如何进行范围查询的描述和示例(即creationdate
// 2010-01-01
Date date = new Date(1262275200L);
try
{
getConnection();
IndexedSlicesQuery<String, String, String> indexedSlicesQuery = HFactory.createIndexedSlicesQuery(keyspace, ss, ss, ss);
indexedSlicesQuery.setColumnNames("name");
indexedSlicesQuery.addLtExpression("timestamp", ByteBufferUtil.string(date_s.toByteBuffer(date)));
indexedSlicesQuery.addEqualsExpression("searchall", ByteBufferUtil.string(bs.toByteBuffer(true)));
indexedSlicesQuery.setColumnFamily(column_family);
indexedSlicesQuery.setStartKey("");
System.out.println(indexedSlicesQuery.toString());
QueryResult<OrderedRows<String, String, String>> res = indexedSlicesQuery.execute();
List<Row<String, String, String>> list = res.get().getList();
for (Row<?, ?, ?> row : list)
{
System.out.println(row.getKey());
}
}
//2010-01-01
日期=新日期(1262275200L);
尝试
{
getConnection();
indexedlicesquery indexedlicesquery=HFactory.createindexedlicesquery(键空间,ss,ss,ss);
setColumnNames(“名称”);
indexedlicesquery.addLtExpression(“timestamp”,ByteBufferUtil.string(date_.s.toByteBuffer(date)));
addequalexpression(“searchall”,ByteBufferUtil.string(bs.toByteBuffer(true));
indexedlicesquery.setColumnFamily(column_family);
IndexedLicesQuery.setStartKey(“”);
System.out.println(indexedlicesquery.toString());
QueryResult res=indexedlicesquery.execute();
List List=res.get().getList();
用于(行:列表)
{
System.out.println(row.getKey());
}
}