Genommen von Apache Spark, Dataset.scala (https://github.com/apache/spark/blob/0c47e274ab8c286498fa002e2c92febcb53905c6/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala)Was passiert in diesem Scala-Code? Callback-Funktionen
Linie 2132:
/**
* Returns the number of rows in the [[Dataset]].
* @group action
* @since 1.6.0
*/
def count(): Long = withCallback("count", groupBy().count()) { df =>
df.collect(needCallback = false).head.getLong(0)
}
Linie 2393:
/**
* Wrap a Dataset action to track the QueryExecution and time cost, then report to the
* user-registered callback functions.
*/
private def withCallback[U](name: String, df: DataFrame)(action: DataFrame => U) = {
try {
df.queryExecution.executedPlan.foreach { plan => plan.resetMetrics()
}
val start = System.nanoTime()
val result = action(df)
val end = System.nanoTime()
sqlContext.listenerManager.onSuccess(name, df.queryExecution, end - start)
result
} catch {
case e: Exception =>
sqlContext.listenerManager.onFailure(name, df.queryExecution, e)
throw e
}
}
Was ist hier los? Ich verstehe nicht, wie count() irgendwie mit Callback gleich ist und einen Körper hat; irgendwie wird es auf dem von withCallback zurückgegebenen Datenrahmen aufgerufen, aber ich verstehe die Syntax nicht.
Dies ist [Scala Currying] (http://docs.scala-lang.org/tutorials/tour/currying.html) – zsxwing