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();
}
}
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(*)"));
}
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);
}
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"));
}
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");
}
Aggregations