在火花流中,每个批处理间隔的数据总是产生一个且只有一个RDD,为什么我们用它foreachRDD()
来预测RDD?RDD只有一个,不需要foreach.在我的测试中,我从未见过RDD不止一个.
无论数据量有多大,一个批处理间隔的数据是否在DStream中生成一个且只有一个 RDD?
TraversableOnce:"集合的模板特征,可以遍历一次或一次或多次."
我不明白这句话.为什么可以遍历更多次?不仅一次吗?谢谢!
这是一个测试程序:
object Test {
def main(args: Array[String]): Unit = {
// there is an unhandled exception in here, I expect program can remind me, and I can handled it before running.
myException()
}
def myException: Unit ={
throw new Exception
}
}
Run Code Online (Sandbox Code Playgroud)
在Java中,当我使用unhandling异常调用方法时,程序将发生错误,并告诉你add throws declaration
或surround with try/catch
.
在Scala中运行之前如何知道程序有未处理的异常?
我写了一段测试用的代码:
class A extends JavaTokenParsers {
def str: Parser[Any] = stringLiteral ~ ":" ~ stringLiteral ^^
{ case x ~ ":" ~ y => (x, y) } //how to use case keyword like this?
}
object B extends A with App{
val s = """
"name": "John"
"""
println(parseAll(str, s))
}
Run Code Online (Sandbox Code Playgroud)
我在Scala Second Edition中阅读了编程的 "第15章:案例类和模式匹配" ,但我从未见过这样的案例:
... ^^ { case x ~ ":" ~ y => (x, y) }
Run Code Online (Sandbox Code Playgroud)
它不是匹配关键字,但^^看起来像匹配.我知道部分功能 …
Elasticsearch "DFS_QUERY_THEN_FETCH"中的DFS是什么?
DFS的缩写是什么?
我的代码抛出异常 scala.util.control.BreakControl
,但我不知道为什么.有人知道吗?
有些地方我用breakable
和break
,但我不为什么导致此异常.
片段1
breakable {
for (quaOfLine <- dataOfLine) {
try {
// ... some other code
if (judgeTime(jsonQua.getInt("startTime")) == judgeTime(jsonLine.getInt("startTime"))) {
// ... some other code
if (quaRRIDs.length / RRIDs.length.toFloat >= 0.8 || quaRRIDs.length / RRIDs.length.toFloat <= 1.2) {
var count = 0
breakable {
for (rrid <- RRIDs) {
for (quaRRID <- quaRRIDs) {
if (rrid == quaRRID) {
count += 1
break //break
}
}
}
}
if (count / …
Run Code Online (Sandbox Code Playgroud) 我设置的火花流时间间隔是5s.如果当前5s接收到非常多的数据,并且火花流不能在5s内完成,但下一批数据即将到来.
火花流是否会在同一时间处理下一批数据?
我的意思是批次会并行执行吗?
有一个函数f
中foo.c
,我把f Prototypes
成一个头文件.
然后,有3个问题:
foo.h
?foo.c
和foo.h
必须在同一个目录 ?f.h
,foo.c
并且f.h
可以在不同的目录中.看一个例子:〜/的CFile/foo.c的
#include "~/hfile/f.h"
int f(void){
...
}
Run Code Online (Sandbox Code Playgroud)
〜/ HFILE/FH
int f(void);
Run Code Online (Sandbox Code Playgroud)
〜/主/ cmain.c
#include "~/hfile/f.h"
int main(void){
f();
...
}
Run Code Online (Sandbox Code Playgroud)
然后,当我f
在cmain.c中调用函数时,cmain.c可以 通过指令找到fh#include
,但cmain.c如何通过fh找到foo.c,因为cmain.c只包含fh 而不包含foo.c?或编译器或链接器如何通过fh找到foo.c?
代码:
@FunctionalInterface
interface VoidSupplier {
void apply() throws Exception;
}
void execute(VoidSupplier voidSupplier) {
if (voidSupplier != null) {
try {
voidSupplier.apply();
} catch (Throwable e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
调用execute
使用lambda:
@Test
public void testLambda() {
InputStream i = null;
execute(() -> i.close()); // use lambda
System.out.println("output some message"); // will be executed
}
Run Code Online (Sandbox Code Playgroud)
调用execute
使用方法参考:
@Test
void testMethodReference() {
InputStream i = null;
execute(i::close); // use method reference
System.out.println("output some message"); …
Run Code Online (Sandbox Code Playgroud)