Search in sources :

Example 96 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath 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 97 with QueryPath

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

the class SliceByNamesReadCommandSerializer method deserialize.

public SliceByNamesReadCommand deserialize(DataInput dis, int version) throws IOException {
    boolean isDigest = dis.readBoolean();
    String table = dis.readUTF();
    ByteBuffer key = ByteBufferUtil.readWithShortLength(dis);
    QueryPath columnParent = QueryPath.deserialize(dis);
    int size = dis.readInt();
    List<ByteBuffer> columns = new ArrayList<ByteBuffer>();
    for (int i = 0; i < size; ++i) {
        columns.add(ByteBufferUtil.readWithShortLength(dis));
    }
    SliceByNamesReadCommand command = new SliceByNamesReadCommand(table, key, columnParent, columns);
    command.setDigestQuery(isDigest);
    return command;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) ByteBuffer(java.nio.ByteBuffer)

Example 98 with QueryPath

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

the class LongTableTest method testGetRowMultiColumn.

@Test
public void testGetRowMultiColumn() throws Throwable {
    final Table table = Table.open("Keyspace1");
    final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Standard1");
    for (int i = 1; i < 5000; i += 100) {
        RowMutation rm = new RowMutation("Keyspace1", Util.dk("key" + i).key);
        ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1");
        for (int j = 0; j < i; j++) cf.addColumn(column("c" + j, "v" + j, 1L));
        rm.add(cf);
        rm.applyUnsafe();
    }
    Runnable verify = new WrappedRunnable() {

        public void runMayThrow() throws Exception {
            ColumnFamily cf;
            for (int i = 1; i < 5000; i += 100) {
                for (int j = 0; j < i; j++) {
                    cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key" + i), new QueryPath("Standard1"), ByteBufferUtil.bytes("c" + j)));
                    TableTest.assertColumns(cf, "c" + j);
                }
            }
        }
    };
    TableTest.reTest(table.getColumnFamilyStore("Standard1"), verify);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) Test(org.junit.Test)

Example 99 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath 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 100 with QueryPath

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

the class SSTableExportTest method testExportSuperCf.

@Test
public void testExportSuperCf() throws IOException {
    File tempSS = tempSSTableFile("Keyspace1", "Super4");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Super4");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // Add rowA
    cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superA"), ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis());
    writer.append(Util.dk("rowA"), cfamily);
    cfamily.clear();
    // Add rowB
    cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superB"), ByteBufferUtil.bytes("colB")), ByteBufferUtil.bytes("valB"), System.currentTimeMillis());
    writer.append(Util.dk("rowB"), cfamily);
    cfamily.clear();
    // Add rowExclude
    cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superX"), ByteBufferUtil.bytes("colX")), ByteBufferUtil.bytes("valX"), System.currentTimeMillis());
    writer.append(Util.dk("rowExclude"), cfamily);
    cfamily.clear();
    SSTableReader reader = writer.closeAndOpenReader();
    // Export to JSON and verify
    File tempJson = File.createTempFile("Super4", ".json");
    SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[] { asHex("rowExclude") });
    JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
    JSONObject rowA = (JSONObject) json.get(asHex("rowA"));
    JSONObject superA = (JSONObject) rowA.get(cfamily.getComparator().getString(ByteBufferUtil.bytes("superA")));
    JSONArray subColumns = (JSONArray) superA.get("subColumns");
    JSONArray colA = (JSONArray) subColumns.get(0);
    JSONObject rowExclude = (JSONObject) json.get(asHex("rowExclude"));
    assert hexToBytes((String) colA.get(1)).equals(ByteBufferUtil.bytes("valA"));
    assert colA.size() == 3;
    assert rowExclude == null;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) PrintStream(java.io.PrintStream) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) JSONObject(org.json.simple.JSONObject) 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)

Aggregations

QueryPath (org.apache.cassandra.db.filter.QueryPath)127 Test (org.junit.Test)67 ByteBuffer (java.nio.ByteBuffer)40 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)22 ColumnFamily (org.apache.cassandra.db.ColumnFamily)14 RowMutation (org.apache.cassandra.db.RowMutation)12 File (java.io.File)10 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 IOException (java.io.IOException)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 Table (org.apache.cassandra.db.Table)8 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)8 WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)8 ArrayList (java.util.ArrayList)5 IColumn (org.apache.cassandra.db.IColumn)5 PrintStream (java.io.PrintStream)4 UnknownHostException (java.net.UnknownHostException)4 HashSet (java.util.HashSet)4 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)4