Skip to content

Commit b4520e9

Browse files
committed
update sample
1 parent 06202a2 commit b4520e9

File tree

4 files changed

+53
-52
lines changed

4 files changed

+53
-52
lines changed

tools/src/main/java/com/datastax/astra/tool/CsvLoaderAnoop.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public class CsvLoaderAnoop {
1717

1818
public static void main(String[] args) throws Exception {
1919
DataAPIClient client =
20-
new DataAPIClient("<replace_me>");
20+
new DataAPIClient("AstraCS:rhZhqUkdzcYSlRNUfZjiZApq:c36d4c0575d4e471a93618a1586bf7b6be970fc3a5442f711fd79a932f98fb09");
2121
Database db =
22-
client.getDatabase("<replace_me>");
22+
client.getDatabase("https://07cae943-ea78-4d65-ac2a-a9e819e2d5d3-us-east1.apps.astra.datastax.com");
2323
Collection<Document> collection =
24-
db.createCollection("anoop");
24+
db.createCollection("best_buy2");
2525
collection.deleteAll();
2626
CsvLoader.load(
2727
"/Users/cedricklunven/Downloads/anoop.csv",

tools/src/main/java/com/datastax/astra/tool/CsvLoaderLIsting.java

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.datastax.astra.tool;
2+
3+
import com.datastax.astra.client.Collection;
4+
import com.datastax.astra.client.DataAPIClient;
5+
import com.datastax.astra.client.Database;
6+
import com.datastax.astra.client.model.DataAPIKeywords;
7+
import com.datastax.astra.client.model.Document;
8+
import com.datastax.astra.tool.csv.CsvLoader;
9+
import com.datastax.astra.tool.csv.CsvLoaderSettings;
10+
import com.datastax.astra.tool.csv.CsvRowMapper;
11+
import lombok.extern.slf4j.Slf4j;
12+
13+
/**
14+
* Sample Code to load a CSV file into Astra using the DataStax Java Driver
15+
*/
16+
@Slf4j
17+
public class CsvLoaderListing {
18+
19+
20+
public static void main(String[] args) throws Exception {
21+
// Get an empty Collection
22+
DataAPIClient client = new DataAPIClient("<replace_me>");
23+
Database db = client.getDatabase("<replace_me>");
24+
Collection<Document> collection = db.createCollection("airbnb");
25+
collection.deleteAll();
26+
27+
// Zou !
28+
String csvFilename = "/Users/cedricklunven/Downloads/listings.csv";
29+
CsvLoader.load(csvFilename, collection, new CsvRowMapper() {
30+
@Override
31+
public Document map(Document doc) {
32+
doc.put(DataAPIKeywords.ID.getKeyword(), doc.get("id"));
33+
doc.remove("id");
34+
return doc;
35+
}
36+
});
37+
38+
}
39+
40+
}

tools/src/main/java/com/datastax/astra/tool/csv/CsvLoader.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
@Slf4j
2020
public class CsvLoader {
2121

22+
/**
23+
* Distributed import of CSV file into Astra.
24+
*
25+
* @throws Exception
26+
* exception in processing CSV
27+
*/
28+
public static void load(String fileName, Collection<Document> collection, CsvRowMapper processor) throws Exception {
29+
load(fileName, CsvLoaderSettings.builder().build(), collection, processor);
30+
}
31+
2232
/**
2333
* Distributed import of CSV file into Astra.
2434
*

0 commit comments

Comments
 (0)