Search in sources :

Example 1 with ConvertingCodecFactory

use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.

the class CodecSettingsTest method should_return_string_converting_codecs.

@Test
void should_return_string_converting_codecs() {
    Config config = TestConfigUtils.createTestConfig("dsbulk.codec");
    CodecSettings settings = new CodecSettings(config);
    settings.init();
    ConvertingCodecFactory codecFactory = settings.createCodecFactory(false, false);
    assertThat(codecFactory.createConvertingCodec(DataTypes.BOOLEAN, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToBooleanCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.TINYINT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToByteCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.SMALLINT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToShortCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.INT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToIntegerCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.BIGINT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToLongCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.FLOAT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToFloatCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.DOUBLE, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToDoubleCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.VARINT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToBigIntegerCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.DECIMAL, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToBigDecimalCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.DATE, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToLocalDateCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.TIME, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToLocalTimeCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.TIMESTAMP, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToInstantCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.UUID, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToUUIDCodec.class);
    assertThat(codecFactory.createConvertingCodec(DataTypes.TIMEUUID, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToUUIDCodec.class);
}
Also used : ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) Config(com.typesafe.config.Config) Test(org.junit.jupiter.api.Test)

Example 2 with ConvertingCodecFactory

use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.

the class CodecSettingsTest method should_return_codecs_honoring_overflow_strategy.

@Test
void should_return_codecs_honoring_overflow_strategy() {
    Config config = TestConfigUtils.createTestConfig("dsbulk.codec", "overflowStrategy", "TRUNCATE");
    CodecSettings settings = new CodecSettings(config);
    settings.init();
    ConvertingCodecFactory codecFactory = settings.createCodecFactory(false, false);
    ConvertingCodec<String, Byte> codec = codecFactory.createConvertingCodec(DataTypes.TINYINT, GenericType.STRING, true);
    assertThat(codec.externalToInternal("128")).isEqualTo((byte) 127);
}
Also used : ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) Config(com.typesafe.config.Config) Test(org.junit.jupiter.api.Test)

Example 3 with ConvertingCodecFactory

use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.

the class JsonNodeToMapCodecTest method setUp.

@BeforeEach
void setUp() {
    ConversionContext context = new TextConversionContext().setNullStrings("NULL").setFormatNumbers(true).setRoundingMode(HALF_EVEN);
    ConvertingCodecFactory codecFactory = new ConvertingCodecFactory(context);
    codec = (JsonNodeToMapCodec<Double, List<String>>) codecFactory.<JsonNode, Map<Double, List<String>>>createConvertingCodec(DataTypes.mapOf(DataTypes.DOUBLE, DataTypes.listOf(DataTypes.TEXT)), 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) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ConvertingCodecFactory

use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.

the class JsonNodeToSetCodecTest method setUp.

@BeforeEach
void setUp() {
    ConversionContext context = new TextConversionContext().setNullStrings("NULL");
    ConvertingCodecFactory codecFactory = new ConvertingCodecFactory(context);
    codec1 = (JsonNodeToSetCodec<Double>) codecFactory.<JsonNode, Set<Double>>createConvertingCodec(DataTypes.setOf(DataTypes.DOUBLE), JSON_NODE_TYPE, true);
    codec2 = (JsonNodeToSetCodec<String>) codecFactory.<JsonNode, Set<String>>createConvertingCodec(DataTypes.setOf(DataTypes.TEXT), JSON_NODE_TYPE, true);
}
Also used : ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) TextConversionContext(com.datastax.oss.dsbulk.codecs.text.TextConversionContext) Set(java.util.Set) 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 5 with ConvertingCodecFactory

use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.

the class JsonNodeToShortCodecTest method setUp.

@BeforeEach
void setUp() {
    ConversionContext context = new TextConversionContext().setNullStrings("NULL").setFormatNumbers(true);
    ConvertingCodecFactory codecFactory = new ConvertingCodecFactory(context);
    codec = (JsonNodeToShortCodec) codecFactory.<JsonNode, Short>createConvertingCodec(DataTypes.SMALLINT, 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