MCAP 转 Lance
更新时间:2026-11-23
简介
把一个 MCAP 文件转成一张 Lance 表,一条消息一行,消息字节原样保存、不解码,支持任意消息编码。转换后可按 topic、时间范围过滤和随机读取。
功能描述
- 表结构:
topic/channel_id/schema_name/message_encoding/log_time/publish_time/sequence/data(消息原始字节) - MCAP 的 header、schema、channel、metadata、attachment 写进表的 schema metadata(键
mcap) - 默认给
topic、log_time建标量索引 - 输出表已存在且
overwrite=False时跳过
算子参数
输入
| 输入 | 含义 |
|---|---|
| input_path | MCAP 文件路径(本地) |
| output_path | Lance 表路径,本地或 bos:// / s3:// |
输出
| 输出 | 含义 |
|---|---|
| lance | 输出 Lance 表路径(large_string),失败为 None |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| topics | list[str] 或 None | None | 只转这些 topic |
| include_attachments | bool | True | 是否保存 attachment 内容 |
| max_attachment_bytes | int | 1048576 | attachment 总字节上限,超过则该行失败 |
| create_indices | bool | True | 是否建 topic / log_time 索引 |
| overwrite | bool | False | 输出表已存在时是否重写 |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.file.mcap_to_lance import McapToLance
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18ds = daft.from_pydict({
19 "input": ["/data/mcap/episode_0001/episode.mcap"],
20 "output": ["/data/lance/episode_0001.lance"],
21 })
22 ds = ds.with_column(
23 "lance",
24 aihc_udf(
25 McapToLance,
26 construct_args={"topics": None},
27 num_cpus=1,
28 num_gpus=0,
29 concurrency=4,
30 batch_size=1,
31 )(col("input"), col("output")),
32 )
33 ds.show()
评价此篇文章
