Java Code Examples for org.apache.cassandra.db.marshal.Int32Type#instance()

The following examples show how to use org.apache.cassandra.db.marshal.Int32Type#instance() . 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: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void testBatchRemoveInternal(boolean reversed)
{
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), reversed);
    int[] values = new int[]{ 1, 2, 3, 5 };

    for (int i = 0; i < values.length; ++i)
        map.addColumn(new BufferCell(type.makeCellName(values[reversed ? values.length - 1 - i : i])));

    BatchRemoveIterator<Cell> batchIter = map.batchRemoveIterator();
    batchIter.next();
    batchIter.remove();
    batchIter.next();
    batchIter.remove();

    assertEquals("1st column before commit", 1, map.iterator().next().name().toByteBuffer().getInt(0));

    batchIter.commit();

    assertEquals("1st column after commit", 3, map.iterator().next().name().toByteBuffer().getInt(0));
}
 
Example 2
Source File: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void testAddAllInternal(boolean reversed)
{
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), reversed);
    ColumnFamily map2 = ArrayBackedSortedColumns.factory.create(metadata(), reversed);

    int[] values1 = new int[]{ 1, 3, 5, 6 };
    int[] values2 = new int[]{ 2, 4, 5, 6 };

    for (int i = 0; i < values1.length; ++i)
        map.addColumn(new BufferCell(type.makeCellName(values1[reversed ? values1.length - 1 - i : i])));

    for (int i = 0; i < values2.length; ++i)
        map2.addColumn(new BufferCell(type.makeCellName(values2[reversed ? values2.length - 1 - i : i])));

    map2.addAll(map);

    Iterator<Cell> iter = map2.iterator();
    assertEquals("1st column", 1, iter.next().name().toByteBuffer().getInt(0));
    assertEquals("2nd column", 2, iter.next().name().toByteBuffer().getInt(0));
    assertEquals("3rd column", 3, iter.next().name().toByteBuffer().getInt(0));
    assertEquals("4st column", 4, iter.next().name().toByteBuffer().getInt(0));
    assertEquals("5st column", 5, iter.next().name().toByteBuffer().getInt(0));
    assertEquals("6st column", 6, iter.next().name().toByteBuffer().getInt(0));
}
 
Example 3
Source File: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void testGetCollectionInternal(boolean reversed)
{
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), reversed);
    int[] values = new int[]{ 1, 2, 3, 5, 9 };

    List<Cell> sorted = new ArrayList<>();
    for (int v : values)
        sorted.add(new BufferCell(type.makeCellName(v)));
    List<Cell> reverseSorted = new ArrayList<>(sorted);
    Collections.reverse(reverseSorted);

    for (int i = 0; i < values.length; ++i)
        map.addColumn(new BufferCell(type.makeCellName(values[reversed ? values.length - 1 - i : i])));

    assertSame(sorted, map.getSortedColumns());
    assertSame(reverseSorted, map.getReverseSortedColumns());
}
 
Example 4
Source File: LazyCassandraUtils.java    From Hive-Cassandra with Apache License 2.0 6 votes vote down vote up
public static AbstractType getCassandraType(PrimitiveObjectInspector oi) {
  switch (oi.getPrimitiveCategory()) {
  case BOOLEAN:
    return BooleanType.instance;
  case INT:
    return Int32Type.instance;
  case LONG:
    return LongType.instance;
  case FLOAT:
    return FloatType.instance;
  case DOUBLE:
    return DoubleType.instance;
  case STRING:
    return UTF8Type.instance;
  case BYTE:
  case SHORT:
  case BINARY:
    return BytesType.instance;
  case TIMESTAMP:
    return DateType.instance;
  default:
    throw new RuntimeException("Hive internal error.");

  }
}
 
Example 5
Source File: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void testRemoveInternal(boolean reversed)
{
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), reversed);

    int[] values = new int[]{ 1, 2, 2, 3 };

    for (int i = 0; i < values.length; ++i)
        map.addColumn(new BufferCell(type.makeCellName(values[reversed ? values.length - 1 - i : i])));

    Iterator<Cell> iter = map.getReverseSortedColumns().iterator();
    assertTrue(iter.hasNext());
    iter.next();
    iter.remove();
    assertTrue(iter.hasNext());
    iter.next();
    iter.remove();
    assertTrue(iter.hasNext());
    iter.next();
    iter.remove();
    assertTrue(!iter.hasNext());
}
 
