# 新增 Vector 向量数据类型，支持 Loki 远程写入 | Greptime 双周精选

Source: https://greptime.cn/blogs/2024-11-21-biweekly

## 内容概述

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

最近的内容更新如下：

- **倒排索引和主键分离**

- **支持修改更多的表选项**

- **新增 Vector 向量数据类型**

- **支持 Loki 远程写入**

## 社区贡献者名单

在过去的两周里，GreptimeDB 共合并了 **96 个**PR，其中有 **3 位**独立贡献者，累计 **7 个**PR 被成功合并，还有很多待合并的 PR。

祝贺以下各位在过去 2 周内成为我们最突出的贡献者：

- @[lyang24](https://github.com/lyang24) ([db#5003](https://github.com/GreptimeTeam/greptimedb/pull/5003) [db#4965](https://github.com/GreptimeTeam/greptimedb/pull/4965) [db#4792](https://github.com/GreptimeTeam/greptimedb/pull/4792))

- @[linyihai](https://github.com/linyihai)（[db#4996](https://github.com/GreptimeTeam/greptimedb/pull/4996)[db#4966](https://github.com/GreptimeTeam/greptimedb/pull/4966)[db#4951](https://github.com/GreptimeTeam/greptimedb/pull/4951)）

- @[Kev1n8](https://github.com/Kev1n8)（[db#4881](https://github.com/GreptimeTeam/greptimedb/pull/4881)）

👏 欢迎 @[linyihai](https://github.com/linyihai) 作为新的贡献者加入到社区，并成功合并了 PR，还有更多来自其他独立贡献者的 PR 正在等待合并。

<figure>
<img src="/zh/blogs/2024-11-21-biweekly/image1.png" alt="GreptimeDB 的新晋独立贡献者" style="width: 80%; margin: 0 auto"/>
<figcaption>GreptimeDB 的新晋独立贡献者</figcaption>
</figure>

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

## PR 亮点

### [db#4964](https://github.com/GreptimeTeam/greptimedb/pull/4964) 新增 Vector 向量数据类型

`VECTOR(n)` 表示一个 `n` 维的向量。例如创建一个具有 3 维向量的列的表：

```sql
CREATE TABLE t (ts TIMESTAMP TIME INDEX, v VECTOR(3));
INSERT INTO t VALUES (1, "[1.0, 2.0, 3.0]");
```

### [db#4929](https://github.com/GreptimeTeam/greptimedb/pull/4929) 显式指定倒排索引的列

现在，倒排索引的列可以在建表 SQL 中指定。例如：

```sql
CREATE TABLE t (
  "ts" TIMESTAMP,
  "host" STRING,
  "job" STRING,
  "val" DOUBLE,
  TIME INDEX("ts"),
  PRIMARY KEY("host", "job"),
  INVERTED INDEX("job", "val")
);
```

### [db#4952](https://github.com/GreptimeTeam/greptimedb/pull/4952) [db#4965](https://github.com/GreptimeTeam/greptimedb/pull/4965) [db#4983](https://github.com/GreptimeTeam/greptimedb/pull/4983) 支持修改更多的表选项

1.  Fulltext 列选项可以被修改。例如：

```sql
-- 为一列设置 fulltext 选项：
ALTER TABLE monitor SET COLUMN s FULLTEXT WITH (analyzer = 'Chinese', case_sensitive = 'false');
-- 为一列关闭 fulltext 选项：
ALTER TABLE monitor COLUMN s UNSET FULLTEXT;
```

2. TWCS compaction 选项可以被修改。例如：

```sql
ALTER TABLE ato SET 'compaction.twcs.time_window'='2h';
```

更多请看：https://docs.greptime.com/user-guide/deployments-administration/manage-data/compaction/#time-windowed-compaction-strategy-twcs

### [db#4987](https://github.com/GreptimeTeam/greptimedb/pull/4987) 增加了更多的距离函数

新增的 3 个距离函数是：`cos_distance`， `l2sq_distance` 和 `dot_product`。

### [db#4972](https://github.com/GreptimeTeam/greptimedb/pull/4972) 支持对 SQL 语句设置执行超时

对 MySQL 客户端，设置执行超时方法是 `SET MAX_EXECUTION_TIME = <毫秒数>`；对 PostgreSQL 客户端则是 `SET statement_timeout TO <毫秒数>`。

### [db#5006](https://github.com/GreptimeTeam/greptimedb/pull/5006) 支持对每个 HTTP 请求设置超时

每个请求超时可以通过 HTTP header `x-greptime-timeout` 来设置。

### [db#4941](https://github.com/GreptimeTeam/greptimedb/pull/4941) 支持 Loki 远程写入

现在 GreptimeDB 有了一个新的 HTTP 接口来接收 Loki 的远程写入，例如：

```
loki.write "local_loki" {
    endpoint {
        url = "http://localhost:4000/v1/loki/api/v1/push"
    }
}
```

### [db#4925](https://github.com/GreptimeTeam/greptimedb/pull/4925) 为 Log Pipeline 增加了 JSON path processor

现在可以直接在 Log Pipeline 里使用 JSON path 更方便地处理复杂的 JSON 对象了。

### [db#4960](https://github.com/GreptimeTeam/greptimedb/pull/4960) Windowed sort 进一步优化

在 windowed sort 的优化中支持 filter，进一步提升查询性能。

### [db#4928](https://github.com/GreptimeTeam/greptimedb/pull/4928) 索引文件 ("puffin") 读性能提升

将索引文件 (puffin) 的读实现更加对齐 OpenDAL  以获取更好的读性能。

## Good First Issue

### [db#4497 支持将 auto 值设置给具有默认值的配置项](https://github.com/GreptimeTeam/greptimedb/issues/4497)

关键词：Config

难度：中等

### [db#4957 为 `get_schema_options_by_table_id` 方法增加超时配置](https://github.com/GreptimeTeam/greptimedb/issues/4957)

关键词：Config

难度：简单

---

## 关于 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/
