当前位置: 首页>>代码示例>>Java>>正文


Java Util.getOnlyRow方法代码示例

本文整理汇总了Java中org.apache.cassandra.Util.getOnlyRow方法的典型用法代码示例。如果您正苦于以下问题:Java Util.getOnlyRow方法的具体用法?Java Util.getOnlyRow怎么用?Java Util.getOnlyRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.Util的用法示例。


在下文中一共展示了Util.getOnlyRow方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testIndexScanWithLimitOne

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testIndexScanWithLimitOne()
{
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(WITH_COMPOSITE_INDEX);
    Mutation rm;

    new RowUpdateBuilder(cfs.metadata, 0, "kk1").clustering("c").add("birthdate", 1L).build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata, 0, "kk1").clustering("c").add("notbirthdate", 1L).build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata, 0, "kk2").clustering("c").add("birthdate", 1L).build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata, 0, "kk2").clustering("c").add("notbirthdate", 2L).build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata, 0, "kk3").clustering("c").add("birthdate", 1L).build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata, 0, "kk3").clustering("c").add("notbirthdate", 2L).build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata, 0, "kk4").clustering("c").add("birthdate", 1L).build().applyUnsafe();
    new RowUpdateBuilder(cfs.metadata, 0, "kk4").clustering("c").add("notbirthdate", 2L).build().applyUnsafe();

    // basic single-expression query, limit 1
    Util.getOnlyRow(Util.cmd(cfs)
                        .filterOn("birthdate", Operator.EQ, 1L)
                        .filterOn("notbirthdate", Operator.EQ, 1L)
                        .withLimit(1)
                        .build());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:23,代码来源:SecondaryIndexTest.java

