scala - 如何在 Spark Scala 应用程序的配置中的案例类字段上放置布尔条件并在运行时评估它们?
问题描述
我有一个用 Scala 编写的 Spark 应用程序,其中有一个 Dataset[Event],其中 Event 是用户定义的类型,如下所示:
case class Event(timestamp: Long, state: String, source: String)
我正在转变为:
case class TransformedEvent(timestamp: Long, state: String, source: String, is_finished: Boolean)
基本上,我在其他字段的基础上添加一个字段“is_finished”。
示例:is_finished = true if
state = "state1"
AND
source = "source1"
等等
为了更好地解释,这里是代码:
val events: Dataset[Event] = getEvents()
// Here is the transformation
val transformedEvents: Dataset[TransformedEvent] = events.map(e => convert(e))
// where the convert function is something like this
def convert(event: Event): TransformedEvent = {
val isFinished = if(event.state == "state1" && event.source = "source1")
TransformedEvent(timestamp = event.timestamp,
state = event.state,
source = event.source,
is_finished = isFinished)
}
我正在尝试找出一种方法来制作这种
event.state == "state1" && event.source = "source1"
配置驱动的条件,因为我将来可能必须添加/删除/更新这些条件,因此不想在每次发生这种情况时都更改代码和部署。
谁能指出我正确的方向?
提前致谢。
解决方案
推荐阅读
- mysql - 所以我试图将其他表中的数据插入到工资单表中,但我遇到了很多麻烦
- javascript - 将文本放在图像顶部不起作用?
- r - 如何将观察结果转化为变量并根据变量条件总结每个值
- kubernetes - Github 操作:使用 kubectl 创建命名空间以部署构建
- neo4j - Liquigraph 模式文件丢失?
- reactjs - 无法从嵌套的 JSON 文件中为反应状态分配值
- amazon-web-services - 从组织中删除时如何删除 AWS 子账户?
- java - DateFormat 模式“dd/MM/yyyy”接受错误的月份
- python - 将列添加到从主数据框派生的数据框会导致添加的列添加到从主数据框派生的其他数据框
- python-3.x - 获取封闭函数的所有属性