org.apache.cassandra.db.filter.NamesQueryFilter Java Examples

The following examples show how to use org.apache.cassandra.db.filter.NamesQueryFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CounterMutation.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void getCurrentValuesFromCFS(List<CounterUpdateCell> counterUpdateCells,
                                     ColumnFamilyStore cfs,
                                     ClockAndCount[] currentValues)
{
    SortedSet<CellName> names = new TreeSet<>(cfs.metadata.comparator);
    for (int i = 0; i < currentValues.length; i++)
        if (currentValues[i] == null)
            names.add(counterUpdateCells.get(i).name());

    ReadCommand cmd = new SliceByNamesReadCommand(getKeyspaceName(), key(), cfs.metadata.cfName, Long.MIN_VALUE, new NamesQueryFilter(names));
    Row row = cmd.getRow(cfs.keyspace);
    ColumnFamily cf = row == null ? null : row.cf;

    for (int i = 0; i < currentValues.length; i++)
    {
        if (currentValues[i] != null)
            continue;

        Cell cell = cf == null ? null : cf.getColumn(counterUpdateCells.get(i).name());
        if (cell == null || !cell.isLive()) // absent or a tombstone.
            currentValues[i] = ClockAndCount.BLANK;
        else
            currentValues[i] = CounterContext.instance().getLocalClockAndCount(cell.value());
    }
}
 
Example #2
Source File: ReadMessageTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetColumn()
{
    Keyspace keyspace = Keyspace.open("Keyspace1");
    CellNameType type = keyspace.getColumnFamilyStore("Standard1").getComparator();
    Mutation rm;
    DecoratedKey dk = Util.dk("key1");

    // add data
    rm = new Mutation("Keyspace1", dk.getKey());
    rm.add("Standard1", Util.cellname("Column1"), ByteBufferUtil.bytes("abcd"), 0);
    rm.apply();

    ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.getKey(), "Standard1", System.currentTimeMillis(), new NamesQueryFilter(FBUtilities.singleton(Util.cellname("Column1"), type)));
    Row row = command.getRow(keyspace);
    Cell col = row.cf.getColumn(Util.cellname("Column1"));
    assertEquals(col.value(), ByteBuffer.wrap("abcd".getBytes()));
}
 
Example #3
Source File: CassandraEmbeddedStoreManager.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private void retryDummyRead(String ks, String cf) throws PermanentBackendException {

        final long limit = System.currentTimeMillis() + (60L * 1000L);

        while (System.currentTimeMillis() < limit) {
            try {
                SortedSet<CellName> names = new TreeSet<>(new Comparator<CellName>() {
                    // This is a singleton set.  We need to define a comparator because SimpleDenseCellName is not
                    // comparable, but it doesn't have to be a useful comparator
                    @Override
                    public int compare(CellName o1, CellName o2)
                    {
                        return 0;
                    }
                });
                names.add(CellNames.simpleDense(ByteBufferUtil.zeroByteBuffer(1)));
                NamesQueryFilter nqf = new NamesQueryFilter(names);
                SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(ks, ByteBufferUtil.zeroByteBuffer(1), cf, 1L, nqf);
                StorageProxy.read(ImmutableList.<ReadCommand> of(cmd), ConsistencyLevel.QUORUM);
                log.info("Read on CF {} in KS {} succeeded", cf, ks);
                return;
            } catch (Throwable t) {
                log.warn("Failed to read CF {} in KS {} following creation", cf, ks, t);
            }

            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                throw new PermanentBackendException(e);
            }
        }

        throw new PermanentBackendException("Timed out while attempting to read CF " + cf + " in KS " + ks + " following creation");
    }
 
Example #4
Source File: CollationController.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public ColumnFamily getTopLevelColumns(boolean copyOnHeap)
{
    return filter.filter instanceof NamesQueryFilter
           && cfs.metadata.getDefaultValidator() != CounterColumnType.instance
           ? collectTimeOrderedData(copyOnHeap)
           : collectAllData(copyOnHeap);
}
 
Example #5
Source File: CollationController.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * remove columns from @param filter where we already have data in @param container newer than @param sstableTimestamp
 */
private void reduceNameFilter(QueryFilter filter, ColumnFamily container, long sstableTimestamp)
{
    if (container == null)
        return;

    for (Iterator<CellName> iterator = ((NamesQueryFilter) filter.filter).columns.iterator(); iterator.hasNext(); )
    {
        CellName filterColumn = iterator.next();
        Cell cell = container.getColumn(filterColumn);
        if (cell != null && cell.timestamp() > sstableTimestamp)
            iterator.remove();
    }
}
 
Example #6
Source File: ReadCommand.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static ReadCommand create(String ksName, ByteBuffer key, String cfName, long timestamp, IDiskAtomFilter filter)
{
    if (filter instanceof SliceQueryFilter)
        return new SliceFromReadCommand(ksName, key, cfName, timestamp, (SliceQueryFilter)filter);
    else
        return new SliceByNamesReadCommand(ksName, key, cfName, timestamp, (NamesQueryFilter)filter);
}
 
