Search in sources :

Example 21 with QueryFilter

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

the class SystemTable method isIndexBuilt.

public static boolean isIndexBuilt(String table, String indexName) {
    ColumnFamilyStore cfs = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(INDEX_CF);
    QueryFilter filter = QueryFilter.getNamesFilter(decorate(ByteBufferUtil.bytes(table)), new QueryPath(INDEX_CF), ByteBufferUtil.bytes(indexName));
    return ColumnFamilyStore.removeDeleted(cfs.getColumnFamily(filter), Integer.MAX_VALUE) != null;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter)

Example 22 with QueryFilter

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

the class SystemTable method getSavedToken.

public static Token getSavedToken() {
    Table table = Table.open(Table.SYSTEM_TABLE);
    QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCATION_KEY), new QueryPath(STATUS_CF), TOKEN);
    ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter);
    return cf == null ? null : StorageService.getPartitioner().getTokenFactory().fromByteArray(cf.getColumn(TOKEN).value());
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter)

Example 23 with QueryFilter

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

the class SSTableExportTest method testRoundTripStandardCf.

@Test
public void testRoundTripStandardCf() throws IOException, ParseException {
    File tempSS = tempSSTableFile("Keyspace1", "Standard1");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // Add rowA
    cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("name")), ByteBufferUtil.bytes("val"), System.currentTimeMillis());
    writer.append(Util.dk("rowA"), cfamily);
    cfamily.clear();
    // Add rowExclude
    cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("name")), ByteBufferUtil.bytes("val"), System.currentTimeMillis());
    writer.append(Util.dk("rowExclude"), cfamily);
    cfamily.clear();
    SSTableReader reader = writer.closeAndOpenReader();
    // Export to JSON and verify
    File tempJson = File.createTempFile("Standard1", ".json");
    SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[] { asHex("rowExclude") });
    // Import JSON to another SSTable file
    File tempSS2 = tempSSTableFile("Keyspace1", "Standard1");
    SSTableImport.importJson(tempJson.getPath(), "Keyspace1", "Standard1", tempSS2.getPath());
    reader = SSTableReader.open(Descriptor.fromFilename(tempSS2.getPath()));
    QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Standard1", null, null), ByteBufferUtil.bytes("name"));
    ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
    assertTrue(cf != null);
    assertTrue(cf.getColumn(ByteBufferUtil.bytes("name")).value().equals(hexToBytes("76616c")));
    qf = QueryFilter.getNamesFilter(Util.dk("rowExclude"), new QueryPath("Standard1", null, null), ByteBufferUtil.bytes("name"));
    cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
    assert cf == null;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) PrintStream(java.io.PrintStream) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 24 with QueryFilter

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

the class SSTableImportTest method testImportSuperCf.

@Test
public void testImportSuperCf() throws IOException, ParseException, URISyntaxException {
    String jsonUrl = resourcePath("SuperCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Super4");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Super4", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Super4", null, null), ByteBufferUtil.bytes("superA"));
    ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
    IColumn superCol = cf.getColumn(ByteBufferUtil.bytes("superA"));
    assert superCol != null;
    assert superCol.getSubColumns().size() > 0;
    IColumn subColumn = superCol.getSubColumn(ByteBufferUtil.bytes("636f6c4141"));
    assert subColumn.value().equals(hexToBytes("76616c75654141"));
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 25 with QueryFilter

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

the class SSTableImportTest method testImportCounterCf.

@Test
public void testImportCounterCf() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("CounterCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Counter1");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Counter1", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Counter1"));
    IColumnIterator iter = qf.getSSTableColumnIterator(reader);
    ColumnFamily cf = iter.getColumnFamily();
    while (iter.hasNext()) cf.addColumn(iter.next());
    IColumn c = cf.getColumn(ByteBufferUtil.bytes("colAA"));
    assert c instanceof CounterColumn : c;
    assert ((CounterColumn) c).total() == 42;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) CounterColumn(org.apache.cassandra.db.CounterColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Aggregations

QueryFilter (org.apache.cassandra.db.filter.QueryFilter)26 QueryPath (org.apache.cassandra.db.filter.QueryPath)22 ByteBuffer (java.nio.ByteBuffer)7 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)7 ColumnFamily (org.apache.cassandra.db.ColumnFamily)6 File (java.io.File)5 IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)5 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)5 Test (org.junit.Test)5 IColumn (org.apache.cassandra.db.IColumn)4 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 CloseableIterator (org.apache.cassandra.utils.CloseableIterator)3 ArrayList (java.util.ArrayList)2 ConfigurationException (org.apache.cassandra.config.ConfigurationException)2 DeletedColumn (org.apache.cassandra.db.DeletedColumn)2 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)2 NamesQueryFilter (org.apache.cassandra.db.filter.NamesQueryFilter)2 SliceQueryFilter (org.apache.cassandra.db.filter.SliceQueryFilter)2 Closeable (java.io.Closeable)1