Skip to content

Commit 1da2de0

Browse files
committed
fix(bulk-write): ensure table exists before bulk write
- Add logic to ensure the target table exists before starting bulk write - Update README with important notes about bulk write API usage - Refactor write loops in benchmark classes for better readability
1 parent c7402d4 commit 1da2de0

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

ingester-example/src/main/java/io/greptime/bench/benchmark/BulkWriteBenchmark.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,21 @@ public static void main(String[] args) throws Exception {
132132
* @param tableSchema the schema of the table to ensure
133133
* @param ctx the context for the operation
134134
*/
135-
private static void ensureTableExists(GreptimeDB greptimeDB, TableSchema tableSchema, TableDataProvider tableDataProvider, Context ctx) {
135+
private static void ensureTableExists(
136+
GreptimeDB greptimeDB, TableSchema tableSchema, TableDataProvider tableDataProvider, Context ctx) {
136137
Table initTable = Table.from(tableSchema);
137138
Iterator<Object[]> rows = tableDataProvider.rows();
138139
// Add an initial row to the table to get the table schema.
139140
initTable.addRow(rows.hasNext() ? rows.next() : new Object[0]);
140141
try {
141142
// Write an initial row to ensure the table exists.
142-
greptimeDB.write(Collections.singletonList(initTable), WriteOp.Insert, ctx).get();
143+
greptimeDB
144+
.write(Collections.singletonList(initTable), WriteOp.Insert, ctx)
145+
.get();
143146
// Delete the initial row to leave the table empty.
144-
greptimeDB.write(Collections.singletonList(initTable), WriteOp.Delete, ctx).get();
147+
greptimeDB
148+
.write(Collections.singletonList(initTable), WriteOp.Delete, ctx)
149+
.get();
145150
LOG.info("Table ensured for benchmark: {}", tableSchema.getTableName());
146151
} catch (Exception e) {
147152
LOG.error("Table creation may have been skipped if it already exists: {}", e.getMessage());

0 commit comments

Comments
 (0)