Skip to content

Commit

Permalink
docs: set table options via gRPC SDK (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicecui authored Dec 26, 2024
1 parent 712c48f commit a8a10a9
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 8 deletions.
34 changes: 30 additions & 4 deletions docs/user-guide/ingest-data/for-iot/grpc-sdks/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Import the library in your code:
```go
import (
greptime "github.com/GreptimeTeam/greptimedb-ingester-go"
ingesterContext "github.com/GreptimeTeam/greptimedb-ingester-go/context"
"github.com/GreptimeTeam/greptimedb-ingester-go/table"
"github.com/GreptimeTeam/greptimedb-ingester-go/table/types"
)
Expand All @@ -60,6 +61,31 @@ cli, _ := greptime.NewClient(cfg)
```
</div>

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

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

```go
hints := []*ingesterContext.Hint{
{
Key: "ttl",
Value: "3d",
},
}

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.
resp, err := c.client.Write(ctx, data)
if err != nil {
return err
}
```

</div>

<div id="low-level-object">

```go
Expand Down Expand Up @@ -123,7 +149,7 @@ if err != nil {
<div id="insert-rows">

```go
resp, err := cli.Write(context.Background(), cpuMetric, memMetric)
resp, err := cli.Write(ctx, cpuMetric, memMetric)
if err != nil {
// Handle error appropriately
}
Expand All @@ -135,7 +161,7 @@ log.Printf("affected rows: %d\n", resp.GetAffectedRows().GetValue())
<div id="streaming-insert">

```go
err := cli.StreamWrite(context.Background(), cpuMetric, memMetric)
err := cli.StreamWrite(ctx, cpuMetric, memMetric)
if err != nil {
// Handle error appropriately
}
Expand Down Expand Up @@ -201,7 +227,7 @@ memMetrics := []MemMetric{
<div id="high-level-style-insert-data">

```go
resp, err := cli.WriteObject(context.Background(), cpuMetrics)
resp, err := cli.WriteObject(ctx, cpuMetrics)
log.Printf("affected rows: %d\n", resp.GetAffectedRows().GetValue())
```

Expand All @@ -210,7 +236,7 @@ log.Printf("affected rows: %d\n", resp.GetAffectedRows().GetValue())
<div id="high-level-style-streaming-insert">

```go
err := cli.StreamWriteObject(context.Background(), cpuMetrics)
err := cli.StreamWriteObject(ctx, cpuMetrics)
```

Close the stream writing after all data has been written.
Expand Down
14 changes: 14 additions & 0 deletions docs/user-guide/ingest-data/for-iot/grpc-sdks/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ For customizing the connection options, please refer to [API Documentation](#ing

</div>

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

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

```java
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>

<div id="low-level-object">

Expand Down
13 changes: 13 additions & 0 deletions docs/user-guide/ingest-data/for-iot/grpc-sdks/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ The following example shows how to set the username and password when using the
Each row item in a table consists of three types of columns: `Tag`, `Timestamp`, and `Field`. For more information, see [Data Model](/user-guide/concepts/data-model.md).
The types of column values could be `String`, `Float`, `Int`, `Timestamp`, `JSON` etc. For more information, see [Data Types](/reference/sql/data-types.md).

## Set table options

Although the time series table is created automatically when writing data to GreptimeDB via the SDK,
you can still configure table options.
The SDK supports the following table options:

- `auto_create_table`: Default is `True`. If set to `False`, it indicates that the table already exists and does not need automatic creation, which can improve write performance.
- `ttl`, `append_mode`, `merge_mode`: For more details, refer to the [table options](/reference/sql/create.md#table-options).

<InjectContent id="set-table-options" content={props.children}/>

For how to write data to GreptimeDB, see the following sections.

## Low-level API

The GreptimeDB low-level API provides a straightforward method to write data to GreptimeDB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go get -u github.com/GreptimeTeam/greptimedb-ingester-go@VAR::goSdkVersion
```go
import (
greptime "github.com/GreptimeTeam/greptimedb-ingester-go"
ingesterContext "github.com/GreptimeTeam/greptimedb-ingester-go/context"
"github.com/GreptimeTeam/greptimedb-ingester-go/table"
"github.com/GreptimeTeam/greptimedb-ingester-go/table/types"
)
Expand All @@ -59,6 +60,31 @@ cli, _ := greptime.NewClient(cfg)
```
</div>

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

你可以使用 `ingesterContext` 设置表选项。
例如设置 `ttl` 选项:

```go
hints := []*ingesterContext.Hint{
{
Key: "ttl",
Value: "3d",
},
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
ctx = ingesterContext.New(ctx, ingesterContext.WithHints(hints))
// 使用 ingesterContext写入数据到 GreptimeDB
// `data` 对象在之后的章节中描述
resp, err := c.client.Write(ctx, data)
if err != nil {
return err
}
```

</div>

<div id="low-level-object">

```go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ GreptimeDB client = GreptimeDB.create(opts);

</div>

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

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

```java
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>

<div id="low-level-object">

```java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ GreptimeDB 提供了用于高吞吐量数据写入的 ingester 库。
表中的每条行数据包含三种类型的列:`Tag``Timestamp``Field`。更多信息请参考 [数据模型](/user-guide/concepts/data-model.md)
列值的类型可以是 `String``Float``Int``JSON`, `Timestamp` 等。更多信息请参考 [数据类型](/reference/sql/data-types.md)

## 设置表选项

虽然在通过 SDK 向 GreptimeDB 写入数据时会自动创建时间序列表,但你仍然可以配置表选项。
SDK 支持以下表选项:

- `auto_create_table`:默认值为 `True`。如果设置为 `False`,则表示表已经存在且不需要自动创建,这可以提高写入性能。
- `ttl``append_mode``merge_mode`:更多详情请参考[表选项](/reference/sql/create.md#table-options)

<InjectContent id="set-table-options" content={props.children}/>

关于如何向 GreptimeDB 写入数据,请参考以下各节。

## 低层级 API

GreptimeDB 的低层级 API 通过向具有预定义模式的 `table` 对象添加 `row` 来写入数据。
Expand Down
4 changes: 2 additions & 2 deletions variables/variables-0.11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export const variables = {
greptimedbVersion: 'v0.11.1',
prometheusVersion: 'v2.52.0',
nodeExporterVersion: 'v1.8.0',
goSdkVersion: 'v0.5.4',
javaSdkVersion: '0.9.1',
goSdkVersion: 'v0.6.0',
javaSdkVersion: '0.11.0',
};
4 changes: 2 additions & 2 deletions variables/variables-nightly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export const variables = {
greptimedbVersion: 'v0.11.1',
prometheusVersion: 'v2.52.0',
nodeExporterVersion: 'v1.8.0',
goSdkVersion: 'v0.5.4',
javaSdkVersion: '0.9.1',
goSdkVersion: 'v0.6.0',
javaSdkVersion: '0.11.0',
};

0 comments on commit a8a10a9

Please sign in to comment.