Search in sources :

Example 21 with ConvertingCodecFactory

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");
}
Also used : ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) Config(com.typesafe.config.Config) Test(org.junit.jupiter.api.Test)

Example 22 with ConvertingCodecFactory

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);
}
Also used : ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) Config(com.typesafe.config.Config) TupleType(com.datastax.oss.driver.api.core.type.TupleType) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) Test(org.junit.jupiter.api.Test)

Example 23 with ConvertingCodecFactory

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);
}
Also used : ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) Config(com.typesafe.config.Config) Test(org.junit.jupiter.api.Test)

Example 24 with ConvertingCodecFactory

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);
}
Also used : ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) TextConversionContext(com.datastax.oss.dsbulk.codecs.text.TextConversionContext) TextConversionContext(com.datastax.oss.dsbulk.codecs.text.TextConversionContext) ConversionContext(com.datastax.oss.dsbulk.codecs.api.ConversionContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with ConvertingCodecFactory

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);
}
Also used : ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) TextConversionContext(com.datastax.oss.dsbulk.codecs.text.TextConversionContext) TextConversionContext(com.datastax.oss.dsbulk.codecs.text.TextConversionContext) ConversionContext(com.datastax.oss.dsbulk.codecs.api.ConversionContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ConvertingCodecFactory (com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory)37 TextConversionContext (com.datastax.oss.dsbulk.codecs.text.TextConversionContext)29 BeforeEach (org.junit.jupiter.api.BeforeEach)29 ConversionContext (com.datastax.oss.dsbulk.codecs.api.ConversionContext)28 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 Config (com.typesafe.config.Config)5 Test (org.junit.jupiter.api.Test)5 List (java.util.List)4 CodecSettings (com.datastax.oss.dsbulk.workflow.commons.settings.CodecSettings)3 DriverSettings (com.datastax.oss.dsbulk.workflow.commons.settings.DriverSettings)3 ExecutorSettings (com.datastax.oss.dsbulk.workflow.commons.settings.ExecutorSettings)3 LogSettings (com.datastax.oss.dsbulk.workflow.commons.settings.LogSettings)3 MonitoringSettings (com.datastax.oss.dsbulk.workflow.commons.settings.MonitoringSettings)3 SchemaSettings (com.datastax.oss.dsbulk.workflow.commons.settings.SchemaSettings)3 Instant (java.time.Instant)3 TupleValue (com.datastax.oss.driver.api.core.data.TupleValue)2 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)2 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)2 ConnectorSettings (com.datastax.oss.dsbulk.workflow.commons.settings.ConnectorSettings)2 EngineSettings (com.datastax.oss.dsbulk.workflow.commons.settings.EngineSettings)2