Search in sources :

Example 11 with RecordMapper

use of com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper in project dsbulk by datastax.

the class SchemaSettingsTest method should_disable_null_to_unset_when_protocol_version_lesser_than_4.

@ParameterizedTest
@MethodSource("allProtocolVersions")
void should_disable_null_to_unset_when_protocol_version_lesser_than_4(ProtocolVersion version) {
    when(context.getProtocolVersion()).thenReturn(version);
    Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "nullToUnset", true, "keyspace", "ks", "table", "t1");
    SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
    settings.init(session, codecFactory, true, false);
    RecordMapper mapper = settings.createRecordMapper(session, recordMetadata, false);
    if (version.getCode() < V4.getCode()) {
        assertThat((Boolean) getInternalState(mapper, NULL_TO_UNSET)).isFalse();
    } else {
        assertThat((Boolean) getInternalState(mapper, NULL_TO_UNSET)).isTrue();
    }
}
Also used : Config(com.typesafe.config.Config) RecordMapper(com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with RecordMapper

use of com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper in project dsbulk by datastax.

the class SchemaSettingsTest method should_create_record_mapper_when_mapping_ttl_and_timestamp.

@Test
void should_create_record_mapper_when_mapping_ttl_and_timestamp() {
    Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "mapping", "\" 0 = \\\"COL 2\\\" , 2 = c1, 1=ttl(*), 3=writetime(*) \", ", "keyspace", "ks", "table", "t1");
    SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
    settings.init(session, codecFactory, true, false);
    RecordMapper mapper = settings.createRecordMapper(session, recordMetadata, false);
    assertThat(mapper).isNotNull();
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    verify(session).prepare(argument.capture());
    assertThat(argument.getValue()).isEqualTo("INSERT INTO ks.t1 (\"COL 2\", c1) VALUES (:\"COL 2\", :c1) " + "USING TTL :\"ttl(*)\" AND TIMESTAMP :\"writetime(*)\"");
    assertMapping(mapper, "0", C2, "2", C1, "1", CqlIdentifier.fromInternal("ttl(*)"), "3", CqlIdentifier.fromInternal("writetime(*)"));
}
Also used : Config(com.typesafe.config.Config) RecordMapper(com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 13 with RecordMapper

use of com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper in project dsbulk by datastax.

the class SchemaSettingsTest method should_create_record_mapper_with_inferred_mapping_and_skip.

@Test
void should_create_record_mapper_with_inferred_mapping_and_skip() {
    // Infer mapping, but skip C2.
    Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "keyspace", "ks", "table", "t1", "mapping", "\" *=-\\\"COL 2\\\" \"");
    SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
    settings.init(session, codecFactory, false, true);
    RecordMapper mapper = settings.createRecordMapper(session, recordMetadata, false);
    assertThat(mapper).isNotNull();
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    verify(session).prepare(argument.capture());
    assertThat(argument.getValue()).isEqualTo("INSERT INTO ks.t1 (c1, c3) VALUES (:c1, :c3)");
    assertMapping(mapper, C1, C1, C3, C3);
}
Also used : Config(com.typesafe.config.Config) RecordMapper(com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 14 with RecordMapper

use of com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper in project dsbulk by datastax.

the class SchemaSettingsTest method should_detect_quoted_writetime_var_in_query.

@Test
void should_detect_quoted_writetime_var_in_query() {
    ColumnDefinitions definitions = mockColumnDefinitions(mockColumnDefinition("c1", DataTypes.TEXT), mockColumnDefinition("c2", DataTypes.TEXT), mockColumnDefinition("\"This is a quoted \\\" variable name\"", DataTypes.TEXT));
    when(ps.getVariableDefinitions()).thenReturn(definitions);
    when(table.getColumn(CqlIdentifier.fromInternal("c2"))).thenReturn(Optional.of(col2));
    Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "query", "\"INSERT INTO ks.t1 (c1,c2) VALUES (:c1, :c2) USING TTL 123 AND tImEsTaMp     :\\\"This is a quoted \\\"\\\" variable name\\\"\"");
    SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
    settings.init(session, codecFactory, false, true);
    RecordMapper mapper = settings.createRecordMapper(session, recordMetadata, false);
    DefaultMapping mapping = (DefaultMapping) getInternalState(mapper, "mapping");
    assertThat(mapping).isNotNull();
    @SuppressWarnings("unchecked") Set<CQLWord> writeTimeVariables = (Set<CQLWord>) getInternalState(mapping, "writeTimeVariables");
    assertThat(writeTimeVariables).containsOnly(CQLWord.fromInternal("This is a quoted \" variable name"));
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) DriverUtils.mockColumnDefinitions(com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockColumnDefinitions) EnumSet(java.util.EnumSet) Set(java.util.Set) Config(com.typesafe.config.Config) RecordMapper(com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper) DefaultMapping(com.datastax.oss.dsbulk.mapping.DefaultMapping) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 15 with RecordMapper

use of com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper in project dsbulk by datastax.

the class SchemaSettingsTest method should_create_record_mapper_when_using_custom_query.

@Test
void should_create_record_mapper_when_using_custom_query() {
    ColumnDefinitions definitions = mockColumnDefinitions(mockColumnDefinition("c1var", DataTypes.TEXT), mockColumnDefinition("c2var", DataTypes.TEXT));
    when(ps.getVariableDefinitions()).thenReturn(definitions);
    when(table.getColumn(CqlIdentifier.fromInternal("c2"))).thenReturn(Optional.of(col2));
    Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "mapping", "\"0 = c1var , 2 = c2var\"", "query", "\"INSERT INTO ks.t1 (c2, c1) VALUES (:c2var, :c1var)\"");
    SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
    settings.init(session, codecFactory, true, false);
    RecordMapper mapper = settings.createRecordMapper(session, recordMetadata, false);
    assertThat(mapper).isNotNull();
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    verify(session).prepare(argument.capture());
    assertThat(argument.getValue()).isEqualTo("INSERT INTO ks.t1 (c2, c1) VALUES (:c2var, :c1var)");
    assertMapping(mapper, "0", "c1var", "2", "c2var");
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) DriverUtils.mockColumnDefinitions(com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockColumnDefinitions) Config(com.typesafe.config.Config) RecordMapper(com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

RecordMapper (com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper)21 Config (com.typesafe.config.Config)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 Test (org.junit.jupiter.api.Test)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 CQLWord (com.datastax.oss.dsbulk.mapping.CQLWord)5 EnumSet (java.util.EnumSet)5 Set (java.util.Set)5 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)4 DefaultMapping (com.datastax.oss.dsbulk.mapping.DefaultMapping)4 DriverUtils.mockColumnDefinitions (com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockColumnDefinitions)4 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)1 IndexMetadata (com.datastax.oss.driver.api.core.metadata.schema.IndexMetadata)1 ConvertingCodecFactory (com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory)1 NestedBatchException (com.datastax.oss.dsbulk.workflow.commons.schema.NestedBatchException)1 BatchSettings (com.datastax.oss.dsbulk.workflow.commons.settings.BatchSettings)1 CodecSettings (com.datastax.oss.dsbulk.workflow.commons.settings.CodecSettings)1 ConnectorSettings (com.datastax.oss.dsbulk.workflow.commons.settings.ConnectorSettings)1 DriverSettings (com.datastax.oss.dsbulk.workflow.commons.settings.DriverSettings)1