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

如何在Cassandra(特别是CQLSH)中插入字符串或文本作为blob?,cassandra,cqlsh,Cassandra,Cqlsh,为了在CQLSH中进行测试,我尝试将文本或字符串作为blob插入 insert into test_by_score (commit, delta, test, score) values (textAsBlob('bdb14fbe076f6b94444c660e36a400151f26fc6f'), 0, textAsBlob('{"prefix": "enwiki", "title": "\"Aghnadarragh\""}'), 100); 它没有真正起作用,

为了在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中,从而在该位置插入字符串?

以下操作似乎有效。
SELECT
语句中的
WHERE
条件可能试图访问不正确的十六进制
0x0b5db8b91bfdeb0a30b372dd8dda123b3fd1ab6

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
);
抓住所有的行 选择特定的行。
你可以发布CQL模式吗?您是否使用程序来使用CQLSH插入Blob?或者您想通过CQLSH手动插入?我想手动插入文本。我的特定模式应该无关紧要。我的问题比较笼统。我有一个字符串,我想把它转换成一个blob,并将它插入到一个只包含blob的列中。这可以手动完成吗?我只是想澄清一下,您希望通过给定的查询重新创建问题……别担心,无论发生什么情况,尽可能清楚地回答问题总是很好的,这样对我和将来的任何人都很有用。:)我们不能在SELECT语句中也使用
textAsBlob()
吗?是的,您可以使用
blobAsType(value)
,请参见@AlexisWilke no,您需要
blobAsText()
SELECT * FROM example.test_by_score 
SELECT * FROM example.test_by_score 
  WHERE commit = 0x62646231346662653037366636623934343434633636306533366134303031353166323666633666;