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_and_statement_provided.
@Test
void should_create_record_mapper_when_mapping_and_statement_provided() {
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "mapping", "\" 0 = \\\"COL 2\\\" , 2 = c1 \", ", "query", "\"insert into ks.t1 (c1,\\\"COL 2\\\") values (:c1, :\\\"COL 2\\\")\"");
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 (c1,\"COL 2\") values (:c1, :\"COL 2\")");
assertMapping(mapper, "0", C2, "2", C1);
}
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_is_a_list_and_indexed.
@Test
void should_create_record_mapper_when_mapping_is_a_list_and_indexed() {
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "mapping", "\"\\\"COL 2\\\", c1\", ", "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)");
assertMapping(mapper, "0", C2, "1", C1);
}
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_keyspace_and_table_provided.
@Test
void should_create_record_mapper_when_mapping_keyspace_and_table_provided() {
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "mapping", "\" 0 = \\\"COL 2\\\" , 2 = c1 \"", "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)");
assertMapping(mapper, "0", C2, "2", C1);
}
use of com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper in project dsbulk by datastax.
the class SchemaSettingsTest method should_infer_insert_query_without_solr_query_column.
@Test
void should_infer_insert_query_without_solr_query_column() {
ColumnMetadata solrQueryCol = mock(ColumnMetadata.class);
CqlIdentifier solrQueryColName = CqlIdentifier.fromInternal("solr_query");
when(solrQueryCol.getName()).thenReturn(solrQueryColName);
when(solrQueryCol.getType()).thenReturn(DataTypes.TEXT);
when(table.getColumns()).thenReturn(ImmutableMap.of(C1, col1, C2, col2, C3, col3, solrQueryColName, solrQueryCol));
IndexMetadata idx = mock(IndexMetadata.class);
CqlIdentifier idxName = CqlIdentifier.fromInternal("idx");
when(table.getIndexes()).thenReturn(ImmutableMap.of(idxName, idx));
when(idx.getClassName()).thenReturn(Optional.of("com.datastax.bdp.search.solr.Cql3SolrSecondaryIndex"));
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "keyspace", "ks", "table", "t1");
SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
settings.init(session, codecFactory, false, true);
RecordMapper mapper = settings.createRecordMapper(session, recordMetadata, false);
ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
verify(session).prepare(argument.capture());
assertThat(argument.getValue()).isEqualTo("INSERT INTO ks.t1 (c1, \"COL 2\", c3) VALUES (:c1, :\"COL 2\", :c3)");
assertMapping(mapper, C1, C1, C2, C2, C3, C3);
}
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_function.
@Test
void should_create_record_mapper_when_mapping_function() {
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "mapping", "\" now() = \\\"COL 2\\\" , 2 = c1 \", ", "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 (c1, \"COL 2\") VALUES (:c1, now())");
assertMapping(mapper, "2", C1);
}
Aggregations