use of com.datastax.oss.dsbulk.mapping.CQLWord in project dsbulk by datastax.
the class SchemaSettingsTest method should_not_error_when_insert_query_does_not_contain_clustering_column_but_mutation_is_static_only.
@Test
void should_not_error_when_insert_query_does_not_contain_clustering_column_but_mutation_is_static_only() {
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "query", "\"INSERT INTO ks.t1 (c1, c3) VALUES (:c1, :c3)\"");
when(table.getPrimaryKey()).thenReturn(newArrayList(col1, col2));
when(table.getPartitionKey()).thenReturn(singletonList(col1));
when(table.getClusteringColumns()).thenReturn(ImmutableMap.of(col2, ClusteringOrder.ASC));
when(col3.isStatic()).thenReturn(true);
SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
settings.init(session, codecFactory, false, true);
RecordMapper mapper = settings.createRecordMapper(session, recordMetadata, false);
@SuppressWarnings("unchecked") Set<CQLWord> primaryKeyVariables = (Set<CQLWord>) getInternalState(mapper, "primaryKeyVariables");
assertThat(primaryKeyVariables).doesNotContain(CQLWord.fromCqlIdentifier(C2));
}
use of com.datastax.oss.dsbulk.mapping.CQLWord in project dsbulk by datastax.
the class SchemaSettingsTest method should_use_default_writetime_var_name.
@Test
void should_use_default_writetime_var_name() {
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "keyspace", "ks", "table", "t1", "mapping", "\" *=*, f1 = writetime(*) \"");
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("writetime(*)"));
}
use of com.datastax.oss.dsbulk.mapping.CQLWord in project dsbulk by datastax.
the class SchemaSettingsTest method should_detect_writetime_var_in_query.
@Test
void should_detect_writetime_var_in_query() {
ColumnDefinitions definitions = mockColumnDefinitions(mockColumnDefinition("c1", DataTypes.TEXT), mockColumnDefinition("c2", DataTypes.TEXT), mockColumnDefinition("c3", 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 TIMESTAMP :c3\"", "mapping", "\" f1 = c1 , f2 = c2 , f3 = c3 \" ");
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(C3.asInternal()));
}
use of com.datastax.oss.dsbulk.mapping.CQLWord in project dsbulk by datastax.
the class SchemaSettingsTest method should_detect_positional_writetime_var_in_query.
@Test
void should_detect_positional_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 (?, ?) USING TTL 123 AND tImEsTaMp ?\"");
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(INTERNAL_TIMESTAMP_VARNAME);
}
use of com.datastax.oss.dsbulk.mapping.CQLWord in project dsbulk by datastax.
the class SchemaSettingsTest method assertMapping.
private static void assertMapping(DefaultMapping mapping, Object... fieldsAndVars) {
ImmutableSetMultimap.Builder<Object, Object> expected = ImmutableSetMultimap.builder();
for (int i = 0; i < fieldsAndVars.length; i += 2) {
String first = fieldsAndVars[i] instanceof String ? (String) fieldsAndVars[i] : ((CqlIdentifier) fieldsAndVars[i]).asInternal();
CQLWord second = fieldsAndVars[i + 1] instanceof String ? CQLWord.fromInternal((String) fieldsAndVars[i + 1]) : CQLWord.fromCqlIdentifier((CqlIdentifier) fieldsAndVars[i + 1]);
if (CharMatcher.inRange('0', '9').matchesAllOf(first)) {
expected.put(new DefaultIndexedField(Integer.parseInt(first)), second);
} else {
expected.put(new DefaultMappedField(first), second);
}
}
@SuppressWarnings("unchecked") SetMultimap<Field, CQLWord> fieldsToVariables = (SetMultimap<Field, CQLWord>) getInternalState(mapping, "fieldsToVariables");
assertThat(fieldsToVariables).isEqualTo(expected.build());
}
Aggregations