Skip to content

Commit 39818d2

Browse files
user feedback, futures are sweet, thanks chris and alex you guys are beautiful
1 parent 1b35ea6 commit 39818d2

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/main/java/com/datastax/cdm/CassandraDatasetManager.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.eclipse.jgit.api.errors.GitAPIException;
1313
import org.eclipse.jgit.api.errors.InvalidRemoteException;
1414
import org.eclipse.jgit.api.errors.TransportException;
15+
import org.eclipse.jgit.lib.RefUpdate;
1516

1617

1718
import javax.management.Query;
@@ -221,8 +222,8 @@ void install(String name) throws IOException, InterruptedException, GitAPIExcept
221222

222223
Config config = mapper.readValue(configFile, Config.class);
223224

224-
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
225225
{
226+
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
226227
Session session = cluster.connect();
227228

228229
StringBuilder createKeyspace = new StringBuilder();
@@ -233,6 +234,7 @@ void install(String name) throws IOException, InterruptedException, GitAPIExcept
233234
System.out.println(createKeyspace);
234235
session.execute("DROP KEYSPACE IF EXISTS " + config.keyspace);
235236
session.execute(createKeyspace.toString());
237+
cluster.close();
236238
}
237239

238240
System.out.println("Schema: " + schema);
@@ -274,17 +276,35 @@ void install(String name) throws IOException, InterruptedException, GitAPIExcept
274276
fieldlist.add(new Field(c.getName(), ftype));
275277
}
276278

279+
int totalComplete = 0;
280+
List<ResultSetFuture> futures = new ArrayList<>();
277281
for(CSVRecord record: records) {
278282
// generate a CQL statement
279283
String cql = generateCQL(table,
280284
record,
281285
fieldlist,
282286
types);
283-
session.execute(cql);
287+
288+
ResultSetFuture future = session.executeAsync(cql);
289+
futures.add(future);
290+
totalComplete++;
291+
if(totalComplete % 100 == 0) {
292+
for (ResultSetFuture f : futures) {
293+
f.getUninterruptibly();
294+
}
295+
futures.clear();
296+
}
297+
System.out.print("Complete: " + totalComplete + "\r");
298+
299+
}
300+
for (ResultSetFuture f : futures) {
301+
f.getUninterruptibly();
284302
}
303+
futures.clear();
304+
System.out.println("Done importing " + table);
285305
}
286306

287-
307+
cluster2.close();
288308
System.out.println("Loading data");
289309
}
290310

@@ -300,6 +320,7 @@ String generateCQL(String table,
300320
HashMap<String, String> types) {
301321

302322
HashSet needs_quotes = new HashSet();
323+
303324
needs_quotes.add("text");
304325
needs_quotes.add("datetime");
305326

@@ -323,6 +344,9 @@ String generateCQL(String table,
323344
if(needs_quotes.contains(f.type)) {
324345
v = "'" + v.replace("'", "''") + "'";
325346
}
347+
if(v.trim().equals("")) {
348+
v = "null";
349+
}
326350
values.add(v);
327351
}
328352

0 commit comments

Comments
 (0)