# Greptime 双周精选 （8.28-9.17）｜GreptimeDB 贡献者地图首次扩大到非洲

Source: https://greptime.cn/blogs/2023-09-20-biweekly

## 内容概述

作为一个成长中的开源项目，GreptimeDB 的进展离不开来自全球的社区贡献者们，感谢各位！

过去三周，我们所有项目中共有 **189** 个 PR 被合并，以下 4 个是这段时间较为重要的 PR 总结：

- **优化了 SQL 的数据类型**

- **通过 `ALTER TABLE` 支持了增加主键列**

- **重构了分布式结构中的心跳协议**

- **限制了 TIME INDEX 类型**

## 社区贡献者名单

在过去的三周里，共有来自外部的 **2 位贡献者**，累计 **2 个 PR 被成功合并**，还有很多待合并的 PR。

祝贺以下各位在过去 3 周内成为我们活跃的贡献者：

- @[NiwakaDev](https://github.com/NiwakaDev) ([db#2267](https://github.com/GreptimeTeam/greptimedb/pull/2267))

- @[Lilit0x](https://github.com/Lilit0x)([db#2400](https://github.com/GreptimeTeam/greptimedb/pull/2400))

🎉 热烈欢迎 @[Lilit0x](https://github.com/Lilit0x) 作为新的贡献者加入社区并成功合并了首个 PR [db#2400](https://github.com/GreptimeTeam/greptimedb/pull/2400)，还有更多来自其他独立贡献者的 PR 正在等待合并。

同时衷心感谢我们所有的成员和贡献者！是你们的付出让我们的项目得以成功，也是你们让 GreptimeDB 成为一个更优质的产品。让我们一起努力，建立一个更棒的社区！

## PR 亮点

### [db#2331](https://github.com/GreptimeTeam/greptimedb/pull/2331) 优化了 SQL 的数据类型

在这个 PR 之前，`CREATE TABLE` 和 `DESC TABLE` 中展示的数据类型不同，这让用户感到困惑，例如：

```sql
CREATE TABLE data_types (
  s string,
  tint tinyint,
  sint smallint,
  i int,
  bint bigint,
  v varchar,
  f float,
  d double,
  b boolean,
  vb varbinary,
  dt date,
  dtt datetime,
  ts0 timestamp(0),
  ts3 timestamp(3),
  ts6 timestamp(6),
  ts9 timestamp(9) DEFAULT CURRENT_TIMESTAMP TIME INDEX,
  PRIMARY KEY(s));
```

```sql
+--------+----------------------+------+------+---------------------+---------------+
| Column | Type                 | Key  | Null | Default             | Semantic Type |
+--------+----------------------+------+------+---------------------+---------------+
| s      | String               | PRI  | YES  |                     | TAG           |
| tint   | Int8                 |      | YES  |                     | FIELD         |
| sint   | Int16                |      | YES  |                     | FIELD         |
| i      | Int32                |      | YES  |                     | FIELD         |
| bint   | Int64                |      | YES  |                     | FIELD         |
| v      | String               |      | YES  |                     | FIELD         |
| f      | Float32              |      | YES  |                     | FIELD         |
| d      | Float64              |      | YES  |                     | FIELD         |
| b      | Boolean              |      | YES  |                     | FIELD         |
| vb     | Binary               |      | YES  |                     | FIELD         |
| dt     | Date                 |      | YES  |                     | FIELD         |
| dtt    | DateTime             |      | YES  |                     | FIELD         |
| ts0    | TimestampSecond      |      | YES  |                     | FIELD         |
| ts3    | TimestampMillisecond |      | YES  |                     | FIELD         |
| ts6    | TimestampMicrosecond |      | YES  |                     | FIELD         |
| ts9    | TimestampNanosecond  | PRI  | NO   | current_timestamp() | TIMESTAMP     |
+--------+----------------------+------+------+---------------------+---------------+
16 rows in set (0.00 sec)
```

这个 PR 为 SQL 数据类型增加了别名，如下所示：

- TimestampSecond, Timestamp_s, Timestamp_sec for Timestamp(0).

- TimestampMillisecond, Timestamp_ms for Timestamp(3).

- TimestampMicrosecond, Timestamp_us for Timestamp(6).

- TimestampNanosecond, Timestamp_ns for Timestamp(9).

- INT8 for tinyint

- INT16 for smallint

- INT32 for int

- INT64 for bigint

- And UINT8, UINT16 etc. for UnsignedTinyint etc.

现在，你也可以在 SQL 中使用 GreptimeDB 的类型去创建表：

```sql
 CREATE TABLE data_types (
  s String,
  tint Int8,
  sint Int16,
  i Int32,
  bint Int64,
  v String,
  f Float32,
  d Float64,
  b Boolean,
  vb Varbinary,
  dt Date,
  dtt DateTime,
  ts0 TimestampSecond,
  ts3 TimestampMillisecond,
  ts6 TimestampMicrosecond,
  ts9 TimestampNanosecond DEFAULT CURRENT_TIMESTAMP TIME INDEX,
  PRIMARY KEY(s));
```

### [db#2310](https://github.com/GreptimeTeam/greptimedb/pull/2310) 通过 `ALTER TABLE` 支持了增加主键列

时间序列数据中的 Label 或者 Tag 对应到 Table 模型后被 GreptimeDB 视为主键，所以有必要通过 `ALTER TABLE` 来支持增加主键列。

### [db#96（greptime-proto)](https://github.com/GreptimeTeam/greptimedb/pull/96) 重构了分布式结构中的心跳协议

在即将发布的 0.4 版本中，我们对整个数据库架构进行了深度重构和升级。首先面临重构的是发挥分布式协调基础通信作用的心跳协议。其改造的初衷是更高效地管理大规模的集群和更多的 region 数量，为此我们裁剪了心跳包大小以降低通信层的负担。例如，我们移除了不必要的 NodeStat，去除了 CPU、Load 等信息，只保留了 W/RCU 作为唯一的负载平衡调度参考。同时，我们也删除了不必要的表名，数据库名等信息。

### [db#2281](https://github.com/GreptimeTeam/greptimedb/pull/2281) 协议限制了 TIME INDEX 类型

限制 TIME INDEX 类型，只允许时间戳类型作为 TIME INDEX，避免可能导致的一些歧义。

## 新鲜事

### Dashboard 新特性

- 左侧 tables 列表支持 shortcut 快捷输入，可一键插入预设好的 SQL 查询语句

    - https://github.com/GreptimeTeam/dashboard/pull/323

<p><img src="/zh/blogs/2023-09-20-biweekly/image1.png" alt="演示" style="width: 80%; margin: 0 auto;" /></p>

- 编辑器支持输入提示，SQL 和 PromQL 的编辑器均可根据输入的关键字内容自动提示可能的表名和列名 

    - https://github.com/GreptimeTeam/dashboard/pull/329

    - https://github.com/GreptimeTeam/dashboard/pull/330

<p><img src="/zh/blogs/2023-09-20-biweekly/image2.png" alt="演示" style="width: 80%; margin: 0 auto;" /></p>

## 关于 Greptime

[Greptime 格睿科技](https://greptime.cn/)专注于为可观测、物联网及车联网等领域提供实时、高效的数据存储和分析服务，帮助客户挖掘数据的深层价值。目前基于云原生的时序数据库 [GreptimeDB](https://github.com/GreptimeTeam/greptimedb) 已经衍生出多款适合不同用户的解决方案，更多信息或 demo 展示请联系下方小助手（微信号：greptime）。

欢迎对开源感兴趣的朋友们参与贡献和讨论，从带有 good first issue 标签的 issue 开始你的开源之旅吧～期待在开源社群里遇见你！添加小助手微信即可加入“技术交流群”与志同道合的朋友们面对面交流哦~

Star us on GitHub Now: https://github.com/GreptimeTeam/greptimedb

官网：https://greptime.cn/

文档：https://docs.greptime.cn/

Twitter: https://twitter.com/Greptime

Slack: https://greptime.com/slack

LinkedIn: https://www.linkedin.com/company/greptime/
