在闭包之外调用函数时会出现奇怪的行为:
任务不可序列化:java.io.NotSerializableException:testing
问题是我需要在类中的代码而不是对象.知道为什么会这样吗?Scala对象是否已序列化(默认?)?
这是一个有效的代码示例:
object working extends App {
val list = List(1,2,3)
val rddList = Spark.ctx.parallelize(list)
//calling function outside closure
val after = rddList.map(someFunc(_))
def someFunc(a:Int) = a+1
after.collect().map(println(_))
}
Run Code Online (Sandbox Code Playgroud)
这是一个非工作的例子:
object NOTworking extends App {
new testing().doIT
}
//adding extends Serializable wont help
class testing {
val list = List(1,2,3)
val rddList = Spark.ctx.parallelize(list)
def doIT = {
//again calling the fucntion someFunc
val after = rddList.map(someFunc(_))
//this will crash (spark lazy)
after.collect().map(println(_))
}
def someFunc(a:Int) …Run Code Online (Sandbox Code Playgroud) 无法转义函数中的所有引号
(它的基本用法 - >如果我发现一个字符串什么都不做,如果它不是一个字符串添加"在开头和结尾)
代码段:
def putTheDoubleQuotes(value: Any): Any = {
value match {
case s: String => s //do something ...
case _ => s"\"$value\"" //not working
}
}
Run Code Online (Sandbox Code Playgroud)
唯一有用的是:
case _ => s"""\"$ value \""""
这有更好的语法吗?
它看起来很糟糕,IDE(IntelliJ)标记为红色(但让你运行它真的很生气!!!!!)
目前正在项目中的4个不同分支机构工作.
对于每个分支,Eclipse中都有一个不同的工作区.
问题是当我在不同的工作空间上打开多个日食时,我很难区分它们并理解当前正在查看的工作空间.(路径相同,因此所有分支上的窗口名称都相同
我可以选择这样做:
File->Switch Workspace->Other...
它将显示当前工作区的名称,但我正在寻找一种方式让它出现在我的主显示窗口中,所以我不需要每天做100次这样的动作
想要使用高级消费者api实现延迟消费者
大意:
提交1个偏移量
while (it.hasNext()) {
val msg = it.next().message()
//checks timestamp in msg to see delay period exceeded
while (!delayedPeriodPassed(msg)) {
waitSomeTime() //Thread.sleep or something....
}
//certain that the msg was delayed and can now be handled
Try { process(msg) } //the msg process will never fail the consumer
consumer.commitOffsets //commit each msg
}
Run Code Online (Sandbox Code Playgroud)对此实施的一些担忧:
谢谢!
我有一个PID列表,我需要获取他们的docker容器名称.走向另一个方向很容易...通过图像名称获取docker容器的PID:
$ docker inspect --format '{{.State.Pid}}' {SOME DOCKER NAME}
Run Code Online (Sandbox Code Playgroud)
知道如何通过PID获取名称吗?
使用Eclipse拼写检查时会启用注释,但输入时例如:
String myString = "why isnt this getttting cheackedd";
Run Code Online (Sandbox Code Playgroud)
Eclipse没有检查引号内的拼写,
是否有设置此启用的选项?或者我是否必须为此事件下载插件?
谢谢
我写的功能:
1)发送HTTP GET请求(响应是有效的JSON)
2)解析对json对象的响应
代码段:
val page = url("http://graph.facebook.com/9098498615")
val response = Http(page OK dispatch.as.String)
Await.result(response , 10 seconds)
val myJson= JSON.parseFull(response .toString)
//this isnt helping -> val myJson= JSON.parseRaw(response .toString)
Run Code Online (Sandbox Code Playgroud)
问题是在此之后,myJson为None,而我期望它保留响应中的json数据.
救命 ?
用演员系统在Scala中编写程序.
需要使用Atmos(Typesafe控制台)进行监控
使用sbt或Eclipse找到文档,问题是我正在寻找一种方法:
这个问题的任何链接到一个不错的维基/文档?
谢谢
我有一个兔子 mq 在机器上运行
我在初始化 RPC 连接时收到随机超时
/usr/lib/python2.6/site-packages/pika-0.9.5-py2.6.egg/pika/adapters/blocking_connection.py
问题是超时不一致并且不时发生。
当手动测试这个问题并从同一台机器上运行 blocks_connection.py 1000 次时,它失败了,不会产生超时。
这是我失败时得到的错误:
2013-04-23 08:24:23,396 runtest-trigger.24397 24397 DEBUG producer_rabbit initiate_rpc_connection Connecting to RabbitMQ RPC queue rpcqueue_java on host: auto-db1
2013-04-23 08:24:25,350 runtest-trigger.24397 24397 ERROR testrunner go Run 1354: cought exception: timed out
Traceback (most recent call last):
File "/testrunner.py", line 193, in go
self.set_runparams(jobid)
File "/testrunner.py", line 483, in set_runparams
self.runparams.producers_testrun = self.initialize_producers_testrun(self.runparams)
File "/basehandler.py", line 114, …Run Code Online (Sandbox Code Playgroud) 有一个具有默认参数的案例类Person.
传递mapper一个缺少param的字符串,mapper将其设置为null.
期望它设置默认值
为什么是这样 ?
例如:
@JsonIgnoreProperties(ignoreUnknown = true)
case class Person(id:Int,name:String="")
class MapperTest extends SpecificationWithJUnit {
"Mapper" should {
"use default param" in {
val personWithNoNameString = """{"id":1}"""
val mapper = new ObjectMapper();
mapper.registerModule(DefaultScalaModule)
val personWithNoName = mapper.readValue(personWithNoNameString,classOf[Person])
personWithNoName.name must be("")
}
}
}
Run Code Online (Sandbox Code Playgroud)
得到错误:
'null' is not the same as ''
java.lang.Exception: 'null' is not the same as ''
Run Code Online (Sandbox Code Playgroud)