org.apache.cassandra.db.marshal.FloatType Java Examples
The following examples show how to use
org.apache.cassandra.db.marshal.FloatType.
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 testSet() { // set of floats // test non-frozen DataType setType = DataType.set(DataType.cfloat(), false); AbstractType<?> convertedType = CassandraTypeConverter.convert(setType); SetType<?> expectedType = SetType.getInstance(FloatType.instance, true); Assert.assertEquals(expectedType, convertedType); // test frozen setType = DataType.set(DataType.cfloat(), true); convertedType = CassandraTypeConverter.convert(setType); expectedType = SetType.getInstance(FloatType.instance, false); Assert.assertEquals(expectedType, convertedType); Assert.assertTrue("Expected convertedType to be frozen", convertedType.isFrozenCollection()); }
Example #2
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 #3
Source File: CassandraTypeDeserializerTest.java From debezium-incubator with Apache License 2.0 | 6 votes |
@Test public void testSetType() { Set<Float> sourceSet = new HashSet<>(); sourceSet.add(42F); sourceSet.add(123F); // non-frozen SetType<Float> nonFrozenSetType = SetType.getInstance(FloatType.instance, true); ByteBuffer serializedSet = nonFrozenSetType.decompose(sourceSet); Collection<?> deserializedSet = (Collection<?>) CassandraTypeDeserializer.deserialize(nonFrozenSetType, serializedSet); // order may be different in the resulting collection. Assert.assertTrue(sourceSet.containsAll(deserializedSet)); Assert.assertTrue(deserializedSet.containsAll(sourceSet)); // frozen SetType<Float> frozenSetType = SetType.getInstance(FloatType.instance, false); serializedSet = frozenSetType.decompose(sourceSet); deserializedSet = (Collection<?>) CassandraTypeDeserializer.deserialize(frozenSetType, serializedSet); Assert.assertTrue(sourceSet.containsAll(deserializedSet)); Assert.assertTrue(deserializedSet.containsAll(sourceSet)); }
Example #4
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 #5
Source File: Term.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * Returns the typed value, serialized to a ByteBuffer. * * @return a ByteBuffer of the value. * @throws InvalidRequestException if unable to coerce the string to its type. */ public ByteBuffer getByteBuffer() throws InvalidRequestException { switch (type) { case STRING: return AsciiType.instance.fromString(text); case INTEGER: return IntegerType.instance.fromString(text); case UUID: // we specifically want the Lexical class here, not "UUIDType," because we're supposed to have // a uuid-shaped string here, and UUIDType also accepts integer or date strings (and turns them into version 1 uuids). return LexicalUUIDType.instance.fromString(text); case FLOAT: return FloatType.instance.fromString(text); } // FIXME: handle scenario that should never happen return null; }
Example #6
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 #7
Source File: CassandraLazyFloat.java From Hive-Cassandra with Apache License 2.0 | 6 votes |
@Override public void init(ByteArrayRef bytes, int start, int length) { if ( length == 4 ) { try { ByteBuffer buf = ByteBuffer.wrap(bytes.getData(), start, length); data.set(FloatType.instance.compose(buf)); isNull = false; return; } catch (Throwable ie) { //we are unable to parse the data, try to parse it in the hive lazy way. } } super.init(bytes, start, length); }
Example #8
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testFloat() { DataType floatType = DataType.cfloat(); AbstractType<?> convertedType = CassandraTypeConverter.convert(floatType); FloatType expectedType = FloatType.instance; Assert.assertEquals(expectedType, convertedType); }
Example #9
Source File: Floats.java From stratio-cassandra with Apache License 2.0 | 4 votes |
public Floats(String name, GeneratorConfig config) { super(FloatType.instance, config, name, Float.class); }
Example #10
Source File: CassandraTypeDeserializerTest.java From debezium-incubator with Apache License 2.0 | 3 votes |
@Test public void testFloatType() { Float expectedFloat = 66.6F; ByteBuffer serializedFloat = FloatType.instance.decompose(expectedFloat); Object deserializedFloat = CassandraTypeDeserializer.deserialize(FloatType.instance, serializedFloat); Assert.assertEquals(expectedFloat, deserializedFloat); }