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\"}");
}
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;
}
Aggregations