use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class CodecSettingsTest method should_return_rounding_codecs.
@Test
void should_return_rounding_codecs() {
Config config = TestConfigUtils.createTestConfig("dsbulk.codec", "roundingStrategy", "UP", "formatNumbers", "true");
CodecSettings settings = new CodecSettings(config);
settings.init();
ConvertingCodecFactory codecFactory = settings.createCodecFactory(false, false);
ConvertingCodec<String, Float> codec = codecFactory.createConvertingCodec(DataTypes.FLOAT, GenericType.STRING, true);
assertThat(codec.internalToExternal(0.123f)).isEqualTo("0.13");
}
use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class CodecSettingsTest method should_return_codecs_for_tokenizable_fields.
@Test
void should_return_codecs_for_tokenizable_fields() {
Config config = TestConfigUtils.createTestConfig("dsbulk.codec");
CodecSettings settings = new CodecSettings(config);
settings.init();
ConvertingCodecFactory codecFactory = settings.createCodecFactory(false, false);
assertThat(codecFactory.createConvertingCodec(DataTypes.listOf(DataTypes.INT), GenericType.STRING, true)).isNotNull().isInstanceOf(StringToListCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.setOf(DataTypes.DOUBLE), GenericType.STRING, true)).isNotNull().isInstanceOf(StringToSetCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.mapOf(DataTypes.TIME, DataTypes.TEXT), GenericType.STRING, true)).isNotNull().isInstanceOf(StringToMapCodec.class);
TupleType tupleType = DriverUtils.mockTupleType(DataTypes.INT, DataTypes.DOUBLE);
assertThat(codecFactory.createConvertingCodec(tupleType, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToTupleCodec.class);
UserDefinedType udtType = new UserDefinedTypeBuilder("ks", "udt").withField("f1", DataTypes.INT).withField("f2", DataTypes.DOUBLE).build();
assertThat(codecFactory.createConvertingCodec(udtType, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToUDTCodec.class);
}
use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class CodecSettingsTest method should_return_string_to_unknown_type_codec_for_dynamic_composite_type.
@Test
void should_return_string_to_unknown_type_codec_for_dynamic_composite_type() {
Config config = TestConfigUtils.createTestConfig("dsbulk.codec");
CodecSettings settings = new CodecSettings(config);
settings.init();
ConvertingCodecFactory codecFactory = settings.createCodecFactory(false, false);
assertThat(codecFactory.createConvertingCodec(DataTypes.custom("org.apache.cassandra.db.marshal.DynamicCompositeType"), GenericType.STRING, true)).isNotNull().isInstanceOf(StringToUnknownTypeCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.custom("org.apache.cassandra.db.marshal.DynamicCompositeType"), GenericType.of(JsonNode.class), true)).isNotNull().isInstanceOf(JsonNodeToUnknownTypeCodec.class);
}
use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class JsonNodeToByteCodecTest method setUp.
@BeforeEach
void setUp() {
ConversionContext context = new TextConversionContext().setNullStrings("NULL");
ConvertingCodecFactory codecFactory = new ConvertingCodecFactory(context);
codec = (JsonNodeToByteCodec) codecFactory.<JsonNode, Byte>createConvertingCodec(DataTypes.TINYINT, JSON_NODE_TYPE, true);
}
use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class JsonNodeToDoubleCodecTest method setUp.
@BeforeEach
void setUp() {
ConversionContext context = new TextConversionContext().setNullStrings("NULL");
ConvertingCodecFactory codecFactory = new ConvertingCodecFactory(context);
codec = (JsonNodeToDoubleCodec) codecFactory.<JsonNode, Double>createConvertingCodec(DataTypes.DOUBLE, JSON_NODE_TYPE, true);
}
Aggregations