我有Cassandra(版本2.2.3)数据库的奇怪问题,并使用发送资金功能编写简单应用程序的概念证明时使用静态列。无法更新cassandra中的静态列
我的表是:
CREATE TABLE transactions (
profile text,
timestamp timestamp,
amount text,
balance text,
lock int static,
PRIMARY KEY (profile, timestamp)) WITH CLUSTERING ORDER BY (timestamp ASC);
第一步我添加新的记录
INSERT INTO transactions (profile, timestamp, amount) VALUES ('test_profile', '2015-11-05 15:20:01+0000', '10USD');
然后我想“锁定”当前用户的交易做一些动作与他的平衡。我尝试执行此请求:
UPDATE transactions SET lock = 1 WHERE profile = 'test_profile' IF lock = null;
但作为结果cqlsh我看到
[applied]
-----------
False
我不明白为什么“假”,因为轮廓当前数据是:
profile | timestamp | lock | amount | balance
--------------+--------------------------+------+--------+---------
test_profile | 2015-11-05 15:20:01+0000 | null | 10USD | null
任何想法我做错了什么?
UPDATE
读内纳德Bozic医师的回答后,我改变我的例子来阐明为什么我需要更新条件。完整的代码示例
CREATE TABLE transactions (
profile text,
timestamp timestamp,
amount text,
balance text,
lock int static,
balances map<text,text> static,
PRIMARY KEY (profile, timestamp)
) WITH CLUSTERING ORDER BY (timestamp ASC);
INSERT INTO transactions (profile, timestamp, amount) VALUES ('test_profile', '2015-11-05 15:20:01+0000', '1USD');
INSERT INTO transactions (profile, lock) VALUES ('test_profile', 1) IF NOT EXISTS;
BEGIN BATCH
UPDATE transactions SET balances={'USD':'1USD'} WHERE profile='test_profile';
UPDATE transactions SET balance='1USD' WHERE profile='test_profile' AND timestamp='2015-11-05 15:20:01+0000';
DELETE lock FROM transactions WHERE profile='test_profile';
APPLY BATCH;
如果我尝试再次获得锁我得到
INSERT INTO transactions (profile, lock) VALUES ('test_profile', 1) IF NOT EXISTS;
[applied] | profile | timestamp | balances | lock | amount | balance
-----------+--------------+-----------+-----------------+------+--------+---------
False | test_profile | null | {'USD': '1USD'} | null | null | null
可能是相同的问题https://issues.apache.org/jira/browse/CASSANDRA-10532 –
我在'考cassandra 3.0.0-rc2'和它的工作原理...但不能在其他版本中工作... – greenhost87