Skip to main content

Databend 开源周报第 85 期

Alt text

英文版移步:https://www.databend.com/blog/2023-03-17-databend-weekly

Databend 是一款现代云数仓。专为弹性和高效设计,为您的大规模分析需求保驾护航。自由且开源。即刻体验云服务:https://app.databend.cn

📢 Databend 不再依赖 max_storage_io_requests 设置进行 IO 预读,我们建议使用 v1.0.17-nightly 之后的版本用户,执行 unset max_storage_io_requests 以减少不必要的内存占用。

What's On In Databend

探索 Databend 本周新进展,遇到更贴近你心意的 Databend。

Data Type: MAP

MAP 数据结构使用嵌套的 Array(Tuple(key, value)) 来保存键值对。键必须指定为基本数据类型,并且不允许重复;而值可以是任何数据类型,包括嵌套数组或元组。Databend 还会为 MAP 创建布隆过滤器索引,搜索 MAP 中的值会更加快速。

select * from nginx_log where log['ip'] = '205.91.162.148';
+----+----------------------------------------+
| id | log |
+----+----------------------------------------+
| 1 | {'ip':'205.91.162.148','url':'test-1'} |
+----+----------------------------------------+

如果你想了解更多关于 MAP 数据类型的信息,请阅读以下材料:

Data Transformation During Loading Process

你还记得上周提到的两个 RFC 吗?现在,Databend 已经支持在加载数据到表的过程中进行数据转换。使用 COPY INTO <table> 命令即可实现基本的转换操作。

CREATE TABLE my_table(id int, name string, time date);

COPY INTO my_table
FROM (SELECT t.id, t.name, to_date(t.timestamp) FROM @mystage t)
FILE_FORMAT = (type = parquet) PATTERN='.*parquet';

该功能可以避免在临时表中存储预转换数据,并支持列重新排序、列省略和类型转换操作。此外,可以从 Stage 中的 Parquet 文件加载部分数据或者对其列进行重新排列。该功能简化和优化了 ETL 过程,使用户能够更加关注数据分析而不必考虑如何移动他们的数据。

如果你对这一特性感兴趣,可以查阅下面列出的材料:

Code Corner

一起来探索 Databend 和周边生态中的代码片段或项目。

Run Multiple Futures Parallel

你对并行运行多个 Future 感兴趣吗?Databend 利用这种方法极大地改善了在大量文件情况下的扫描性能。

下面这段不到 30 行的代码将会揭示如何实现这一技巧。

/// Run multiple futures parallel
/// using a semaphore to limit the parallelism number, and a specified thread pool to run the futures.
/// It waits for all futures to complete and returns their results.
pub async fn execute_futures_in_parallel<Fut>(
futures: impl IntoIterator<Item = Fut>,
thread_nums: usize,
permit_nums: usize,
thread_name: String,
) -> Result<Vec<Fut::Output>>
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
// 1. build the runtime.
let semaphore = Semaphore::new(permit_nums);
let runtime = Arc::new(Runtime::with_worker_threads(
thread_nums,
Some(thread_name),
)?);

// 2. spawn all the tasks to the runtime with semaphore.
let join_handlers = runtime.try_spawn_batch(semaphore, futures).await?;

// 3. get all the result.
future::try_join_all(join_handlers)
.await
.map_err(|e| ErrorCode::Internal(format!("try join all futures failure, {}", e)))
}

如果你对这个 Rust 技巧感兴趣,可以阅读这个 PR feat: improve the parquet get splits to parallel

How to Create a System Table

系统表用于提供 Databend 内部状态信息,例如表、函数和设置。

如果你对如何创建系统表感兴趣,可以查看我们最近发布的文档,使用 system.credits 表作为示例,展示如何实现、注册和测试系统表。

以下是部分代码片段:

let table_info = TableInfo {
desc: "'system'.'credits'".to_string(),
name: "credits".to_string(),
ident: TableIdent::new(table_id, 0),
meta: TableMeta {
schema,
engine: "SystemCredits".to_string(),
..Default::default()
},
..Default::default()
};

亮点

以下是一些值得注意的事件,也许您可以找到感兴趣的内容。

What's Up Next

我们始终对前沿技术和创新理念持开放态度,欢迎您加入社区,为 Databend 注入活力。

Quantile 支持设置多个 Level

#10633 的实现中,已经支持传递多个 levels。但是 Issue 中提出的 kurtosis(x)skewness(x) 方法也可以视作为 Databend 贡献的一个好的开始。

在 PR #10474 合并后,Databend 开始支持 QUANTILE 聚合函数,但目前仅支持将单个浮点值设置为 level。如果它还可以支持传递多个参数,或传递列表作为参数,则可能有助于简化某些情况下的 SQL 编写。

SELECT QUANTILE([0.25, 0.5, 0.75])(number) FROM numbers(25);
+-------------------------------------+
| quantile([0.25, 0.5, 0.75])(number) |
+-------------------------------------+
| [6, 12, 18] |
+-------------------------------------+

Feature: quantile support list and add functions kurtosis() and skewness()

如果你对这个主题感兴趣,可以尝试解决其中的部分问题或者参与讨论和 PR review。或者,你可以点击 https://link.databend.rs/i-m-feeling-lucky 来挑选一个随机问题,祝好运!

Changelog

前往查看 Databend 每日构建的变更日志,以了解开发的最新动态。

地址:https://github.com/datafuselabs/databend/releases


Contributors

共有 25 位贡献者参与

非常感谢贡献者们卓越的工作。