Skip to content

Commit

Permalink
chore: more friendly write api
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun committed Jan 8, 2024
1 parent 9de9b60 commit 461588a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
myMetric2s.add(m);
}

List<List<?>> pojos = Arrays.asList(myMetric1s, myMetric2s);

// For performance reasons, the SDK is designed to be purely asynchronous.
// The return value is a future object. If you want to immediately obtain
// the result, you can call `future.get()`.
CompletableFuture<Result<WriteOk, Err>> puts = greptimeDB.writePOJOs(pojos);
CompletableFuture<Result<WriteOk, Err>> puts = greptimeDB.writePOJOs(myMetric1s, myMetric2s);

Result<WriteOk, Err> result = puts.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
myMetric4.addRow(tag1v, tag2v, ts, field1, field2);
}

Collection<Table> tables = Arrays.asList(myMetric3, myMetric4);

// For performance reasons, the SDK is designed to be purely asynchronous.
// The return value is a future object. If you want to immediately obtain
// the result, you can call `future.get()`.
CompletableFuture<Result<WriteOk, Err>> future = greptimeDB.write(tables);
CompletableFuture<Result<WriteOk, Err>> future = greptimeDB.write(myMetric3, myMetric4);

Result<WriteOk, Err> result = future.get();

Expand Down
7 changes: 7 additions & 0 deletions ingester-protocol/src/main/java/io/greptime/Write.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.greptime.models.WriteOk;
import io.greptime.rpc.Context;

import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;

Expand All @@ -30,6 +31,12 @@
* @author jiachun.fjc
*/
public interface Write {
/**
* @see #write(Collection, WriteOp, Context)
*/
default CompletableFuture<Result<WriteOk, Err>> write(Table... tables) {
return write(Arrays.asList(tables), WriteOp.Insert, Context.newDefault());
}

/**
* @see #write(Collection, WriteOp, Context)
Expand Down
7 changes: 7 additions & 0 deletions ingester-protocol/src/main/java/io/greptime/WritePOJO.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.greptime.models.WriteOk;
import io.greptime.rpc.Context;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand All @@ -30,6 +31,12 @@
* @author jiachun.fjc
*/
public interface WritePOJO {
/**
* @see #writePOJOs(Collection, WriteOp, Context)
*/
default CompletableFuture<Result<WriteOk, Err>> writePOJOs(List<?>... pojos) {
return writePOJOs(Arrays.asList(pojos), WriteOp.Insert, Context.newDefault());
}
/**
* @see #writePOJOs(Collection, WriteOp, Context)
*/
Expand Down

0 comments on commit 461588a

Please sign in to comment.