是否有可能在Scala中获得部分函数的域?
例如:
val f: PartialFunction[Int, Unit] = {
case 1 => println("This is 1")
case 2 => println("This is 2")
}
Run Code Online (Sandbox Code Playgroud)
有没有办法得到这样的东西:
val list = f.getDomain
Run Code Online (Sandbox Code Playgroud)
这表示值1和2?
更新:我正在尝试构建通知系统(事件总线).订阅者将如下所示:
class SomeSubscriber extends Subscriber {
notifications {
case LoginEvent(date) => println("Login on " + date)
case LogoutEvent(date) => println("Logout on " + date)
case e: Notification[Any] => async {
println("Other notification: " + e)
ui {
println("UI in async! " + e)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的NotiticationService(事件调度程序)中,我想访问在每个"通知"块中声明的事件,以便我可以将通知推送给订阅者.我怎样才能做到这一点?
提前致谢.
在这样的流程中使用Spark(使用Scala API)编写Avro文件的常见做法有哪些:
我尝试使用spark-avro,但它没有多大帮助.
val someLogs = sc.textFile(inputPath)
val rowRDD = someLogs.map { line =>
createRow(...)
}
val sqlContext = new SQLContext(sc)
val dataFrame = sqlContext.createDataFrame(rowRDD, schema)
dataFrame.write.avro(outputPath)
Run Code Online (Sandbox Code Playgroud)
这失败了,错误:
org.apache.spark.sql.AnalysisException:引用'StringField'不明确,可能是:StringField#0,StringField#1,StringField#2,StringField#3,...
提前致谢,
尤利安