Example #7
Source File: Util.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static NamesQueryFilter namesFilter(ColumnFamilyStore cfs, String... names)
{
    SortedSet<CellName> s = new TreeSet<CellName>(cfs.getComparator());
    for (String str : names)
        s.add(cellname(str));
    return new NamesQueryFilter(s);
}
 
Example #8
Source File: ColumnFamilyStoreTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSliceByNamesCommandOnUUIDTypeSCF() throws Throwable
{
    String keyspaceName = "Keyspace1";
    String cfName = "Super6";
    ByteBuffer superColName = LexicalUUIDType.instance.fromString("a4ed3562-0e8e-4b41-bdfd-c45a2774682d");
    Keyspace keyspace = Keyspace.open(keyspaceName);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
    DecoratedKey key = Util.dk("slice-get-uuid-type");

    // Insert a row with one supercolumn and multiple subcolumns
    putColsSuper(cfs, key, superColName, new BufferCell(cellname("a"), ByteBufferUtil.bytes("A"), 1),
                                         new BufferCell(cellname("b"), ByteBufferUtil.bytes("B"), 1));

    // Get the entire supercolumn like normal
    ColumnFamily cfGet = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, cfName, System.currentTimeMillis()));
    assertEquals(ByteBufferUtil.bytes("A"), cfGet.getColumn(CellNames.compositeDense(superColName, ByteBufferUtil.bytes("a"))).value());
    assertEquals(ByteBufferUtil.bytes("B"), cfGet.getColumn(CellNames.compositeDense(superColName, ByteBufferUtil.bytes("b"))).value());

    // Now do the SliceByNamesCommand on the supercolumn, passing both subcolumns in as columns to get
    SortedSet<CellName> sliceColNames = new TreeSet<CellName>(cfs.metadata.comparator);
    sliceColNames.add(CellNames.compositeDense(superColName, ByteBufferUtil.bytes("a")));
    sliceColNames.add(CellNames.compositeDense(superColName, ByteBufferUtil.bytes("b")));
    SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(keyspaceName, key.getKey(), cfName, System.currentTimeMillis(), new NamesQueryFilter(sliceColNames));
    ColumnFamily cfSliced = cmd.getRow(keyspace).cf;

    // Make sure the slice returns the same as the straight get
    assertEquals(ByteBufferUtil.bytes("A"), cfSliced.getColumn(CellNames.compositeDense(superColName, ByteBufferUtil.bytes("a"))).value());
    assertEquals(ByteBufferUtil.bytes("B"), cfSliced.getColumn(CellNames.compositeDense(superColName, ByteBufferUtil.bytes("b"))).value());
}
 
Example #9
Source File: CommitLogTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testTruncateWithoutSnapshotNonDurable()  throws ExecutionException, InterruptedException
{
    CommitLog.instance.resetUnsafe();
    boolean prevAutoSnapshot = DatabaseDescriptor.isAutoSnapshot();
    DatabaseDescriptor.setAutoSnapshot(false);
    Keyspace notDurableKs = Keyspace.open("NoCommitlogSpace");
    Assert.assertFalse(notDurableKs.metadata.durableWrites);
    ColumnFamilyStore cfs = notDurableKs.getColumnFamilyStore("Standard1");
    CellNameType type = notDurableKs.getColumnFamilyStore("Standard1").getComparator();
    Mutation rm;
    DecoratedKey dk = Util.dk("key1");

    // add data
    rm = new Mutation("NoCommitlogSpace", dk.getKey());
    rm.add("Standard1", Util.cellname("Column1"), ByteBufferUtil.bytes("abcd"), 0);
    rm.apply();

    ReadCommand command = new SliceByNamesReadCommand("NoCommitlogSpace", dk.getKey(), "Standard1", System.currentTimeMillis(), new NamesQueryFilter(FBUtilities.singleton(Util.cellname("Column1"), type)));
    Row row = command.getRow(notDurableKs);
    Cell col = row.cf.getColumn(Util.cellname("Column1"));
    Assert.assertEquals(col.value(), ByteBuffer.wrap("abcd".getBytes()));
    cfs.truncateBlocking();
    DatabaseDescriptor.setAutoSnapshot(prevAutoSnapshot);
    row = command.getRow(notDurableKs);
    Assert.assertEquals(null, row.cf);
}
 
