Search in sources :

Example 1 with SuperColumn

use of org.apache.cassandra.thrift.SuperColumn in project scale7-pelops by s7.

the class SelectorIntegrationTest method testIterateSuperColumnsFromRowUsingOnlyNext.

@Test
public void testIterateSuperColumnsFromRowUsingOnlyNext() {
    Iterator<SuperColumn> iterator = createSelector().iterateSuperColumnsFromRow(SCF, fromLong(50l), null, false, 10, ConsistencyLevel.ONE);
    char letter = 'A';
    int count = 0;
    for (int i = 0; i < 26; i++) {
        SuperColumn superColumn = iterator.next();
        assertEquals("Wrong super column value returned", letter, Bytes.fromByteArray(superColumn.getName()).toChar());
        letter++;
        count++;
    }
    assertEquals("Not all super columns were processed", 26, count);
    try {
        iterator.next();
        fail("The iterator should have thrown a NoSuchElementException exception");
    } catch (NoSuchElementException e) {
    // expected
    }
}
Also used : SuperColumn(org.apache.cassandra.thrift.SuperColumn) NoSuchElementException(java.util.NoSuchElementException) AbstractIntegrationTest(org.scale7.cassandra.pelops.support.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with SuperColumn

use of org.apache.cassandra.thrift.SuperColumn in project scale7-pelops by s7.

the class SelectorIntegrationTest method testIterateSuperColumnsFromRow.

@Test
public void testIterateSuperColumnsFromRow() {
    for (char letter = 'A'; letter <= 'Z'; letter++) {
    }
    Iterator<SuperColumn> iterator = createSelector().iterateSuperColumnsFromRow(SCF, fromLong(50l), null, false, 10, ConsistencyLevel.ONE);
    char letter = 'A';
    int count = 0;
    while (iterator.hasNext()) {
        SuperColumn superColumn = iterator.next();
        assertEquals("Wrong super column value returned", letter, Bytes.fromByteArray(superColumn.getName()).toChar());
        letter++;
        count++;
    }
    assertEquals("Not all super columns were processed", 26, count);
}
Also used : SuperColumn(org.apache.cassandra.thrift.SuperColumn) AbstractIntegrationTest(org.scale7.cassandra.pelops.support.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with SuperColumn

use of org.apache.cassandra.thrift.SuperColumn in project scale7-pelops by s7.

the class Mutator method writeSubColumnsInternal.

/**
     * Writes multiple sub-column values to a super column.
     *
     * @param colFamily        The column family
     * @param rowKey           The key of the row to modify
     * @param colName          The name of the super column
     * @param subColumns       A list of the sub-columns to write
     */
private void writeSubColumnsInternal(String colFamily, Bytes rowKey, Bytes colName, List<Column> subColumns) {
    safeGetRowKey(rowKey);
    validateColumnName(colName);
    validateColumns(subColumns);
    SuperColumn scol = new SuperColumn(nullSafeGet(colName), subColumns);
    ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
    cosc.setSuper_column(scol);
    Mutation mutation = new Mutation();
    mutation.setColumn_or_supercolumn(cosc);
    getMutationList(colFamily, rowKey).add(mutation);
}
Also used : ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) CounterSuperColumn(org.apache.cassandra.thrift.CounterSuperColumn) SuperColumn(org.apache.cassandra.thrift.SuperColumn) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) Mutation(org.apache.cassandra.thrift.Mutation)

Example 4 with SuperColumn

use of org.apache.cassandra.thrift.SuperColumn in project scale7-pelops by s7.

the class Selector method getPageOfSuperColumnsFromRow.

/**
     * Retrieve a page of super columns composed from a segment of the sequence of super columns in a row.
     * @param columnFamily                  The name of the column family containing the super columns
     * @param rowKey                        The key of the row
     * @param startBeyondName               The sequence of super columns must begin with the smallest super column name greater than this value. Pass <code>null</code> to start at the beginning of the sequence.
     * @param reversed                      Whether the scan should proceed in descending super column name order
     * @param count                         The maximum number of super columns that can be retrieved by the scan
     * @param cLevel                        The Cassandra consistency level with which to perform the operation
     * @return                              A page of super columns
     * @throws PelopsException if an error occurs
     */
public List<SuperColumn> getPageOfSuperColumnsFromRow(String columnFamily, Bytes rowKey, Bytes startBeyondName, boolean reversed, int count, ConsistencyLevel cLevel) throws PelopsException {
    if (Bytes.nullSafeGet(startBeyondName) == null) {
        SlicePredicate predicate = Selector.newColumnsPredicateAll(reversed, count);
        return getSuperColumnsFromRow(columnFamily, rowKey, predicate, cLevel);
    } else {
        // cassandra will return the start row but the user is expecting a page of results beyond that point
        int incrementedCount = count + 1;
        SlicePredicate predicate = Selector.newColumnsPredicate(startBeyondName, Bytes.EMPTY, reversed, incrementedCount);
        List<SuperColumn> columns = getSuperColumnsFromRow(columnFamily, rowKey, predicate, cLevel);
        if (columns.size() > 0) {
            SuperColumn first = columns.get(0);
            if (first.name.equals(startBeyondName.getBytes()))
                return columns.subList(1, columns.size());
            else if (columns.size() == incrementedCount)
                return columns.subList(0, columns.size() - 1);
        }
        return columns;
    }
}
Also used : SuperColumn(org.apache.cassandra.thrift.SuperColumn) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate)

Aggregations

SuperColumn (org.apache.cassandra.thrift.SuperColumn)4 ColumnOrSuperColumn (org.apache.cassandra.thrift.ColumnOrSuperColumn)2 Test (org.junit.Test)2 AbstractIntegrationTest (org.scale7.cassandra.pelops.support.AbstractIntegrationTest)2 NoSuchElementException (java.util.NoSuchElementException)1 CounterSuperColumn (org.apache.cassandra.thrift.CounterSuperColumn)1 Mutation (org.apache.cassandra.thrift.Mutation)1 SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)1