数据湖架构
数据湖架构
数据湖概念
数据湖是存储原始数据的集中式存储库,支持结构化、半结构化和非结构化数据。
数据源 → Ingestion → 存储层(对象存储) → 计算层 → 服务层
│ │
├─ 日志文件 ├─ Spark
├─ 数据库CDC ├─ Flink
├─ API数据 ├─ Presto
└─ IoT数据 └─ Trino
Delta Lake架构
Delta Lake提供ACID事务、Schema演进和时间旅行能力。
// Delta Lake写入
Dataset<Row> df = spark.read().json("s3://raw/events/");
df.write()
.format("delta")
.mode(SaveMode.Append)
.partitionBy("date")
.save("s3://lake/events/");
// 读取指定版本
Dataset<Row> versioned = spark.read()
.format("delta")
.option("versionAsOf", 10)
.load("s3://lake/events/");
// 时间旅行查询
Dataset<Row> historical = spark.read()
.format("delta")
.option("timestampAsOf", "2024-01-01")
.load("s3://lake/events/");
Apache Iceberg架构
Iceberg采用树形元数据结构,支持高性能的分区演进和隐藏分区。
// Iceberg表操作
TableIdentifier identifier = TableIdentifier.of("catalog", "db", "events");
Table table = catalog.loadTable(identifier);
// 写入数据
AppendFiles append = table.newAppend();
append.appendFile(dataFile);
append.commit();
// Schema演进
UpdateSchema update = table.updateSchema();
update.addColumn("new_field", Types.StringType.get());
update.commit();
// 分区演进(无数据重写)
table.updateSpec()
.addField(Expressions.days("timestamp"))
.commit();
Apache Hudi架构
Hudi支持Upsert和增量查询,适合需要实时更新的数据湖场景。
// Hudi写入配置
HoodieWriteConfig config = HoodieWriteConfig.newBuilder()
.withPath("s3://lake/user_events/")
.withDeleteDuplicatePolicy(DeleteDuplicatePolicy.USE_CURRENT_EVENT_TIME_ORDER)
.build();
DataFrameWriteBuilder.write(dfs, config)
.mode(SaveMode.Append)
.option("hoodie.datasource.write.recordkey.field", "event_id")
.option("hoodie.datasource.write.precombine.field", "event_time")
.option("hoodie.datasource.write.table.type", "COPY_ON_WRITE")
.save();
三大框架对比
| 特性 | Delta Lake | Iceberg | Hudi |
|---|---|---|---|
| 事务支持 | ACID | ACID | ACID |
| 时间旅行 | 支持 | 支持 | 支持 |
| Schema演进 | 支持 | 支持 | 有限 |
| 增量查询 | 不支持 | 支持 | 支持 |
| 流处理集成 | Spark | 多引擎 | Spark/Flink |