Example 6
Source File: OnDiskIndexTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotEqualsQueryForNumbers() throws Exception
{
    final Map<ByteBuffer, TokenTreeBuilder> data = new HashMap<ByteBuffer, TokenTreeBuilder>()
    {{
            put(Int32Type.instance.decompose(5),  keyBuilder(1L));
            put(Int32Type.instance.decompose(7),  keyBuilder(2L));
            put(Int32Type.instance.decompose(1),  keyBuilder(3L));
            put(Int32Type.instance.decompose(3),  keyBuilder(1L, 4L));
            put(Int32Type.instance.decompose(8),  keyBuilder(8L, 6L));
            put(Int32Type.instance.decompose(10), keyBuilder(5L));
            put(Int32Type.instance.decompose(6),  keyBuilder(7L));
            put(Int32Type.instance.decompose(4),  keyBuilder(9L, 10L));
            put(Int32Type.instance.decompose(0),  keyBuilder(11L, 12L, 1L));
    }};

    OnDiskIndexBuilder builder = new OnDiskIndexBuilder(UTF8Type.instance, Int32Type.instance, OnDiskIndexBuilder.Mode.ORIGINAL);
    for (Map.Entry<ByteBuffer, TokenTreeBuilder> e : data.entrySet())
        addAll(builder, e.getKey(), e.getValue());

    File index = File.createTempFile("on-disk-sa-except-int-test", "db");
    index.deleteOnExit();

    builder.finish(index);

    OnDiskIndex onDisk = new OnDiskIndex(index, Int32Type.instance, new KeyConverter());

    Assert.assertEquals(convert(1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12), convert(onDisk.search(expressionForNot(0, 10, 1))));
    Assert.assertEquals(convert(1, 2, 4, 5, 7, 9, 10, 11, 12), convert(onDisk.search(expressionForNot(0, 10, 1, 8))));
    Assert.assertEquals(convert(1, 2, 4, 5, 7, 11, 12), convert(onDisk.search(expressionForNot(0, 10, 1, 8, 4))));

    onDisk.close();
}
 
Example 7
Source File: OnDiskIndexTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
@Test
public void testDescriptor() throws Exception
{
    final Map<ByteBuffer, Pair<DecoratedKey, Long>> data = new HashMap<ByteBuffer, Pair<DecoratedKey, Long>>()
    {{
            put(Int32Type.instance.decompose(5), Pair.create(keyAt(1L), 1L));
    }};

    OnDiskIndexBuilder builder1 = new OnDiskIndexBuilder(UTF8Type.instance, Int32Type.instance, OnDiskIndexBuilder.Mode.ORIGINAL);
    OnDiskIndexBuilder builder2 = new OnDiskIndexBuilder(UTF8Type.instance, Int32Type.instance, OnDiskIndexBuilder.Mode.ORIGINAL);
    for (Map.Entry<ByteBuffer, Pair<DecoratedKey, Long>> e : data.entrySet())
    {
        DecoratedKey key = e.getValue().left;
        Long position = e.getValue().right;

        builder1.add(e.getKey(), key, position);
        builder2.add(e.getKey(), key, position);
    }

    File index1 = File.createTempFile("on-disk-sa-int", "db");
    File index2 = File.createTempFile("on-disk-sa-int2", "db");
    index1.deleteOnExit();
    index2.deleteOnExit();

    builder1.finish(index1);
    builder2.finish(new Descriptor(Descriptor.VERSION_AA), index2);

    OnDiskIndex onDisk1 = new OnDiskIndex(index1, Int32Type.instance, new KeyConverter());
    OnDiskIndex onDisk2 = new OnDiskIndex(index2, Int32Type.instance, new KeyConverter());

    ByteBuffer number = Int32Type.instance.decompose(5);

    Assert.assertEquals(Collections.singleton(data.get(number).left), convert(onDisk1.search(expressionFor(Int32Type.instance, number))));
    Assert.assertEquals(Collections.singleton(data.get(number).left), convert(onDisk2.search(expressionFor(Int32Type.instance, number))));

    Assert.assertEquals(onDisk1.descriptor.version.version, Descriptor.CURRENT_VERSION);
    Assert.assertEquals(onDisk2.descriptor.version.version, Descriptor.VERSION_AA);
}
 
