英文:
How do I update a column value and set a TTL for the whole row?
问题
I'm trying to update a column value (not key column) and to set a new TTL for the whole row. But when I execute the generated statement, only the column TTL was updated, and the other columns remain with the original values, producing NULL values in future reads.
My app was written in Java and uses DataStax for querying. The function for generating the statement is something like this:
private Statement updateLastActivityStatement(int ttl, Long ts){
return QueryBuilder.update(KEY_SPACE, TABLE_NAME)
.with(QueryBuilder.set(LAST_ACTIVITY, ts))
.where(QueryBuilder.eq(ENTRY_ID, userA))
.and(QueryBuilder.eq(ID, userB))
.using(QueryBuilder.ttl(ttl));
}
英文:
i'm trying to update a column value (not key column) and to set new TTL for the whole row.
But when i execute the generated statement, only column ttl was updates and the other columns remain with the original, producing NULL values in future reads.
My app was written in Java and using datastax for querying, and the function for generating the statement is something like this.
private Statement updateLastActivityStatement(int ttl, Long ts){
return QueryBuilder.update(KEY_SPACE, TABLE_NAME)
.with(QueryBuilder.set(LAST_ACTIVITY, ts))
.where(QueryBuilder.eq(ENTRY_ID, userA))
.and(QueryBuilder.eq(ID, userB))
.using(QueryBuilder.ttl(ttl));
}
答案1
得分: 1
TTL与特定单元绑定,因此当您仅更新特定列时,只有这些列会被更新。要更新所有内容,您需要更新所有值。
英文:
TTL is bound to a specific cell, so when you're updating only specific columns, then only them are updated. To update everything, you need to update all values
答案2
得分: 1
TTL 仅适用于语句中的列,不适用于行中的所有列,也不适用于分区中的所有行。
我能想到的唯一解决方法是使用 default_time_to_live
选项在表上设置默认 TTL。祝好运!
英文:
The TTL only applies to the columns in the statement, not to all the columns in the row nor all the rows in the partition.
The only workaround I could think of is to set a default TTL on the table using the default_time_to_live
option. Cheers!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论