Skip to content

Commit

Permalink
add Java code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicecui committed Dec 25, 2024
1 parent debf981 commit 64f019b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/user-guide/ingest-data/for-iot/grpc-sdks/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ hints := []*ingesterContext.Hint{
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
ctx = ingesterContext.New(ctx, ingesterContext.WithHints(hints))
// Use the ingesterContext when writing data to GreptimeDB.
// The data object is described in the following sections.
// The `data` object is described in the following sections.
resp, err := c.client.Write(ctx, data)
if err != nil {
return err
Expand Down
8 changes: 6 additions & 2 deletions docs/user-guide/ingest-data/for-iot/grpc-sdks/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ For customizing the connection options, please refer to [API Documentation](#ing

<div id="set-table-options">

You can set table options using the `ingesterContext` context.
You can set table options using the `Context`.
For example, to set the `ttl` option, use the following code:

```java
TODO
Context ctx = Context.newDefault();
ctx.withHint("ttl", "3d");
// Use the ctx when writing data to GreptimeDB
// The data object `cpuMetric` and `memMetric` are described in the following sections
CompletableFuture<Result<WriteOk, Err>> future = greptimeDB.write(Arrays.asList(cpuMetric, memMetric), WriteOp.Insert, ctx);
```

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ hints := []*ingesterContext.Hint{
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
ctx = ingesterContext.New(ctx, ingesterContext.WithHints(hints))
// 使用 ingesterContext写入数据到 GreptimeDB
// data 对象在之后的章节中描述
// `data` 对象在之后的章节中描述
resp, err := c.client.Write(ctx, data)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ GreptimeDB client = GreptimeDB.create(opts);

<div id="set-table-options">

你可以
你可以使用 `Context` 设置表选项。
例如,使用以下代码设置 `ttl` 选项:

```java
TODO
Context ctx = Context.newDefault();
ctx.withHint("ttl", "3d");
// 使用 ctx 对象写入数据
// `cpuMetric` 和 `memMetric` 是定义的数据对象,之后的章节中有详细描述
CompletableFuture<Result<WriteOk, Err>> future = greptimeDB.write(Arrays.asList(cpuMetric, memMetric), WriteOp.Insert, ctx);
```

</div>
Expand Down

0 comments on commit 64f019b

Please sign in to comment.