Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blog/release-0-15-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Release date: July 24, 2025
* fix: aggr group by all partition cols use partial commutative by [@discord9](https://github.com/discord9) in [#6534](https://github.com/GreptimeTeam/greptimedb/pull/6534)
* fix: estimate mem size for bulk ingester by [@fengys1996](https://github.com/fengys1996) in [#6550](https://github.com/GreptimeTeam/greptimedb/pull/6550)
* fix: flow mirror cache by [@discord9](https://github.com/discord9) in [#6551](https://github.com/GreptimeTeam/greptimedb/pull/6551)
* fix: closee issue #6555 return empty result by [@yihong0618](https://github.com/yihong0618) in [#6569](https://github.com/GreptimeTeam/greptimedb/pull/6569)
* fix: close issue #6555 return empty result by [@yihong0618](https://github.com/yihong0618) in [#6569](https://github.com/GreptimeTeam/greptimedb/pull/6569)

### 🚜 Refactor
* refactor(flow): faster time window expr by [@discord9](https://github.com/discord9) in [#6495](https://github.com/GreptimeTeam/greptimedb/pull/6495)
Expand Down
2 changes: 1 addition & 1 deletion blog/release-0-16-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Release date: August 06, 2025
### 🐛 Bug Fixes

* fix: aggr group by all partition cols use partial commutative by [@discord9](https://github.com/discord9) in [#6534](https://github.com/GreptimeTeam/greptimedb/pull/6534)
* fix: closee issue #6555 return empty result by [@yihong0618](https://github.com/yihong0618) in [#6569](https://github.com/GreptimeTeam/greptimedb/pull/6569)
* fix: close issue #6555 return empty result by [@yihong0618](https://github.com/yihong0618) in [#6569](https://github.com/GreptimeTeam/greptimedb/pull/6569)
* fix: ignore target files in make fmt-check by [@yihong0618](https://github.com/yihong0618) in [#6560](https://github.com/GreptimeTeam/greptimedb/pull/6560)
* fix: close issue #6586 make pg also show error as mysql by [@yihong0618](https://github.com/yihong0618) in [#6587](https://github.com/GreptimeTeam/greptimedb/pull/6587)
* fix: add map datatype conversion in copy_table_from (#6185) by [@Arshdeep54](https://github.com/Arshdeep54) in [#6422](https://github.com/GreptimeTeam/greptimedb/pull/6422)
Expand Down
6 changes: 3 additions & 3 deletions docs/db-cloud-shared/migrate/migrate-from-influxdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ The similar query in GreptimeDB SQL would be:

```sql [SQL]
SELECT
ts,
greptime_timestamp,
host,
AVG(cpu) RANGE '1h' as mean_cpu
FROM
monitor
WHERE
ts > NOW() - '24 hours'::INTERVAL
greptime_timestamp > NOW() - '24 hours'::INTERVAL
ALIGN '1h' TO NOW
ORDER BY ts DESC;
ORDER BY greptime_timestamp DESC;
```

In this SQL query,
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/sql/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ Output:

Please refer to the [Trigger syntax](/reference/sql/trigger-syntax.md#show-triggers) documentation.

## SHOW CREATE TRIGGER

Please refer to the [Trigger syntax](/reference/sql/trigger-syntax.md#show-create-trigger) documentation.

## Extensions to SHOW Statements

Some extensions to `SHOW` statements accompany the implementation of [`INFORMATION_SCHEMA`](/reference/sql/information-schema/overview.md) just like MySQL, they also accept a `WHERE` clause that provides more flexibility in specifying which rows to display.
Expand Down
47 changes: 40 additions & 7 deletions docs/reference/sql/tql.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@ description: Covers the TQL keyword for executing Time-Series Query Language in

# TQL

The `TQL` keyword executes TQL language in SQL. The TQL is Time-Series Query Language, which is an extension for Prometheus's [PromQL](https://prometheus.io/docs/prometheus/latest/querying/basics/) in GreptimeDB.
The `TQL` keyword executes TQL language in SQL. The TQL is Telemetry Query Language, which is an extension for Prometheus's [PromQL](https://prometheus.io/docs/prometheus/latest/querying/basics/) in GreptimeDB.

## EVAL

### Syntax

```sql
TQL [EVAL | EVALUATE] (start, end, step) expr
TQL [EVAL | EVALUATE] (start, end, step, [lookback]) expr [AS alias]
```

The `start`, `end` and `step` are the query parameters just like [Prometheus Query API](https://prometheus.io/docs/prometheus/latest/querying/api/):

- `start`: `<rfc3339 | unix_timestamp>`: Start timestamp, inclusive.
- `end`: `<rfc3339 | unix_timestamp>`: End timestamp, inclusive.
- `step`: `<duration | float>`: Query resolution step width in `duration` format or float number of seconds.
- `start`: `<rfc3339 | unix_timestamp | expression>`: The start timestamp of the query; the range is inclusive of this value.
- `end`: `<rfc3339 | unix_timestamp | expression>`: The end timestamp of the query; the range is inclusive of this value.
- `step`: `<duration | float>`: The query resolution step, specified as a `duration` or a floating-point number of seconds.
- `lookback`: `<duration | float>`: The maximum lookback duration for evaluation, default is 5 minutes and optional.

The `expr` is the TQL expression query string.
`expr` is the TQL (PromQL) query string.

The optional `AS alias` clause allows you to provide an alias for the query result. This is useful for giving meaningful names to the output columns.

### Examples

Expand All @@ -33,6 +36,36 @@ TQL eval (1677057993, 1677058993, '1m') rate(prometheus_http_requests_total{job=

will get a result just like other normal SQL queries.

`start` and `end` can also be time expressions that evaluate to constants. For example, to query the past 3 hours:

```sql
TQL EVAL (now() - interval '3' hours, now(), '1m')
sum by (namespace, pod) (
increase(kube_pod_container_status_restarts_total[10m:30s])
);
```

To query data for the past day:

```sql
TQL EVAL (
date_trunc('day', now() - interval '1' day),
date_trunc('day', now(),
'1m'
)
sum by (namespace) (
rate(http_requests_total[5m:30s])
);
```

You can also use value aliasing to give a meaningful name to your query result:

```sql
TQL eval (0, 10, '5s') {__name__="test"} AS test_series;
```

This will return the results with the column named `test_series` instead of the default column name.

## EXPLAIN

`EXPLAIN` displays both the logical plan and execution plan for a given PromQL query. The syntax is as follows:
Expand All @@ -47,7 +80,7 @@ For example, to explain the PromQL `sum by (instance) (rate(node_disk_written_by
TQL EXPLAIN sum by (instance) (rate(node_disk_written_bytes_total[2m])) > 50;
```

Notice that since the given query won't be actually executed, the triple `(start, end, step)` is not necessary. But you can still provide it like in `TQL EVAL`:
Notice that since the given query won't be actually executed, the triple `(start, end, step, [lookback])` is not necessary. But you can still provide it like in `TQL EVAL`:

```
TQL EXPLAIN (0, 100, '10s') sum by (instance) (rate(node_disk_written_bytes_total[2m])) > 50;
Expand Down
14 changes: 14 additions & 0 deletions docs/reference/sql/trigger-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ For example:
SHOW TRIGGERS WHERE name = 'load1_monitor';
```

## SHOW CREATE TRIGGER

To show the Trigger's definition:

```sql
SHOW CREATE TRIGGER <trigger-name>;
```

For example:

```sql
SHOW CREATE TRIGGER load1_monitor;
```

## DROP TRIGGER

To delete a trigger, use the following `DROP TRIGGER` clause:
Expand Down
20 changes: 10 additions & 10 deletions docs/user-guide/ingest-data/for-iot/influxdb-line-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ In the GreptimeDB data model, the data is represented as follows in the `census`

```sql
+---------------------+----------+-----------+------+------+
| ts | location | scientist | bees | ants |
| greptime_timestamp | location | scientist | bees | ants |
+---------------------+----------+-----------+------+------+
| 2019-08-18 00:00:00 | klamath | anderson | 23 | NULL |
| 2019-08-18 00:06:00 | klamath | anderson | 28 | NULL |
Expand All @@ -192,15 +192,15 @@ In the GreptimeDB data model, the data is represented as follows in the `census`
The schema of the `census` table is as follows:

```sql
+-----------+----------------------+------+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+-----------+----------------------+------+------+---------+---------------+
| location | String | PRI | YES | | TAG |
| scientist | String | PRI | YES | | TAG |
| bees | Float64 | | YES | | FIELD |
| ts | TimestampNanosecond | PRI | NO | | TIMESTAMP |
| ants | Float64 | | YES | | FIELD |
+-----------+----------------------+------+------+---------+---------------+
+--------------------+----------------------+------+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+--------------------+----------------------+------+------+---------+---------------+
| location | String | PRI | YES | | TAG |
| scientist | String | PRI | YES | | TAG |
| bees | Float64 | | YES | | FIELD |
| greptime_timestamp | TimestampNanosecond | PRI | NO | | TIMESTAMP |
| ants | Float64 | | YES | | FIELD |
+--------------------+----------------------+------+------+---------+---------------+
```

## Reference
Expand Down
6 changes: 3 additions & 3 deletions docs/user-guide/logs/manage-pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ At this point, the Pipeline processing is successful, and the output is as follo
],
"schema": [
{
"colume_type": "FIELD",
"column_type": "FIELD",
"data_type": "STRING",
"fulltext": false,
"name": "message"
},
{
"colume_type": "TIMESTAMP",
"column_type": "TIMESTAMP",
"data_type": "TIMESTAMP_NANOSECOND",
"fulltext": false,
"name": "time"
Expand Down Expand Up @@ -435,4 +435,4 @@ After customizing the DDL to meet your requirements, execute it manually before

**Notes:**
1. The API only infers the table schema from the pipeline configuration; it doesn't check if the table already exists.
2. The API doesn't account for table suffixes. If you're using `dispatcher`, `table_suffix`, or table suffix hints in your pipeline configuration, you'll need to adjust the table name manually.
2. The API doesn't account for table suffixes. If you're using `dispatcher`, `table_suffix`, or table suffix hints in your pipeline configuration, you'll need to adjust the table name manually.
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ from(bucket: "public")

```sql [SQL]
SELECT
ts,
greptime_timestamp,
host,
AVG(cpu) RANGE '1h' as mean_cpu
FROM
monitor
WHERE
ts > NOW() - '24 hours'::INTERVAL
greptime_timestamp > NOW() - '24 hours'::INTERVAL
ALIGN '1h' TO NOW
ORDER BY ts DESC;
ORDER BY greptime_timestamp DESC;
```

在该 SQL 查询中,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ SHOW FULL PROCESSLIST;

请参考 [Trigger 语法](/reference/sql/trigger-syntax.md#show-triggers)文档。

## SHOW CREATE TRIGGER

请参考 [Trigger 语法](/reference/sql/trigger-syntax.md#show-create-trigger)文档。

## SHOW 语句的扩展

与 MySQL 类似,一些 `SHOW` 语句的扩展伴随着 [`INFORMATION_SCHEMA`](/reference/sql/information-schema/overview.md) 的实现,它们还接受 `WHERE` 子句,提供了在指定显示的行时更大的灵活性。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,67 @@ description: 介绍了 `TQL` 关键字及其在 GreptimeDB 中的用法,包括

# TQL

`TQL` 关键字在 SQL 中执行 TQL 语言。TQL 是 Time-Series Query Language 的缩写,是 GreptimeDB 中对 Prometheus 的 [PromQL](https://prometheus.io/docs/prometheus/latest/querying/basics/) 的扩展。
`TQL` 关键字在 SQL 中执行 TQL 语言。TQL 是 Telemetry Query Language 的缩写,是 GreptimeDB 中对 Prometheus 的 [PromQL](https://prometheus.io/docs/prometheus/latest/querying/basics/) 的扩展。

## EVAL

### Syntax

```sql
TQL [EVAL | EVALUATE] (start, end, step) expr
TQL [EVAL | EVALUATE] (start, end, step, [lookback]) expr [AS alias]
```

`start`, `end` 和 `step` 是查询参数,就像 [Prometheus Query API](https://prometheus.io/docs/prometheus/latest/querying/api/) 一样:

- `start`: `<rfc3339 | unix_timestamp>`: Start 时间戳,范围中包含该值。
- `end`: `<rfc3339 | unix_timestamp>`: End 时间戳,范围中包含该值。
- `start`: `<rfc3339 | unix_timestamp | expression >`: 查询的起始时间戳,范围中包含该值。
- `end`: `<rfc3339 | unix_timestamp | expression>`: 查询的截止时间戳,范围中包含该值。
- `step`: `<duration | float>`: 查询分辨率步长,采用 `duration` 格式或浮点秒数。
- `lookback`: `<duration | float>`: 查询评估的最大过去持续时间,默认 5 分钟,可选参数。

`expr` 是 TQL 表达式查询字符串。
`expr` 是 TQL (PromQL) 的查询字符串。

可选的 `AS alias` 子句允许你为查询结果提供别名。这有助于为输出列提供有意义的名称。

### 示例

返回过去 5 分钟内 `http_requests_total` 指标的所有时间序列的每秒值:

```sql
TQL eval (1677057993, 1677058993, '1m') rate(prometheus_http_requests_total{job="prometheus"}[5m]);
TQL EVAL (1677057993, 1677058993, '1m')
rate(prometheus_http_requests_total{job="prometheus"}[5m]);
```

其查询结果和 SQL 查询结果类似。

`start` 和 `end` 还可以是可以被求值为常量的时间表达式,例如查询过去 3 个小时:

```sql
TQL EVAL (now() - interval '3' hours, now(), '1m')
sum by (namespace, pod) (
increase(kube_pod_container_status_restarts_total[10m:30s])
);
```

查询过去一天的数据:
```sql
TQL EVAL (
date_trunc('day', now() - interval '1' day),
date_trunc('day', now()),
'1m'
)
sum by (namespace) (
rate(http_requests_total[5m:30s])
);
```

你也可以使用值别名为查询结果提供有意义的名称:

```sql
TQL eval (0, 10, '5s') {__name__="test"} AS test_series;
```

这将返回列名为 `test_series` 而不是默认列名的结果。

## EXPLAIN

`EXPLAIN` 展示特定 PromQL 查询的逻辑计划和执行计划,其语法如下:
Expand All @@ -47,7 +80,7 @@ TQL EXPLAIN expr;
TQL EXPLAIN sum by (instance) (rate(node_disk_written_bytes_total[2m])) > 50;
```

注意该查询实际上没有被执行,所以 `(start, end, step)` 不是必需的,但你仍然可以像在 `TQL EVAL` 中一样提供这些参数:
注意该查询实际上没有被执行,所以 `(start, end, step, [lookback])` 不是必需的,但你仍然可以像在 `TQL EVAL` 中一样提供这些参数:

```
TQL EXPLAIN (0, 100, '10s') sum by (instance) (rate(node_disk_written_bytes_total[2m])) > 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ SHOW TRIGGERS WHERE <condition>;
SHOW TRIGGERS WHERE name = 'load1_monitor';
```

## SHOW CREATE TRIGGER

用于显示 TRIGGER 的定义:

```sql
SHOW CREATE TRIGGER <trigger-name>;
```

例如:

```sql
SHOW CREATE TRIGGER load1_monitor;
```

## DROP TRIGGER

请使用以下 `DROP TRIGGER` 语句删除 Trigger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ census,location=portland,scientist=mullen ants=32 1566086760000000000

```sql
+---------------------+----------+-----------+------+------+
| ts | location | scientist | bees | ants |
| greptime_timestamp | location | scientist | bees | ants |
+---------------------+----------+-----------+------+------+
| 2019-08-18 00:00:00 | klamath | anderson | 23 | NULL |
| 2019-08-18 00:06:00 | klamath | anderson | 28 | NULL |
Expand All @@ -191,15 +191,15 @@ census,location=portland,scientist=mullen ants=32 1566086760000000000
`census` 表结构如下:

```sql
+-----------+----------------------+------+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+-----------+----------------------+------+------+---------+---------------+
| location | String | PRI | YES | | TAG |
| scientist | String | PRI | YES | | TAG |
| bees | Float64 | | YES | | FIELD |
| ts | TimestampNanosecond | PRI | NO | | TIMESTAMP |
| ants | Float64 | | YES | | FIELD |
+-----------+----------------------+------+------+---------+---------------+
+--------------------+----------------------+------+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+--------------------+----------------------+------+------+---------+---------------+
| location | String | PRI | YES | | TAG |
| scientist | String | PRI | YES | | TAG |
| bees | Float64 | | YES | | FIELD |
| greptime_timestamp | TimestampNanosecond | PRI | NO | | TIMESTAMP |
| ants | Float64 | | YES | | FIELD |
+--------------------+----------------------+------+------+---------+---------------+
```

## 参考
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ curl -X "POST" "http://localhost:4000/v1/pipelines/dryrun?pipeline_name=test" \
],
"schema": [
{
"colume_type": "FIELD",
"column_type": "FIELD",
"data_type": "STRING",
"fulltext": false,
"name": "message"
},
{
"colume_type": "TIMESTAMP",
"column_type": "TIMESTAMP",
"data_type": "TIMESTAMP_NANOSECOND",
"fulltext": false,
"name": "time"
Expand Down
Loading