Java 后端面试题库 / 全部题解免费阅读理解原理,有条理地回答

BatchSource、StreamSource 和 RequestSource 怎样定义?

查看完整题解

参考回答

直接回答

BatchSource 需要批读取配置。StreamSource 要设置流的接入方式,如接收推送的 PushConfig,有需要时配历史批源。RequestSource 声明请求字段及类型。

讲清原理

每个源负责读取或要求的数据不同。接入前应核对实体键类型、时间字段和空值策略。连接配置信息由部署环境管理,源码里的示例用占位地点即可。

例子与易错点

下面声明三个源。批源指向示例 Parquet,流接收同结构的新事件,请求另带当前金额。在工作区可按实际位置运行声明。本地仅检查构造时,可放进 SDK 的 Rift 单元测试,使用模拟源。

from tecton import BatchSource, FileConfig, PushConfig, RequestSource, StreamSource
from tecton.types import Field, Float64, String, Timestamp

archive = FileConfig(
    uri="s3://example-only/transactions/",
    file_format="parquet",
    timestamp_field="event_time",
)
batch = BatchSource(name="order_archive", batch_config=archive)
stream = StreamSource(
    name="order_events",
    stream_config=PushConfig(),
    batch_config=archive,
    schema=[Field("account_id", String), Field("event_time", Timestamp), Field("amount", Float64)],
)
request = RequestSource(name="current_order", schema=[Field("amount", Float64)])
assert [obj.name for obj in (batch, stream, request)] == [
    "order_archive", "order_events", "current_order",
]
print(batch.name, stream.name, request.name)

相关题:第 9 题、第 10 题、第 11 题、第 12 题、第 17 题。

这道题,你掌握得怎么样?

掌握程度由你主动标记,阅读和收藏不会自动改变状态。