Example 8
Source File: OnDiskIndexTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
@Test
public void testSuperBlocks() throws Exception
{
    Map<ByteBuffer, TokenTreeBuilder> terms = new HashMap<>();
    terms.put(UTF8Type.instance.decompose("1234"), keyBuilder(1L, 2L));
    terms.put(UTF8Type.instance.decompose("2345"), keyBuilder(3L, 4L));
    terms.put(UTF8Type.instance.decompose("3456"), keyBuilder(5L, 6L));
    terms.put(UTF8Type.instance.decompose("4567"), keyBuilder(7L, 8L));
    terms.put(UTF8Type.instance.decompose("5678"), keyBuilder(9L, 10L));

    OnDiskIndexBuilder builder = new OnDiskIndexBuilder(UTF8Type.instance, Int32Type.instance, OnDiskIndexBuilder.Mode.SPARSE);
    for (Map.Entry<ByteBuffer, TokenTreeBuilder> entry : terms.entrySet())
        addAll(builder, entry.getKey(), entry.getValue());

    File index = File.createTempFile("on-disk-sa-try-superblocks", ".db");
    index.deleteOnExit();

    builder.finish(index);

    OnDiskIndex onDisk = new OnDiskIndex(index, Int32Type.instance, new KeyConverter());
    OnDiskIndex.OnDiskSuperBlock superBlock = onDisk.dataLevel.getSuperBlock(0);
    Iterator<Token> iter = superBlock.iterator();

    Long lastToken = null;
    while (iter.hasNext())
    {
        Token token = iter.next();

        if (lastToken != null)
            Assert.assertTrue(lastToken.compareTo(token.get()) < 0);

        lastToken = token.get();
    }
}
 
Example 9
Source File: CassandraTypeConverterTest.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
@Test
public void testInt() {
    DataType intType = DataType.cint();
    AbstractType<?> convertedType = CassandraTypeConverter.convert(intType);

    Int32Type expectedType = Int32Type.instance;

    Assert.assertEquals(expectedType, convertedType);
}
 
Example 10
Source File: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatchRemoveCopy()
{
    // Test delete some random columns and check the result
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), false);
    int n = 127;
    int[] values = new int[n];
    for (int i = 0; i < n; i++)
        values[i] = i;
    Set<Integer> toRemove = Sets.newHashSet(3, 12, 13, 15, 58, 103, 112);

    for (int value : values)
        map.addColumn(new BufferCell(type.makeCellName(value)));

    BatchRemoveIterator<Cell> batchIter = map.batchRemoveIterator();
    while (batchIter.hasNext())
        if (toRemove.contains(batchIter.next().name().toByteBuffer().getInt(0)))
            batchIter.remove();

    batchIter.commit();

    int expected = 0;
    while (toRemove.contains(expected))
        expected++;

    for (Cell column : map)
    {
        assertEquals(expected, column.name().toByteBuffer().getInt(0));
        expected++;
        while (toRemove.contains(expected))
            expected++;
    }
    assertEquals(expected, n);
}
 
Example 11
Source File: Selection.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static ColumnSpecification makeWritetimeOrTTLSpec(CFMetaData cfm, Selectable.WritetimeOrTTL tot, ColumnIdentifier alias)
{
    return new ColumnSpecification(cfm.ksName,
                                   cfm.cfName,
                                   alias == null ? new ColumnIdentifier(tot.toString(), true) : alias,
                                   tot.isWritetime ? LongType.instance : Int32Type.instance);
}
 
Example 12
Source File: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testBatchCommitTwice()
{
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), false);
    map.addColumn(new BufferCell(type.makeCellName(1)));
    map.addColumn(new BufferCell(type.makeCellName(2)));

    BatchRemoveIterator<Cell> batchIter = map.batchRemoveIterator();
    batchIter.next();
    batchIter.remove();
    batchIter.commit();
    batchIter.commit();
}
 
Example 13
Source File: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private void testAddInternal(boolean reversed)
{
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), reversed);
    int[] values = new int[]{ 1, 2, 2, 3 };

    for (int i = 0; i < values.length; ++i)
        map.addColumn(new BufferCell(type.makeCellName(values[reversed ? values.length - 1 - i : i])));

    Iterator<Cell> iter = map.iterator();
    assertEquals("1st column", 1, iter.next().name().toByteBuffer().getInt(0));
    assertEquals("2nd column", 2, iter.next().name().toByteBuffer().getInt(0));
    assertEquals("3rd column", 3, iter.next().name().toByteBuffer().getInt(0));
}
 
Example 14
Source File: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testBatchRemoveTwice()
{
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), false);
    map.addColumn(new BufferCell(type.makeCellName(1)));
    map.addColumn(new BufferCell(type.makeCellName(2)));

    BatchRemoveIterator<Cell> batchIter = map.batchRemoveIterator();
    batchIter.next();
    batchIter.remove();
    batchIter.remove();
}
 
