Cassandra数据存储
版本:0.7.6
客户端:cassandra自带的thrift客户端
标准column的查询、删除、新增:
?SuperColumn新增和查询:
/** * 插入SuperColumn * * @throws Exception */public void insertSuperColumn() throws Exception {TTransport tr = new TFramedTransport(new TSocket("localhost",9160)); TProtocol proto = new TBinaryProtocol(tr); Cassandra.Client client = new Cassandra.Client(proto); tr.open(); client.set_keyspace("Keyspace1");ColumnParent cp1 = new ColumnParent();cp1.setColumn_family("Super2");cp1.setSuper_column("address".getBytes());Column city = new Column();city.setName("province".getBytes());city.setValue("guangdong".getBytes());city.setTimestamp(time);client.insert(ByteBuffer.wrap("user2".getBytes()), cp1, city, ConsistencyLevel.ONE);}/** * 读取SuperColumn * * @throws Exception */public void getSuper() throws Exception {TTransport tr = new TFramedTransport(new TSocket("localhost",9160)); TProtocol proto = new TBinaryProtocol(tr); Cassandra.Client client = new Cassandra.Client(proto); tr.open(); client.set_keyspace("Keyspace1");ColumnPath path = new ColumnPath("Super2");path.setSuper_column("address".getBytes());path.setColumn("province".getBytes());ColumnOrSuperColumn s = client.get(ByteBuffer.wrap("user5".getBytes()), path, ConsistencyLevel.ONE);System.out.println(new String(s.column.getValue(), "utf8"));}
?困惑:如果superColumn下的Column是一个SuperColumn怎么插入数据?没有找到相关的api。