Search in sources :

Example 6 with Column

use of org.apache.cassandra.db.Column in project eiger by wlloyd.

the class SSTableExportTest method testEscapingDoubleQuotes.

@Test
public void testEscapingDoubleQuotes() throws IOException {
    File tempSS = tempSSTableFile("Keyspace1", "ValuesWithQuotes");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "ValuesWithQuotes");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // Add rowA
    cfamily.addColumn(null, new Column(ByteBufferUtil.bytes("data"), UTF8Type.instance.fromString("{\"foo\":\"bar\"}")));
    writer.append(Util.dk("rowA"), cfamily);
    cfamily.clear();
    SSTableReader reader = writer.closeAndOpenReader();
    // Export to JSON and verify
    File tempJson = File.createTempFile("ValuesWithQuotes", ".json");
    SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
    JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
    JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
    JSONArray data = (JSONArray) rowA.get(0);
    assert hexToBytes((String) data.get(0)).equals(ByteBufferUtil.bytes("data"));
    assert data.get(1).equals("{\"foo\":\"bar\"}");
}
Also used : PrintStream(java.io.PrintStream) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) JSONObject(org.json.simple.JSONObject) Column(org.apache.cassandra.db.Column) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) CounterColumn(org.apache.cassandra.db.CounterColumn) SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) JSONArray(org.json.simple.JSONArray) FileReader(java.io.FileReader) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 7 with Column

use of org.apache.cassandra.db.Column in project eiger by wlloyd.

the class CassandraStorage method columnToTuple.

private Tuple columnToTuple(ByteBuffer name, IColumn col, CfDef cfDef) throws IOException {
    Tuple pair = TupleFactory.getInstance().newTuple(2);
    List<AbstractType> marshallers = getDefaultMarshallers(cfDef);
    Map<ByteBuffer, AbstractType> validators = getValidatorMap(cfDef);
    setTupleValue(pair, 0, marshallers.get(0).compose(name));
    if (col instanceof Column) {
        // standard
        if (validators.get(name) == null)
            setTupleValue(pair, 1, marshallers.get(1).compose(col.value()));
        else
            setTupleValue(pair, 1, validators.get(name).compose(col.value()));
        return pair;
    }
    // super
    ArrayList<Tuple> subcols = new ArrayList<Tuple>();
    for (IColumn subcol : col.getSubColumns()) subcols.add(columnToTuple(subcol.name(), subcol, cfDef));
    pair.set(1, new DefaultDataBag(subcols));
    return pair;
}
Also used : Column(org.apache.cassandra.db.Column) IColumn(org.apache.cassandra.db.IColumn) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) IColumn(org.apache.cassandra.db.IColumn) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Column (org.apache.cassandra.db.Column)7 IColumn (org.apache.cassandra.db.IColumn)6 ByteBuffer (java.nio.ByteBuffer)4 ColumnOrSuperColumn (org.apache.cassandra.thrift.ColumnOrSuperColumn)4 IOException (java.io.IOException)2 SuperColumn (org.apache.cassandra.db.SuperColumn)2 AbstractType (org.apache.cassandra.db.marshal.AbstractType)2 BytesType (org.apache.cassandra.db.marshal.BytesType)2 org.apache.cassandra.thrift (org.apache.cassandra.thrift)2 Deletion (org.apache.cassandra.thrift.Deletion)2 Mutation (org.apache.cassandra.thrift.Mutation)2 File (java.io.File)1 FileReader (java.io.FileReader)1 PrintStream (java.io.PrintStream)1 ColumnFamily (org.apache.cassandra.db.ColumnFamily)1 CounterColumn (org.apache.cassandra.db.CounterColumn)1 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)1 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)1 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)1 SSTableWriter (org.apache.cassandra.io.sstable.SSTableWriter)1