Example 15
Source File: RangeTombstoneTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Test
public void testOverwritesToDeletedColumns() throws Exception
{
    Keyspace table = Keyspace.open(KSNAME);
    ColumnFamilyStore cfs = table.getColumnFamilyStore(CFNAME);
    ByteBuffer key = ByteBufferUtil.bytes("k6");
    ByteBuffer indexedColumnName = ByteBufferUtil.bytes(1);

    cfs.truncateBlocking();
    cfs.disableAutoCompaction();
    cfs.setCompactionStrategyClass(SizeTieredCompactionStrategy.class.getCanonicalName());
    if (cfs.indexManager.getIndexForColumn(indexedColumnName) == null)
    {
        ColumnDefinition cd = new ColumnDefinition(cfs.metadata, indexedColumnName, Int32Type.instance, null, ColumnDefinition.Kind.REGULAR);
        cd.setIndex("test_index", IndexType.CUSTOM, ImmutableMap.of(SecondaryIndex.CUSTOM_INDEX_OPTION_NAME, TestIndex.class.getName()));
        cfs.indexManager.addIndexedColumn(cd);
    }

    TestIndex index = ((TestIndex)cfs.indexManager.getIndexForColumn(indexedColumnName));
    index.resetCounts();

    Mutation rm = new Mutation(KSNAME, key);
    add(rm, 1, 0);
    rm.apply();

    // add a RT which hides the column we just inserted
    rm = new Mutation(KSNAME, key);
    ColumnFamily cf = rm.addOrGet(CFNAME);
    delete(cf, 0, 1, 1);
    rm.apply();

    // now re-insert that column
    rm = new Mutation(KSNAME, key);
    add(rm, 1, 2);
    rm.apply();

    cfs.forceBlockingFlush();

    // We should have 1 insert and 1 update to the indexed "1" column
    // CASSANDRA-6640 changed index update to just update, not insert then delete
    assertEquals(1, index.inserts.size());
    assertEquals(1, index.updates.size());
}
 
Example 16
Source File: ArrayBackedSortedColumnsTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private void testAddOutOfOrder(boolean reversed)
{
    CellNameType type = new SimpleDenseCellNameType(Int32Type.instance);
    ColumnFamily cells = ArrayBackedSortedColumns.factory.create(metadata(), reversed);

    int[] values = new int[]{ 1, 2, 1, 3, 4, 4, 5, 5, 1, 2, 6, 6, 6, 1, 2, 3 };
    for (int i = 0; i < values.length; ++i)
        cells.addColumn(new BufferCell(type.makeCellName(values[reversed ? values.length - 1 - i : i])));

    assertEquals(6, cells.getColumnCount());

    Iterator<Cell> iter = cells.iterator();
    assertEquals(1, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(2, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(3, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(4, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(5, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(6, iter.next().name().toByteBuffer().getInt(0));

    // Add more values
    values = new int[]{ 11, 15, 12, 12, 12, 16, 10, 8, 8, 7, 4, 4, 5 };
    for (int i = 0; i < values.length; ++i)
        cells.addColumn(new BufferCell(type.makeCellName(values[reversed ? values.length - 1 - i : i])));

    assertEquals(13, cells.getColumnCount());

    iter = cells.reverseIterator();
    assertEquals(16, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(15, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(12, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(11, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(10, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(8,  iter.next().name().toByteBuffer().getInt(0));
    assertEquals(7, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(6, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(5, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(4, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(3, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(2, iter.next().name().toByteBuffer().getInt(0));
    assertEquals(1, iter.next().name().toByteBuffer().getInt(0));
}
 
Example 17
Source File: Integers.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public Integers(String name, GeneratorConfig config)
{
    super(Int32Type.instance, config, name, Integer.class);
}
 
Example 18
Source File: Selection.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public AbstractType<?> getType()
{
    return isWritetime ? LongType.instance : Int32Type.instance;
}
 
Example 19
Source File: Lists.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public static ColumnSpecification indexSpecOf(ColumnSpecification column)
{
    return new ColumnSpecification(column.ksName, column.cfName, new ColumnIdentifier("idx(" + column.name + ")", true), Int32Type.instance);
}
 
Example 20
Source File: Attributes.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private ColumnSpecification timeToLiveReceiver(String ksName, String cfName)
{
    return new ColumnSpecification(ksName, cfName, new ColumnIdentifier("[ttl]", true), Int32Type.instance);
}