作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在阅读structured Streaming的源代码时,我对这个语法感到困惑。
在 microBatchExecution.scala 中
val _logicalPlan = analyzedPlan.transform {
case streamingRelation@StreamingRelation(dataSourceV1, sourceName,
output) =>
toExecutionRelationMap.getOrElseUpdate(streamingRelation, {
// Materialize source to avoid creating it in every batch
val metadataPath = s"$resolvedCheckpointRoot/sources/$nextSourceId"
val source = dataSourceV1.createSource(metadataPath)
nextSourceId += 1
logInfo(s"Using Source [$source] from DataSourceV1 named
'$sourceName' [$dataSourceV1]")
StreamingExecutionRelation(source, output)(sparkSession)
})
……
}
My Question:
how to understand case streamingRelation@StreamingRelation(dataSourceV1, sourceName, output)?
what's the function of "@" here?
最佳答案
有许多不同的方法可以进行模式匹配:
您可以通过类型捕获整个对象到变量:
case streamingRelation: StreamingRelation =>
//do something with object of type StreamingRelation bound to variable streamingRelation
或者你可以解构它:
case StreamingRelation(dataSourceV1, sourceName, output) =>
//do something with members of an object like dataSourceV1, sourceName etc.
@
的语法结合了两者:
case streamingRelation@StreamingRelation(dataSourceV1, sourceName, output) =>
//both whole object is available as streamingRelation and all matched members like dataSourceV1, sourceName
关于scala - 如何理解这个语法? case streamingRelation@StreamingRelation(dataSourceV1, sourceName, 输出),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56235852/
我是一名优秀的程序员,十分优秀!