# Greptime 双周精选 （4 月 24 日-5 月 7 日）- 支持外部表

Source: https://greptime.cn/blogs/2023-05-10-biweekly

## 内容概述

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

以下是这段时间较为重要的 PR 总结：

- 在分布式模式中支持 `DELETE`

- 支持通过外部表查询外部数据

- 重构远程目录管理器

- 支持导入和导出 CSV 和 NDJSON 格式的数据集

## 社区贡献者名单

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

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

- @[DevilExileSu](https://github.com/DevilExileSu) ([db#1444](https://github.com/GreptimeTeam/greptimedb/pull/1444) [db#1501](https://github.com/GreptimeTeam/greptimedb/pull/1501) [db#1502](https://github.com/GreptimeTeam/greptimedb/pull/1502))

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

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

👏 欢迎 @[DevilExileSu](https://github.com/DevilExileSu) 和 @[NiwakaDev](https://github.com/NiwakaDev) 作为新的贡献者加入到我们的社区，并都成功合并了首个 PR！

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

## PR 亮点

### [db#1441](https://github.com/GreptimeTeam/greptimedb/pull/1441) 在分布式模式下支持 `DELETE`

我们一直在努力支持 `DELETE` SQL 语句，首先提供了一个最小可用版本。现在，无论在单机模式还是分布式模式下，我们都支持了 `DELETE`，在 gRPC 和 SQL 中都可以使用。

### [db#1041](https://github.com/GreptimeTeam/greptimedb/pull/1041) 支持通过外部表查询外部数据

当处理时序数据时，通常会与其他外部数据结合使用。现在我们可以轻松地基于不同格式的外部数据源创建外部表，例如 NDJSON/CSV/Parquet 等。
比如，我们有一个本地文件系统上的 CSV 文件 `/var/data/city.csv` ：

```sql
Rank , Name , State , 2023 Population , 2020 Census , Annual Change , Density (mi²)
1 , New York City , New York , 8,992,908 , 8,804,190 , 0.7% , 29,938
2 , Los Angeles , California , 3,930,586 , 3,898,747 , 0.27% , 8,382
3 , Chicago , Illinois , 2,761,625 , 2,746,388 , 0.18% , 12,146
......
```

我们可以用它创建一个外部表 `city`：

```sql
MySQL> CREATE EXTERNAL TABLE city with(location="/var/data/city.csv",format="csv"); 
```

并通过 SQL 查询它：

```sql
MySQL> select * from city;
```

<figure>
<img src="/zh/blogs/2023-05-10-biweekly/image1.png" alt="（图 1：查询结果）" style="width: 80%; margin: 0 auto"/>
<figcaption>（图 1：查询结果）</figcaption>
</figure>

甚至将其与时序数据做 Join 查询：

```sql
select temperatures. value, city.population from temperatures  
     left join city on city.name=temperatures.city
```

### [db#1454](https://github.com/GreptimeTeam/greptimedb/pull/1454) 重构远程目录管理器

Arrow-datafusion 为查询引擎提供了一组 traits（`CatalogList` / `CatalogProvider` / `SchemaProvider`），以通过三要素：目录名称/模式名称/表名称 来检索表实体。但所有这些 traits 都是同步的，这意味着我们不能依靠任何异步操作来从远程目录中检索表实体，例如，分布式模式下的 metasrv。

在这个 PR 中，我们并非在执行计划期间从底层存储中获取表实体，而是提前从语句中解析，并将这些表放在基于内存的目录列表中。因此，我们能够避免将同步特性与异步实现连接起来所带来的成本。

### [db#1475](https://github.com/GreptimeTeam/greptimedb/pull/1475) 支持导入和导出 CSV 和 JSON 格式的数据集

以下是一些主要变化：

- 添加 `ParquetRecordBatchStreamAdapter` (ParquetRecordBatchStream -> DataFusion RecordBatchStream)

- 重构 `Copy From` executor

- 支持从 CSV 和 NDJSON 格式的文件中导入数据

- 支持将表和数据导出到 CSV 和 NDJSON 格式的文件中

- 添加测试

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