Search in sources :

Example 6 with DefaultIndexedField

use of com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField 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)

Example 7 with DefaultIndexedField

use of com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField in project dsbulk by datastax.

the class CSVConnectorTest method should_honor_ignoreLeadingWhitespaces_and_ignoreTrailingWhitespaces_when_reading.

@Test
void should_honor_ignoreLeadingWhitespaces_and_ignoreTrailingWhitespaces_when_reading() throws Exception {
    Path file = Files.createTempFile("test", ".csv");
    Files.write(file, Collections.singleton(" foo "));
    CSVConnector connector = new CSVConnector();
    Config settings = TestConfigUtils.createTestConfig("dsbulk.connector.csv", "url", StringUtils.quoteJson(file), "ignoreLeadingWhitespaces", false, "ignoreTrailingWhitespaces", false, "header", false);
    connector.configure(settings, true, true);
    connector.init();
    List<Record> records = Flux.merge(connector.read()).collectList().block();
    assertThat(records).hasSize(1);
    assertThat(records.get(0).getFieldValue(new DefaultIndexedField(0))).isEqualTo(" foo ");
    connector.close();
}
Also used : Path(java.nio.file.Path) DefaultIndexedField(com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField) Config(com.typesafe.config.Config) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Record(com.datastax.oss.dsbulk.connectors.api.Record) ErrorRecord(com.datastax.oss.dsbulk.connectors.api.ErrorRecord) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with DefaultIndexedField

use of com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField in project dsbulk by datastax.

the class CSVConnectorTest method should_honor_multi_char_delimiter.

@Test
void should_honor_multi_char_delimiter() throws Exception {
    CSVConnector connector = new CSVConnector();
    Config settings = TestConfigUtils.createTestConfig("dsbulk.connector.csv", "url", url("/multi-char-delimiter.csv"), "delimiter", "\"||\"", "ignoreLeadingWhitespaces", true, "ignoreTrailingWhitespaces", true, "header", true);
    connector.configure(settings, true, true);
    connector.init();
    List<Record> records = Flux.merge(connector.read()).collectList().block();
    assertThat(records).hasSize(1);
    Record record = records.get(0);
    assertThat(record.fields()).hasSize(6);
    assertThat(record.getFieldValue(new DefaultIndexedField(0))).isEqualTo("foo");
    assertThat(record.getFieldValue(new DefaultIndexedField(1))).isEqualTo("|bar|");
    assertThat(record.getFieldValue(new DefaultIndexedField(2))).isEqualTo("foo||bar");
    assertThat(record.getFieldValue(new DefaultMappedField("field A"))).isEqualTo("foo");
    assertThat(record.getFieldValue(new DefaultMappedField("field B"))).isEqualTo("|bar|");
    assertThat(record.getFieldValue(new DefaultMappedField("field C"))).isEqualTo("foo||bar");
    connector.close();
}
Also used : DefaultIndexedField(com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField) Config(com.typesafe.config.Config) DefaultMappedField(com.datastax.oss.dsbulk.connectors.api.DefaultMappedField) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Record(com.datastax.oss.dsbulk.connectors.api.Record) ErrorRecord(com.datastax.oss.dsbulk.connectors.api.ErrorRecord) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with DefaultIndexedField

use of com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField in project dsbulk by datastax.

the class RecordUtils method indexedCSV.

public static Record indexedCSV(String... values) {
    int counter = COUNTER.incrementAndGet();
    DefaultRecord record = DefaultRecord.indexed("source" + counter, URI.create("file://file" + counter + ".csv"), counter - 1);
    for (int i = 0; i < values.length; i++) {
        record.put(new DefaultIndexedField(i), values[i]);
    }
    return record;
}
Also used : DefaultIndexedField(com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord)

Example 10 with DefaultIndexedField

use of com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField in project dsbulk by datastax.

the class RecordUtils method mappedCSV.

public static Record mappedCSV(String... tokens) {
    int counter = COUNTER.incrementAndGet();
    DefaultRecord record = DefaultRecord.indexed("source" + counter, URI.create("file://file" + counter + ".csv"), counter - 1);
    for (int i = 0; i < tokens.length; i += 2) {
        record.put(new DefaultMappedField(tokens[i]), tokens[i + 1]);
        record.put(new DefaultIndexedField(i % 2), tokens[i + 1]);
    }
    return record;
}
Also used : DefaultIndexedField(com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField) DefaultMappedField(com.datastax.oss.dsbulk.connectors.api.DefaultMappedField) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord)

Aggregations

DefaultIndexedField (com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField)10 DefaultRecord (com.datastax.oss.dsbulk.connectors.api.DefaultRecord)9 ErrorRecord (com.datastax.oss.dsbulk.connectors.api.ErrorRecord)7 Record (com.datastax.oss.dsbulk.connectors.api.Record)7 Config (com.typesafe.config.Config)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Path (java.nio.file.Path)6 Test (org.junit.jupiter.api.Test)5 DefaultMappedField (com.datastax.oss.dsbulk.connectors.api.DefaultMappedField)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 ImmutableSetMultimap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSetMultimap)1 SetMultimap (com.datastax.oss.driver.shaded.guava.common.collect.SetMultimap)1 Field (com.datastax.oss.dsbulk.connectors.api.Field)1 CQLWord (com.datastax.oss.dsbulk.mapping.CQLWord)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1