1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| // Construct JSON data
int numRecords = 100;
ObjectMapper om = new ObjectMapper();
List<String> jsonObjects = new ArrayList<>();
for (int i = 0; i < numRecords; i++)
{
Map<String,String> data = new HashMap<>();
data.put("id", Integer.toString(i));
data.put("category", "Technology");
data.put("name", "DVD #" + i);
data.put("description", "Lightweight storage for low-res screenplays and licensed software, #" + i);
data.put("stock", Integer.toString(i + 5000));
// Convert map to JSON and add to list
jsonObjects.add(om.writeValueAsString(data));
}
// Connect to database
String url = "https://abcdefg.cloud.kinetica.com/hijklmn/gpudb-0"
GPUdb.Options options = new GPUdb.Options();
options.setUsername("auser");
options.setPassword("apassword");
GPUdb kdb = new GPUdb(url, options);
// Set batch size
int batchSize = 10000;
// Issue BulkInserter JSON ingest call
try (BulkInserter<String> bi = new BulkInserter<>(
kdb, tableName, Type.fromTable(kdb, tableName),
batchSize, null, new WorkerList(kdb) ))
{
for (String jsonObject : jsonObjects)
bi.insert(jsonObject);
}
|