如何在Cassandra(特别是CQLSH)中插入字符串或文本作为blob?

问题描述 投票:9回答:1

我试图在CQLSH中插入文本或一些字符串作为blob用于测试目的

insert into test_by_score (commit, delta, test, score)
       values (textAsBlob('bdb14fbe076f6b94444c660e36a400151f26fc6f'), 0,
       textAsBlob('{"prefix": "enwiki", "title": "\"Aghnadarragh\""}'), 100);

它没有真正起作用,因为我做了之后:

select * from test_by_score where commit = 0x0b5db8b91bfdeb0a304b372dd8dda123b3fd1ab6;

它说有0列...这有点出乎意料(因为它没有向我抛出错误)但我猜textAsBlob不是cqlsh中的东西。那么有人知道怎么做吗?


架构:

CREATE TABLE IF NOT EXISTS test_by_score (
    commit blob, 
    delta int, 
    score int, 
    test blob, 
    PRIMARY KEY(commit, delta, test)
);

我已经不情愿地发布了我的架构,因为我相信我的问题并不是关于这个特定的架构。我只想知道的是,如果有一个列保存blob,是否可以通过首先将字符串更改为blob然后将其插入cqlsh来在该位置插入字符串?

cassandra cqlsh
1个回答
11
投票

以下似乎正在起作用。你的WHERE声明中的SELECT条件可能是试图访问不正确的十六进制0x0b5db8b91bfdeb0a304b372dd8dda123b3fd1ab6

DROP KEYSPACE example;
CREATE KEYSPACE example WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};
USE example;

CREATE TABLE IF NOT EXISTS test_by_score (
    commit blob, -- blob representing the commit hash
    delta int, -- how much the scores have changed
    score int, -- the test score, which is determined by the client
    test blob, -- blob for the test
    PRIMARY KEY(commit, delta, test)
);

INSERT INTO test_by_score  (commit, delta, test, score) VALUES 
  (textAsBlob('bdb14fbe076f6b94444c660e36a400151f26fc6f'), 0, textAsBlob('{"prefix": "enwiki", "title": "\"Aghnadarragh\""}'), 100
);

INSERT INTO test_by_score (commit, delta, test, score) VALUES (
  textAsBlob('cdb14fbe076f6b94444c660e36a400151f26fc6f'), 0, textAsBlob('{"prefix": "enwiki", "title": "\"Aghnadarragh\""}'), 100
);

INSERT INTO test_by_score (commit, delta, test, score) VALUES (
  textAsBlob('adb14fbe076f6b94444c660e36a400151f26fc6f'), 0, textAsBlob('{"prefix": "enwiki", "title": "\"Aghnadarragh\""}'), 100
);

To grab all the rows

SELECT * FROM example.test_by_score 

To select a specific row.

SELECT * FROM example.test_by_score 
  WHERE commit = 0x62646231346662653037366636623934343434633636306533366134303031353166323666633666;
© www.soinside.com 2019 - 2024. All rights reserved.