示例2: testRecoverCounter

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testRecoverCounter() throws IOException
{
    CommitLog.instance.resetUnsafe(true);
    Keyspace keyspace1 = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace1.getColumnFamilyStore(CF_COUNTER1);

    for (int i = 0; i < 10; ++i)
    {
        new CounterMutation(new RowUpdateBuilder(cfs.metadata, 1L, 0, "key")
            .clustering("cc").add("val", CounterContext.instance().createLocal(1L))
            .build(), ConsistencyLevel.ALL).apply();
    }

    keyspace1.getColumnFamilyStore("Counter1").clearUnsafe();

    int replayed = CommitLog.instance.resetUnsafe(false);

    ColumnDefinition counterCol = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
    Row row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val").build());
    assertEquals(10L, CounterContext.instance().total(row.getCell(counterCol).value()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:23,代码来源:RecoveryManagerTest.java

示例3: addTwoAndCheck

import org.apache.cassandra.Util; //导入方法依赖的package包/类
private void addTwoAndCheck(ColumnFamilyStore cfs, long addOne, long expectedOne, long addTwo, long expectedTwo)
{
    ColumnDefinition cDefOne = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
    ColumnDefinition cDefTwo = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val2"));

    Mutation m = new RowUpdateBuilder(cfs.metadata, 5, "key1")
        .clustering("cc")
        .add("val", addOne)
        .add("val2", addTwo)
        .build();
    new CounterMutation(m, ConsistencyLevel.ONE).apply();

    Row row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val", "val2").build());
    assertEquals(expectedOne, CounterContext.instance().total(row.getCell(cDefOne).value()));
    assertEquals(expectedTwo, CounterContext.instance().total(row.getCell(cDefTwo).value()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:17,代码来源:CounterMutationTest.java

示例4: testExpiringColumnExpiration

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testExpiringColumnExpiration() throws IOException
{
    int ttl = 1;
    ColumnDefinition def = cfm.getColumnDefinition(new ColumnIdentifier("a", true));

    Cell cell = BufferCell.expiring(def, 0, ttl, nowInSeconds, ((AbstractType) def.cellValueType()).decompose("a1"));

    PartitionUpdate update = PartitionUpdate.singleRowUpdate(cfm, dk, BTreeRow.singleCellRow(cfm.comparator.make("c1"), cell));
    new Mutation(update).applyUnsafe();

    // when we read with a nowInSeconds before the cell has expired,
    // the PartitionIterator includes the row we just wrote
    Row row = Util.getOnlyRow(Util.cmd(cfs, dk).includeRow("c1").withNowInSeconds(nowInSeconds).build());
    assertEquals("a1", ByteBufferUtil.string(row.getCell(def).value()));

    // when we read with a nowInSeconds after the cell has expired, the row is filtered
    // so the PartitionIterator is empty
    Util.assertEmpty(Util.cmd(cfs, dk).includeRow("c1").withNowInSeconds(nowInSeconds + ttl + 1).build());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:21,代码来源:RowTest.java

示例5: testGetRowSingleColumn

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testGetRowSingleColumn() throws Throwable
{
    String tableName = createTable("CREATE TABLE %s (a text, b int, c int, PRIMARY KEY (a, b))");

    for (int i = 0; i < 2; i++)
        execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", "0", i, i);

    final ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore(tableName);

    for (int round = 0; round < 2; round++)
    {
        // slice with limit 1
        Row row = Util.getOnlyRow(Util.cmd(cfs, "0").columns("c").withLimit(1).build());
        assertEquals(ByteBufferUtil.bytes(0), row.getCell(cfs.metadata.getColumnDefinition(new ColumnIdentifier("c", false))).value());

        // fetch each row by name
        for (int i = 0; i < 2; i++)
        {
            row = Util.getOnlyRow(Util.cmd(cfs, "0").columns("c").includeRow(i).build());
            assertEquals(ByteBufferUtil.bytes(i), row.getCell(cfs.metadata.getColumnDefinition(new ColumnIdentifier("c", false))).value());
        }

        // fetch each row by slice
        for (int i = 0; i < 2; i++)
        {
            row = Util.getOnlyRow(Util.cmd(cfs, "0").columns("c").fromIncl(i).toIncl(i).build());
            assertEquals(ByteBufferUtil.bytes(i), row.getCell(cfs.metadata.getColumnDefinition(new ColumnIdentifier("c", false))).value());
        }

        if (round == 0)
            cfs.forceBlockingFlush();
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:35,代码来源:KeyspaceTest.java

示例6: addAndCheck

import org.apache.cassandra.Util; //导入方法依赖的package包/类
private void addAndCheck(ColumnFamilyStore cfs, long toAdd, long expected)
{
    ColumnDefinition cDef = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
    Mutation m = new RowUpdateBuilder(cfs.metadata, 5, "key1").clustering("cc").add("val", toAdd).build();
    new CounterMutation(m, ConsistencyLevel.ONE).apply();

    Row row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val").build());
    assertEquals(expected, CounterContext.instance().total(row.getCell(cDef).value()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:10,代码来源:CounterMutationTest.java

示例7: testBatch

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testBatch() throws WriteTimeoutException
{
    ColumnFamilyStore cfsOne = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF1);
    ColumnFamilyStore cfsTwo = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF2);

    cfsOne.truncateBlocking();
    cfsTwo.truncateBlocking();

    // Do the update (+1, -1), (+2, -2)
    Mutation batch = new Mutation(KEYSPACE1, Util.dk("key1"));
    batch.add(new RowUpdateBuilder(cfsOne.metadata, 5, "key1")
        .clustering("cc")
        .add("val", 1L)
        .add("val2", -1L)
        .build().get(cfsOne.metadata));

    batch.add(new RowUpdateBuilder(cfsTwo.metadata, 5, "key1")
        .clustering("cc")
        .add("val", 2L)
        .add("val2", -2L)
        .build().get(cfsTwo.metadata));

    new CounterMutation(batch, ConsistencyLevel.ONE).apply();

    ColumnDefinition c1cfs1 = cfsOne.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
    ColumnDefinition c2cfs1 = cfsOne.metadata.getColumnDefinition(ByteBufferUtil.bytes("val2"));

    Row row = Util.getOnlyRow(Util.cmd(cfsOne).includeRow("cc").columns("val", "val2").build());
    assertEquals(1L, CounterContext.instance().total(row.getCell(c1cfs1).value()));
    assertEquals(-1L, CounterContext.instance().total(row.getCell(c2cfs1).value()));

    ColumnDefinition c1cfs2 = cfsTwo.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
    ColumnDefinition c2cfs2 = cfsTwo.metadata.getColumnDefinition(ByteBufferUtil.bytes("val2"));
    row = Util.getOnlyRow(Util.cmd(cfsTwo).includeRow("cc").columns("val", "val2").build());
    assertEquals(2L, CounterContext.instance().total(row.getCell(c1cfs2).value()));
    assertEquals(-2L, CounterContext.instance().total(row.getCell(c2cfs2).value()));

    // Check the caches, separately
    CBuilder cb = CBuilder.create(cfsOne.metadata.comparator);
    cb.add("cc");

    assertEquals(ClockAndCount.create(1L, 1L), cfsOne.getCachedCounter(Util.dk("key1").getKey(), cb.build(), c1cfs1, null));
    assertEquals(ClockAndCount.create(1L, -1L), cfsOne.getCachedCounter(Util.dk("key1").getKey(), cb.build(), c2cfs1, null));

    assertEquals(ClockAndCount.create(1L, 2L), cfsTwo.getCachedCounter(Util.dk("key1").getKey(), cb.build(), c1cfs2, null));
    assertEquals(ClockAndCount.create(1L, -2L), cfsTwo.getCachedCounter(Util.dk("key1").getKey(), cb.build(), c2cfs2, null));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:49,代码来源:CounterMutationTest.java

示例8: testDeletes

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testDeletes() throws WriteTimeoutException
{
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF1);
    cfs.truncateBlocking();
    ColumnDefinition cOne = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
    ColumnDefinition cTwo = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val2"));

    // Do the initial update (+1, -1)
    new CounterMutation(
        new RowUpdateBuilder(cfs.metadata, 5, "key1")
            .clustering("cc")
            .add("val", 1L)
            .add("val2", -1L)
            .build(),
        ConsistencyLevel.ONE).apply();

    Row row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val", "val2").build());
    assertEquals(1L, CounterContext.instance().total(row.getCell(cOne).value()));
    assertEquals(-1L, CounterContext.instance().total(row.getCell(cTwo).value()));

    // Remove the first counter, increment the second counter
    new CounterMutation(
        new RowUpdateBuilder(cfs.metadata, 5, "key1")
            .clustering("cc")
            .delete(cOne)
            .add("val2", -5L)
            .build(),
        ConsistencyLevel.ONE).apply();

    row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val", "val2").build());
    assertEquals(null, row.getCell(cOne));
    assertEquals(-6L, CounterContext.instance().total(row.getCell(cTwo).value()));

    // Increment the first counter, make sure it's still shadowed by the tombstone
    new CounterMutation(
        new RowUpdateBuilder(cfs.metadata, 5, "key1")
            .clustering("cc")
            .add("val", 1L)
            .build(),
        ConsistencyLevel.ONE).apply();
    row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val", "val2").build());
    assertEquals(null, row.getCell(cOne));

    // Get rid of the complete partition
    RowUpdateBuilder.deleteRow(cfs.metadata, 6, "key1", "cc").applyUnsafe();
    Util.assertEmpty(Util.cmd(cfs).includeRow("cc").columns("val", "val2").build());

    // Increment both counters, ensure that both stay dead
    new CounterMutation(
        new RowUpdateBuilder(cfs.metadata, 6, "key1")
            .clustering("cc")
            .add("val", 1L)
            .add("val2", 1L)
            .build(),
        ConsistencyLevel.ONE).apply();
    Util.assertEmpty(Util.cmd(cfs).includeRow("cc").columns("val", "val2").build());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:59,代码来源:CounterMutationTest.java

示例9: testTransferRangeTombstones

import org.apache.cassandra.Util; //导入方法依赖的package包/类
/**
 * Test to make sure RangeTombstones at column index boundary transferred correctly.
 */
@Test
public void testTransferRangeTombstones() throws Exception
{
    String ks = KEYSPACE1;
    String cfname = "StandardInteger1";
    Keyspace keyspace = Keyspace.open(ks);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
    ClusteringComparator comparator = cfs.getComparator();

    String key = "key1";


    RowUpdateBuilder updates = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros(), key);

    // add columns of size slightly less than column_index_size to force insert column index
    updates.clustering(1)
            .add("val", ByteBuffer.wrap(new byte[DatabaseDescriptor.getColumnIndexSize() - 64]))
            .build()
            .apply();

    updates = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros(), key);
    updates.clustering(6)
            .add("val", ByteBuffer.wrap(new byte[DatabaseDescriptor.getColumnIndexSize()]))
            .build()
            .apply();

    // add RangeTombstones
    //updates = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros() + 1 , key);
    //updates.addRangeTombstone(Slice.make(comparator, comparator.make(2), comparator.make(4)))
    //        .build()
    //        .apply();


    updates = new RowUpdateBuilder(cfs.metadata, FBUtilities.timestampMicros() + 1, key);
    updates.addRangeTombstone(Slice.make(comparator.make(5), comparator.make(7)))
            .build()
            .apply();

    cfs.forceBlockingFlush();

    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    cfs.clearUnsafe();
    transferSSTables(sstable);

    // confirm that a single SSTable was transferred and registered
    assertEquals(1, cfs.getLiveSSTables().size());

    Row r = Util.getOnlyRow(Util.cmd(cfs).build());
    Assert.assertFalse(r.isEmpty());
    Assert.assertTrue(1 == Int32Type.instance.compose(r.clustering().get(0)));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:55,代码来源:StreamingTransferTest.java


注:本文中的org.apache.cassandra.Util.getOnlyRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。