Search in sources :

Example 1 with CQLWord

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));
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) Config(com.typesafe.config.Config) RecordMapper(com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with CQLWord

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(*)"));
}
Also used : 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 3 with CQLWord

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()));
}
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 4 with CQLWord

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);
}
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 5 with CQLWord

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());
}
Also used : DefaultIndexedField(com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField) ImmutableSetMultimap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSetMultimap) DefaultMappedField(com.datastax.oss.dsbulk.connectors.api.DefaultMappedField) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Field(com.datastax.oss.dsbulk.connectors.api.Field) DefaultIndexedField(com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField) DefaultMappedField(com.datastax.oss.dsbulk.connectors.api.DefaultMappedField) SetMultimap(com.datastax.oss.driver.shaded.guava.common.collect.SetMultimap) ImmutableSetMultimap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSetMultimap) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord)

Aggregations

CQLWord (com.datastax.oss.dsbulk.mapping.CQLWord)23 CQLFragment (com.datastax.oss.dsbulk.mapping.CQLFragment)12 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)8 RecordMapper (com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper)8 Config (com.typesafe.config.Config)8 EnumSet (java.util.EnumSet)8 Set (java.util.Set)8 DefaultMapping (com.datastax.oss.dsbulk.mapping.DefaultMapping)7 FunctionCall (com.datastax.oss.dsbulk.mapping.FunctionCall)7 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)6 Field (com.datastax.oss.dsbulk.connectors.api.Field)6 IndexedMappingField (com.datastax.oss.dsbulk.mapping.IndexedMappingField)6 MappedMappingField (com.datastax.oss.dsbulk.mapping.MappedMappingField)6 MappingField (com.datastax.oss.dsbulk.mapping.MappingField)6 NonNull (edu.umd.cs.findbugs.annotations.NonNull)6 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)5 DataType (com.datastax.oss.driver.api.core.type.DataType)5 ArrayList (java.util.ArrayList)5