org.apache.cassandra.db.marshal.DecimalType Java Examples

The following examples show how to use org.apache.cassandra.db.marshal.DecimalType. 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: CellValidatorTest.java    From deep-spark with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: DecimalTypeTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void test2Compare()
{
    ByteBuffer lowBB = DecimalType.instance.decompose(low);
    ByteBuffer low2BB = DecimalType.instance.decompose(low);
    ByteBuffer highBB = DecimalType.instance.decompose(high);
    assertEquals(-1, DecimalType.instance.compare(lowBB, highBB));

    lowBB = DecimalType.instance.decompose(low);
    highBB = DecimalType.instance.decompose(high);
    assertEquals(1, DecimalType.instance.compare(highBB, lowBB));

    lowBB = DecimalType.instance.decompose(low);
    assertEquals(0, DecimalType.instance.compare(low2BB, lowBB));

    lowBB = DecimalType.instance.decompose(low);
    assertEquals(-1, DecimalType.instance.compare(ByteBufferUtil.EMPTY_BYTE_BUFFER, lowBB));

    lowBB = DecimalType.instance.decompose(low);
    assertEquals(1, DecimalType.instance.compare(lowBB,ByteBufferUtil.EMPTY_BYTE_BUFFER));

    assertEquals(0, DecimalType.instance.compare(ByteBufferUtil.EMPTY_BYTE_BUFFER,ByteBufferUtil.EMPTY_BYTE_BUFFER));
}
 
Example #3
Source File: DecimalTypeTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void test3Sort()
{
    ByteBuffer zeroBB = DecimalType.instance.decompose(zero);
    ByteBuffer minusBB = DecimalType.instance.decompose(minus);
    ByteBuffer lowBB = DecimalType.instance.decompose(low);
    ByteBuffer highBB = DecimalType.instance.decompose(high);

    ByteBuffer[] array = {highBB,minusBB,lowBB,lowBB,zeroBB,minusBB};

    // Sort the array of ByteBuffer using a DecimalType comparator
    Arrays.sort(array, DecimalType.instance);

    // Check that the array is in order
    for (int i = 1; i < array.length; i++)
    {
        BigDecimal i0 = DecimalType.instance.compose(array[i - 1]);
        BigDecimal i1 = DecimalType.instance.compose(array[i]);
        assertTrue("#" + i, i0.compareTo(i1) <= 0);
    }
}
 
Example #4
Source File: CassandraTypeConverterTest.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecimal() {
    DataType decimalType = DataType.decimal();
    AbstractType<?> convertedType = CassandraTypeConverter.convert(decimalType);

    DecimalType expectedType = DecimalType.instance;

    Assert.assertEquals(expectedType, convertedType);
}
 
Example #5
Source File: DecimalTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void test1Decompose_compose()
{
    ByteBuffer bb = DecimalType.instance.decompose(low);

    String string = DecimalType.instance.compose(bb).toPlainString();

    // check that the decomposed buffer when re-composed is equal to the initial string.
    assertEquals(LOW, string);

    // check that a null argument yields an empty byte buffer
    bb = DecimalType.instance.decompose(null);
    assertEquals(bb, ByteBufferUtil.EMPTY_BYTE_BUFFER);
}
 
Example #6
Source File: CassandraTypeDeserializerTest.java    From debezium-incubator with Apache License 2.0 3 votes vote down vote up
@Test
public void testDecimalType() {
    BigDecimal expectedDecimal = BigDecimal.valueOf(Math.PI);

    ByteBuffer serializedDecimal = DecimalType.instance.decompose(expectedDecimal);

    Object deserializedDecimal = CassandraTypeDeserializer.deserialize(DecimalType.instance, serializedDecimal);

    Assert.assertEquals(expectedDecimal, deserializedDecimal);
}