use of com.datastax.oss.dsbulk.runner.DataStaxBulkLoader in project dsbulk by datastax.
the class CSVConnectorEndToEndCCMIT method load_ttl_timestamp_now_in_mapping_and_unload.
@Test
void load_ttl_timestamp_now_in_mapping_and_unload() throws IOException {
session.execute("DROP TABLE IF EXISTS table_ttl_timestamp");
session.execute("CREATE TABLE table_ttl_timestamp (key int PRIMARY KEY, value text, loaded_at timeuuid)");
List<String> args = Lists.newArrayList("load", "--log.directory", quoteJson(logDir), "--connector.csv.ignoreLeadingWhitespaces", "true", "--connector.csv.ignoreTrailingWhitespaces", "true", "--connector.csv.url", ClassLoader.getSystemResource("ttl-timestamp.csv").toExternalForm(), "--schema.keyspace", session.getKeyspace().get().asInternal(), "--schema.table", "table_ttl_timestamp", "--schema.mapping", "*:*,now()=loaded_at,created_at=writetime(*),time_to_live=ttl(*)");
ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_OK);
assertTTLAndTimestamp();
FileUtils.deleteDirectory(logDir);
args = Lists.newArrayList("unload", "--connector.csv.url", quoteJson(unloadDir), "--log.directory", quoteJson(logDir), "--connector.csv.ignoreLeadingWhitespaces", "true", "--connector.csv.ignoreTrailingWhitespaces", "true", "--schema.keyspace", session.getKeyspace().get().asInternal(), "--schema.table", "table_ttl_timestamp", "--schema.mapping", "*:*,created_at=writetime(value),time_to_live=ttl(value)", "--connector.csv.maxConcurrentFiles", "1");
status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_OK);
validateOutputFiles(2, unloadDir);
}
use of com.datastax.oss.dsbulk.runner.DataStaxBulkLoader in project dsbulk by datastax.
the class CSVConnectorEndToEndCCMIT method load_unload_constant.
@ParameterizedTest
@MethodSource
void load_unload_constant(DataType cqlType, String literal, Object expectedIn, String expectedOut) throws IOException {
assumeTrue(ccm.getCassandraVersion().compareTo(V3_11_5) >= 0, "Literal selectors are supported starting with C* 3.11.5, see CASSANDRA-9243");
session.execute("DROP TABLE IF EXISTS test_constant");
String cqlTypeAsString = cqlType.asCql(true, true);
session.execute(String.format("CREATE TABLE test_constant (pk int PRIMARY KEY, v %s)", cqlTypeAsString));
MockConnector.mockReads(RecordUtils.mappedCSV("pk", "1"));
List<String> args = new ArrayList<>();
args.add("load");
args.add("--connector.name");
args.add("mock");
args.add("--schema.keyspace");
args.add(session.getKeyspace().get().asInternal());
args.add("--schema.table");
args.add("test_constant");
args.add("--schema.mapping");
args.add(String.format("pk=pk,(%s)%s=v", cqlTypeAsString, literal));
ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_OK);
List<Row> rows = session.execute("SELECT v FROM test_constant WHERE pk = 1").all();
assertThat(rows).hasSize(1);
assertThat(rows.get(0).getObject(0)).isNotNull().isEqualTo(expectedIn);
args = new ArrayList<>();
args.add("unload");
args.add("--connector.csv.url");
args.add(quoteJson(unloadDir));
args.add("--codec.binary");
args.add("HEX");
args.add("--schema.keyspace");
args.add(session.getKeyspace().get().asInternal());
args.add("--schema.table");
args.add("test_constant");
args.add("--schema.mapping");
args.add(String.format("pk=pk,constant=(%s)%s", cqlTypeAsString, literal));
status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_OK);
assertThat(FileUtils.readAllLinesInDirectoryAsStreamExcludingHeaders(unloadDir).collect(Collectors.toList())).singleElement().asString().isEqualTo("1," + expectedOut);
}
use of com.datastax.oss.dsbulk.runner.DataStaxBulkLoader in project dsbulk by datastax.
the class CSVConnectorEndToEndCCMIT method load_ttl_timestamp_now_in_query_and_mapping_external_names.
@Test
void load_ttl_timestamp_now_in_query_and_mapping_external_names() {
session.execute("DROP TABLE IF EXISTS table_ttl_timestamp");
session.execute("CREATE TABLE table_ttl_timestamp (key int PRIMARY KEY, value text, loaded_at timeuuid)");
List<String> args = Lists.newArrayList("load", "--log.directory", quoteJson(logDir), "--connector.csv.ignoreLeadingWhitespaces", "true", "--connector.csv.ignoreTrailingWhitespaces", "true", "--connector.csv.url", ClassLoader.getSystemResource("ttl-timestamp.csv").toExternalForm(), "--driver.pooling.local.connections", "1", "--schema.keyspace", session.getKeyspace().get().asInternal(), "--schema.query", "insert into table_ttl_timestamp (key, value, loaded_at) values (:key, :value, now()) using ttl :t1 and timestamp :t2", "--schema.mapping", // map to t2 and t1 respectively
"*=*, created_at = __timestamp, time_to_live = __ttl");
ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_OK);
assertTTLAndTimestamp();
assertThat(logs).hasMessageContaining("The special __ttl mapping token has been deprecated").hasMessageContaining("The special __timestamp mapping token has been deprecated");
logs.clear();
}
use of com.datastax.oss.dsbulk.runner.DataStaxBulkLoader in project dsbulk by datastax.
the class CSVConnectorEndToEndCCMIT method extra_mapping_custom_query.
@Test
void extra_mapping_custom_query() {
List<String> args = new ArrayList<>();
args.add("load");
args.add("--connector.csv.url");
args.add(quoteJson(CsvUtils.CSV_RECORDS_UNIQUE));
args.add("--connector.csv.header");
args.add("false");
args.add("--schema.keyspace");
args.add(session.getKeyspace().get().asInternal());
args.add("--schema.query");
args.add(INSERT_INTO_IP_BY_COUNTRY);
args.add("--schema.mapping");
args.add("beginning_ip_address,ending_ip_address,beginning_ip_number,ending_ip_number," + "country_code,country_name,extra");
ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_ABORTED_FATAL_ERROR);
validateErrorMessageLogged("doesn't match any bound variable found in query", "extra");
}
use of com.datastax.oss.dsbulk.runner.DataStaxBulkLoader in project dsbulk by datastax.
the class CSVConnectorEndToEndCCMIT method should_truncate_and_round.
/**
* Test for DAT-224.
*/
@Test
void should_truncate_and_round() throws Exception {
session.execute("DROP TABLE IF EXISTS numbers");
session.execute("CREATE TABLE IF NOT EXISTS numbers (key varchar PRIMARY KEY, vdouble double, vdecimal decimal)");
List<String> args = new ArrayList<>();
args.add("load");
args.add("--connector.csv.url");
args.add(ClassLoader.getSystemResource("number.csv").toExternalForm());
args.add("--connector.csv.header");
args.add("true");
args.add("--connector.csv.delimiter");
args.add(";");
args.add("--connector.csv.comment");
args.add("#");
args.add("--codec.overflowStrategy");
args.add("TRUNCATE");
args.add("--schema.keyspace");
args.add(session.getKeyspace().get().asInternal());
args.add("--schema.table");
args.add("numbers");
args.add("--schema.mapping");
args.add("*=*");
ExitStatus loadStatus = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(loadStatus, STATUS_OK);
checkNumbersWritten(OverflowStrategy.TRUNCATE, UNNECESSARY, session);
FileUtils.deleteDirectory(logDir);
args = new ArrayList<>();
args.add("unload");
args.add("--connector.csv.url");
args.add(quoteJson(unloadDir));
args.add("--connector.csv.header");
args.add("false");
args.add("--connector.csv.delimiter");
args.add(";");
args.add("--connector.csv.maxConcurrentFiles");
args.add("1");
args.add("--codec.roundingStrategy");
args.add("FLOOR");
args.add("--codec.formatNumbers");
args.add("true");
args.add("--schema.keyspace");
args.add(session.getKeyspace().get().asInternal());
args.add("--schema.query");
args.add("SELECT key, vdouble, vdecimal FROM numbers");
ExitStatus unloadStatus = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(unloadStatus, STATUS_OK);
checkNumbersRead(OverflowStrategy.TRUNCATE, FLOOR, true, unloadDir);
FileUtils.deleteDirectory(logDir);
// check we can load from the unloaded dataset
args = new ArrayList<>();
args.add("load");
args.add("--connector.csv.url");
args.add(quoteJson(unloadDir));
args.add("--connector.csv.header");
args.add("false");
args.add("--connector.csv.delimiter");
args.add(";");
args.add("--codec.overflowStrategy");
args.add("TRUNCATE");
args.add("--schema.keyspace");
args.add(session.getKeyspace().get().asInternal());
args.add("--schema.table");
args.add("numbers");
args.add("--schema.mapping");
args.add("key,vdouble,vdecimal");
loadStatus = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(loadStatus, STATUS_OK);
checkNumbersWritten(OverflowStrategy.TRUNCATE, FLOOR, session);
}
Aggregations