org.apache.cassandra.db.marshal.Int32Type Java Examples
The following examples show how to use
org.apache.cassandra.db.marshal.Int32Type.
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: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 6 votes |
@Test public void testList() { // list of ints // test non-frozen DataType listType = DataType.list(DataType.cint(), false); AbstractType<?> convertedType = CassandraTypeConverter.convert(listType); ListType<?> expectedType = ListType.getInstance(Int32Type.instance, true); Assert.assertEquals(expectedType, convertedType); // test frozen listType = DataType.list(DataType.cint(), true); convertedType = CassandraTypeConverter.convert(listType); expectedType = ListType.getInstance(Int32Type.instance, false); Assert.assertEquals(expectedType, convertedType); Assert.assertTrue("Expected convertedType to be frozen", convertedType.isFrozenCollection()); }
Example #2
Source File: LazyCassandraUtils.java From Hive-Cassandra with Apache License 2.0 | 6 votes |
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 #3
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
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 #4
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
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 #5
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
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 #6
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
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 #7
Source File: SelectStatementTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * Calls the <code>SelectStatement.buildBound</code> with the specified restrictions. * * @param restrictions the restrictions * @return the result from the method call to <code>SelectStatement.buildBound</code> * @throws InvalidRequestException if the method call throw an exception */ private static List<Composite> executeBuildBound(Restriction[] restrictions, Bound bound) throws InvalidRequestException { List<AbstractType<?>> types = new ArrayList<>(); for (int i = 0, m = restrictions.length; i < m; i++) types.add(Int32Type.instance); CompoundSparseCellNameType cType = new CompoundSparseCellNameType(types); CFMetaData cfMetaData = new CFMetaData("keyspace", "test", ColumnFamilyType.Standard, cType); List<ColumnDefinition> columnDefs = new ArrayList<>(); for (int i = 0, m = restrictions.length; i < m; i++) { ByteBuffer name = ByteBufferUtil.bytes("clustering_" + i); columnDefs.add(ColumnDefinition.clusteringKeyDef(cfMetaData, name, types.get(i), i)); } return SelectStatement.buildBound(bound, columnDefs, restrictions, false, cType, QueryOptions.DEFAULT); }
Example #8
Source File: CompactionHistoryTabularData.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public static TabularData from(UntypedResultSet resultSet) throws OpenDataException { TabularDataSupport result = new TabularDataSupport(TABULAR_TYPE); for (UntypedResultSet.Row row : resultSet) { UUID id = row.getUUID(ITEM_NAMES[0]); String ksName = row.getString(ITEM_NAMES[1]); String cfName = row.getString(ITEM_NAMES[2]); long compactedAt = row.getLong(ITEM_NAMES[3]); long bytesIn = row.getLong(ITEM_NAMES[4]); long bytesOut = row.getLong(ITEM_NAMES[5]); Map<Integer, Long> rowMerged = row.getMap(ITEM_NAMES[6], Int32Type.instance, LongType.instance); result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[]{ id.toString(), ksName, cfName, compactedAt, bytesIn, bytesOut, "{" + FBUtilities.toString(rowMerged) + "}" })); } return result; }
Example #9
Source File: CellValidatorTest.java From deep-spark with Apache License 2.0 | 6 votes |
public void testValidatorClassToKind() { assertEquals(Kind.validatorClassToKind(null), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(TimeUUIDType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(UTF8Type.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(Int32Type.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(BooleanType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(TimestampType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(DecimalType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(LongType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(DoubleType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(FloatType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(InetAddressType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(IntegerType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(UUIDType.class), Kind.NOT_A_COLLECTION); assertEquals(Kind.validatorClassToKind(SetType.class), Kind.SET); assertEquals(Kind.validatorClassToKind(ListType.class), Kind.LIST); assertEquals(Kind.validatorClassToKind(MapType.class), Kind.MAP); }
Example #10
Source File: CassandraTypeDeserializerTest.java From debezium-incubator with Apache License 2.0 | 6 votes |
@Test public void testListType() { List<Integer> expectedList = new ArrayList<>(); expectedList.add(1); expectedList.add(3); expectedList.add(5); // non-frozen ListType<Integer> nonFrozenListType = ListType.getInstance(Int32Type.instance, true); ByteBuffer serializedList = nonFrozenListType.decompose(expectedList); Object deserializedList = CassandraTypeDeserializer.deserialize(nonFrozenListType, serializedList); Assert.assertEquals(expectedList, deserializedList); // frozen ListType<Integer> frozenListType = ListType.getInstance(Int32Type.instance, false); serializedList = frozenListType.decompose(expectedList); deserializedList = CassandraTypeDeserializer.deserialize(frozenListType, serializedList); Assert.assertEquals(expectedList, deserializedList); }
Example #11
Source File: CassandraTypeDeserializerTest.java From debezium-incubator with Apache License 2.0 | 6 votes |
@Test public void testMapTypeNonStringKeys() { Map<Integer, Float> sourceMap = new HashMap<>(); sourceMap.put(1, 1.5F); sourceMap.put(2, 3.1414F); MapType<Integer, Float> mapType = MapType.getInstance(Int32Type.instance, FloatType.instance, true); ByteBuffer serializedMap = mapType.decompose(sourceMap); Object deserializedMap = CassandraTypeDeserializer.deserialize(mapType, serializedMap); Map<Integer, Float> expectedMap = new HashMap<>(); expectedMap.put(1, 1.5F); expectedMap.put(2, 3.1414F); Assert.assertEquals(expectedMap, deserializedMap); }
Example #12
Source File: OnDiskIndexTest.java From sasi with Apache License 2.0 | 5 votes |
@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 #13
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@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 #14
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@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: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private void testIteratorInternal(boolean reversed) { CellNameType type = new SimpleDenseCellNameType(Int32Type.instance); ColumnFamily map = ArrayBackedSortedColumns.factory.create(metadata(), reversed); int[] values = new int[]{ 1, 2, 3, 5, 9 }; for (int i = 0; i < values.length; ++i) map.addColumn(new BufferCell(type.makeCellName(values[reversed ? values.length - 1 - i : i]))); assertSame(new int[]{ 3, 2, 1 }, map.reverseIterator(new ColumnSlice[]{ new ColumnSlice(type.make(3), Composites.EMPTY) })); assertSame(new int[]{ 3, 2, 1 }, map.reverseIterator(new ColumnSlice[]{ new ColumnSlice(type.make(4), Composites.EMPTY) })); assertSame(map.iterator(), map.iterator(ColumnSlice.ALL_COLUMNS_ARRAY)); }
Example #16
Source File: NonTokenizingAnalyzerTest.java From sasi with Apache License 2.0 | 5 votes |
@Test public void ensureIncompatibleInputSkipped() throws Exception { NonTokenizingAnalyzer analyzer = new NonTokenizingAnalyzer(); NonTokenizingOptions options = NonTokenizingOptions.getDefaultOptions(); analyzer.init(options, Int32Type.instance); ByteBuffer toAnalyze = ByteBufferUtil.bytes(1); analyzer.reset(toAnalyze); Assert.assertTrue(!analyzer.hasNext()); }
Example #17
Source File: OnDiskIndexTest.java From sasi with Apache License 2.0 | 5 votes |
private static Expression expressionForNot(Integer lower, Integer upper, Integer... terms) { return expressionForNot(Int32Type.instance, Int32Type.instance.decompose(lower), Int32Type.instance.decompose(upper), Iterables.transform(Arrays.asList(terms), new Function<Integer, ByteBuffer>() { @Override public ByteBuffer apply(Integer term) { return Int32Type.instance.decompose(term); } })); }
Example #18
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
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 #19
Source File: HintedHandOffTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testHintsMetrics() throws Exception { for (int i = 0; i < 99; i++) HintedHandOffManager.instance.metrics.incrPastWindow(InetAddress.getLocalHost()); HintedHandOffManager.instance.metrics.log(); UntypedResultSet rows = executeInternal("SELECT hints_dropped FROM system." + SystemKeyspace.PEER_EVENTS_CF); Map<UUID, Integer> returned = rows.one().getMap("hints_dropped", UUIDType.instance, Int32Type.instance); assertEquals(Iterators.getLast(returned.values().iterator()).intValue(), 99); }
Example #20
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@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 #21
Source File: OnDiskIndexTest.java From sasi with Apache License 2.0 | 5 votes |
@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 #22
Source File: ColumnSliceTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testDifferentMinMaxLengths() { List<AbstractType<?>> types = new ArrayList<>(); types.add(Int32Type.instance); types.add(Int32Type.instance); types.add(Int32Type.instance); CompoundDenseCellNameType nameType = new CompoundDenseCellNameType(types); // slice does intersect ColumnSlice slice = new ColumnSlice(composite(), composite()); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(), composite()); assertTrue(slice.intersects(columnNames(1), columnNames(1, 2), nameType, false)); slice = new ColumnSlice(composite(), composite(1)); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(1), composite()); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(1), composite(1)); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(0), composite(1, 2, 3)); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(1, 2, 3), composite(2)); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); // slice does not intersect slice = new ColumnSlice(composite(2), composite(3, 4, 5)); assertFalse(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(0), composite(0, 1, 2)); assertFalse(slice.intersects(columnNames(1), columnNames(1, 2), nameType, false)); }
Example #23
Source File: Selection.java From stratio-cassandra with Apache License 2.0 | 5 votes |
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 #24
Source File: ColumnSliceTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testColumnNameHelper() { List<AbstractType<?>> types = new ArrayList<>(); types.add(Int32Type.instance); types.add(Int32Type.instance); types.add(Int32Type.instance); CompoundDenseCellNameType nameType = new CompoundDenseCellNameType(types); assertTrue(ColumnNameHelper.overlaps(columnNames(0, 0, 0), columnNames(3, 3, 3), columnNames(1, 1, 1), columnNames(2, 2, 2), nameType)); assertFalse(ColumnNameHelper.overlaps(columnNames(0, 0, 0), columnNames(3, 3, 3), columnNames(4, 4, 4), columnNames(5, 5, 5), nameType)); assertFalse(ColumnNameHelper.overlaps(columnNames(0, 0, 0), columnNames(3, 3, 3), columnNames(3, 3, 4), columnNames(5, 5, 5), nameType)); assertTrue(ColumnNameHelper.overlaps(columnNames(0), columnNames(3, 3, 3), columnNames(1, 1), columnNames(5), nameType)); }
Example #25
Source File: ColumnSliceTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private static Composite composite(Integer ... components) { List<AbstractType<?>> types = new ArrayList<>(); types.add(Int32Type.instance); types.add(Int32Type.instance); types.add(Int32Type.instance); CompoundDenseCellNameType nameType = new CompoundDenseCellNameType(types); return nameType.make((Object[]) components); }
Example #26
Source File: Attributes.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public int getTimeToLive(QueryOptions options) throws InvalidRequestException { if (timeToLive == null) return 0; ByteBuffer tval = timeToLive.bindAndGet(options); if (tval == null) throw new InvalidRequestException("Invalid null value of TTL"); try { Int32Type.instance.validate(tval); } catch (MarshalException e) { throw new InvalidRequestException("Invalid timestamp value"); } int ttl = Int32Type.instance.compose(tval); if (ttl < 0) throw new InvalidRequestException("A TTL must be greater or equal to 0"); if (ttl > ExpiringCell.MAX_TTL) throw new InvalidRequestException(String.format("ttl is too large. requested (%d) maximum (%d)", ttl, ExpiringCell.MAX_TTL)); return ttl; }
Example #27
Source File: OnDiskIndexTest.java From sasi with Apache License 2.0 | 5 votes |
@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 #28
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testInt() { DataType intType = DataType.cint(); AbstractType<?> convertedType = CassandraTypeConverter.convert(intType); Int32Type expectedType = Int32Type.instance; Assert.assertEquals(expectedType, convertedType); }
Example #29
Source File: ArrayBackedSortedColumnsTest.java From stratio-cassandra with Apache License 2.0 | 4 votes |
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 #30
Source File: RangeTombstoneTest.java From stratio-cassandra with Apache License 2.0 | 4 votes |
@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()); }