Example #10
Source File: SSTableAttachedSecondaryIndexTest.java    From sasi with Apache License 2.0 4 votes vote down vote up
private void testSearchWithoutOrPartialPredicateFiltering(boolean forceFlush)
{
    ColumnFamilyStore store = Keyspace.open(KS_NAME).getColumnFamilyStore(CF_NAME);

    final ByteBuffer firstName = UTF8Type.instance.decompose("first_name");
    final ByteBuffer age = UTF8Type.instance.decompose("age");

    RowMutation rm1 = new RowMutation(KS_NAME, AsciiType.instance.decompose("key1"));
    rm1.add(CF_NAME, firstName, AsciiType.instance.decompose("pavel"), System.currentTimeMillis());
    rm1.add(CF_NAME, age, Int32Type.instance.decompose(26), System.currentTimeMillis());
    rm1.add(CF_NAME, UTF8Type.instance.decompose("/data/1"), Int32Type.instance.decompose(1), System.currentTimeMillis());
    rm1.add(CF_NAME, UTF8Type.instance.decompose("/data/2"), Int32Type.instance.decompose(2), System.currentTimeMillis());
    rm1.add(CF_NAME, UTF8Type.instance.decompose("/data/3"), Int32Type.instance.decompose(3), System.currentTimeMillis());
    rm1.add(CF_NAME, UTF8Type.instance.decompose("/data/4"), Int32Type.instance.decompose(4), System.currentTimeMillis());

    rm1.apply();

    if (forceFlush)
        store.forceBlockingFlush();

    // don't request any columns that are in the index expressions
    SortedSet<ByteBuffer> columns = new TreeSet<ByteBuffer>(store.getComparator())
    {{
        add(UTF8Type.instance.decompose("/data/2"));
    }};

    Set<String> rows = getIndexed(store, new NamesQueryFilter(columns), 10,
                                  new IndexExpression(firstName, IndexOperator.EQ, UTF8Type.instance.decompose("a")),
                                  new IndexExpression(age, IndexOperator.GTE, Int32Type.instance.decompose(26)));

    Assert.assertEquals(rows.toString(), 1, rows.size());
    Assert.assertEquals(rows.toString(), "key1", Iterables.get(rows, 0));

    // now, let's request only one of the expressions to be returned as a column, this will make sure
    // that when missing columns are filtered, only appropriate expressions are taken into consideration.
    columns = new TreeSet<ByteBuffer>(store.getComparator())
    {{
            add(UTF8Type.instance.decompose("/data/1"));
            add(UTF8Type.instance.decompose("/data/2"));
            add(firstName);
    }};

    getIndexed(store, new NamesQueryFilter(columns), 10,
               new IndexExpression(firstName, IndexOperator.EQ, UTF8Type.instance.decompose("a")),
               new IndexExpression(age, IndexOperator.GTE, Int32Type.instance.decompose(26)));

    Assert.assertEquals(rows.toString(), 1, rows.size());
    Assert.assertEquals(rows.toString(), "key1", Iterables.get(rows, 0));
}
 
Example #11
Source File: AbstractCellNameType.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public IVersionedSerializer<NamesQueryFilter> namesQueryFilterSerializer()
{
    return namesQueryFilterSerializer;
}
 
Example #12
Source File: CassandraServer.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public IDiskAtomFilter readFilter()
{
    return expected == null || expected.isEmpty()
         ? new SliceQueryFilter(ColumnSlice.ALL_COLUMNS_ARRAY, false, 1)
         : new NamesQueryFilter(ImmutableSortedSet.copyOf(expected.getComparator(), expected.getColumnNames()));
}
 
Example #13
Source File: ColumnFamilyStoreTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Test
public void testCassandra6778() throws CharacterCodingException
{
    String cfname = "StandardInteger1";
    Keyspace keyspace = Keyspace.open("Keyspace1");
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);

    // insert two columns that represent the same integer but have different binary forms (the
    // second one is padded with extra zeros)
    Mutation rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("k1"));
    CellName column1 = cellname(ByteBuffer.wrap(new byte[]{1}));
    rm.add(cfname, column1, ByteBufferUtil.bytes("data1"), 1);
    rm.apply();
    cfs.forceBlockingFlush();

    rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("k1"));
    CellName column2 = cellname(ByteBuffer.wrap(new byte[]{0, 0, 1}));
    rm.add(cfname, column2, ByteBufferUtil.bytes("data2"), 2);
    rm.apply();
    cfs.forceBlockingFlush();

    // fetch by the first column name; we should get the second version of the column value
    SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(
        "Keyspace1", ByteBufferUtil.bytes("k1"), cfname, System.currentTimeMillis(),
        new NamesQueryFilter(FBUtilities.singleton(column1, cfs.getComparator())));

    ColumnFamily cf = cmd.getRow(keyspace).cf;
    assertEquals(1, cf.getColumnCount());
    Cell cell = cf.getColumn(column1);
    assertEquals("data2", ByteBufferUtil.string(cell.value()));
    assertEquals(column2, cell.name());

    // fetch by the second column name; we should get the second version of the column value
    cmd = new SliceByNamesReadCommand(
        "Keyspace1", ByteBufferUtil.bytes("k1"), cfname, System.currentTimeMillis(),
        new NamesQueryFilter(FBUtilities.singleton(column2, cfs.getComparator())));

    cf = cmd.getRow(keyspace).cf;
    assertEquals(1, cf.getColumnCount());
    cell = cf.getColumn(column2);
    assertEquals("data2", ByteBufferUtil.string(cell.value()));
    assertEquals(column2, cell.name());
}
 
Example #14
Source File: CellNameType.java    From stratio-cassandra with Apache License 2.0 votes vote down vote up
public IVersionedSerializer<NamesQueryFilter> namesQueryFilterSerializer();