如何为文件输入和输出创建表(列族)

时间:2013-06-21 05:31:15

标签: cassandra

how to read file from cassandra and write file to cassandra?

从上面的链接,我找到了用Cassandra读写文件的方法,但我不知道表格的结构。

下面的代码是将文件插入Cassandra的方法。我猜filenamefile 是两列(它是“文件名”主键吗?)。我们写fileCREATE TABLE (...,...,...)的类型是什么。“blob”好吗?

 ByteBuffer fileByteBuffer = ByteBuffer.wrap( readFileToByteArray( filename ) );
 Statement insertFile = QueryBuilder.insertInto( "files" ).value( "filename", filename ).value( "file", fileByteBuffer );
    session.execute( insertFile );

我创建了columnfamily:

            "CREATE TABLE " + columnfamily + " ("
            + PK+ " varchar PRIMARY KEY," 
            + " password varchar ,"
            + " file blob"
            + ");";

我查询:

 Statement insertFile = QueryBuilder.insertInto(keyspace + "."+columnfamily)
 .value(PK, "LDCR.lua").value("file", fileByteBuffer).value("password", "654321");
 session.execute(insertFile);

但它说:

com.datastax.driver.core.exceptions.InvalidQueryException:unconfigured columnfamily

0 个答案:

没有答案