小编Hen*_*art的帖子

Scala恢复或恢复

我们正在Scala开发一些系统,我们有一些疑问.我们正在讨论如何映射未来的异常,我们不知道何时应该使用选项1或选项2.

val created: Future[...] = ???
Run Code Online (Sandbox Code Playgroud)

选项1:

val a = created recover {   
  case e: database.ADBException =>
    logger.error("Failed ...", e)
    throw new business.ABusinessException("Failed ...", e) 
}
Run Code Online (Sandbox Code Playgroud)

选项2:

val a = created recoverWith {   
  case e: database.ADBException =>
    logger.error("Failed ...", e)
    Future.failed(new business.ABusinessException("Failed ...", e))
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释我何时应该选择1还是选项2?什么是差异?

scala

41
推荐指数
2
解决办法
3万
查看次数

最新的ExecutionContext

我想知道ExecutionContext我应该使用哪些(以及为什么)scalatest % 2.2.6来运行我的未来和模拟的未来.

class Foo {
   def foo: Future[String] = Future.sucessful("B")
}

class Bar(foo: Foo) {
   def bar: Future[String] = foo.foo()
}

class MyTest extends WordSpec {

  implicit val ec: ExecutionContext = ??? // ...global? Why global? Why not?

  val myMock = mock[Foo]
  val myBar = new Bar(myMock)

  "..." in {
    (myMock.foo _).expects(*).returning(Future.succesful("A"))
    whenReady(myBar.bar())(_ shouldBe "A")
  }
}
Run Code Online (Sandbox Code Playgroud)

scala future scalatest scalamock

8
推荐指数
1
解决办法
1598
查看次数

没有附加渲染器,无法更新组件.组件类:"class org.primefaces.component.menuitem.UIMenuItem"

我的页面上有一个警告:

Can not update component without a attached renderer. Component class: "class org.primefaces.component.menuitem.UIMenuItem"
Run Code Online (Sandbox Code Playgroud)

它工作得很完美,但我仍然收到这条警告信息.我所拥有的是一个表,应根据所选行显示用户的上下文菜单,呈现一些菜单.

这是我的表:

<p:dataTable id="protocoloTable" var="protocolo" value="#{juridicaBean.protocolsLazy}" paginator="true" lazy="true" selectionMode="single"
            selection="#{protocoloBean.selectedEntity}">
            <p:ajax event="contextMenu" update=":registration_form:protocoloTableMenu" oncomplete="protoMenu.show(currentEvent);" process="protocoloTable" />
Run Code Online (Sandbox Code Playgroud)

这是菜单:

<p:contextMenu id="protocoloTableMenu" for="protocoloTable" widgetVar="protoMenu">
    <p:menuitem value="Visualizar protocolo" icon="icon-ticket icon-large" actionListener="#{ocorrenciaBean.loadViewOcorrencias(protocoloBean.selectedEntity)}"
                process="@this" update="view_proto_details" oncomplete="PF('viewProtocolDlg').show()"></p:menuitem>
    <p:menuitem value="Nova ocorrência" icon="icon-plus icon-large" actionListener="#{ocorrenciaBean.newOcorrencia(protocoloBean.selectedEntity)}" oncomplete="PF('ocorrenciaDlg').show()" process="@this" update="ocorrencia_details" rendered="#{protocoloBean.selectedEntity.status eq 'PENDENTE'}"></p:menuitem>
    <p:menuitem value="Reabrir protocolo" icon="icon-unlock-alt icon-large" rendered="#{protocoloBean.selectedEntity.status eq 'CONCLUIDO'}"
                actionListener="#{protocoloBean.openProtocol()}" update="protocoloTable" process="@this"></p:menuitem>
Run Code Online (Sandbox Code Playgroud)

PF4

jsf primefaces

7
推荐指数
1
解决办法
2244
查看次数

Spark Dataset唯一ID性能 - row_number vs monotonically_increasing_id

我想为我的数据集行分配唯一的ID.我知道有两种实现选择:

  1. 第一种选择:

    import org.apache.spark.sql.expressions.Window;
    ds.withColumn("id",row_number().over(Window.orderBy("a column")))
    
    Run Code Online (Sandbox Code Playgroud)
  2. 第二种选择:

    df.withColumn("id", monotonically_increasing_id())
    
    Run Code Online (Sandbox Code Playgroud)

第二个选项不是顺序ID,它并不重要.

我想弄清楚是否存在这些实现的任何性能问题.也就是说,如果其中一个选项与另一个相比非常慢.更有意义的是:"monotonically_increasing_id比row_number快得多,因为它不是顺序的......"

scala apache-spark apache-spark-sql apache-spark-dataset

6
推荐指数
2
解决办法
3069
查看次数

为什么Source.fromIterator需要一个Function0 [Iterator [T]]作为参数而不是Iterator [T]?

基于:源代码

我不明白为什么参数Source.fromIteratorFunction0[Iterator[T]]而不是Iterator[T].

这有一个实际的原因吗?我们可以def fromIterator(iterator: => Iterator[T])改为签名吗?(为了避免这样做Source.fromIterator( () => myIterator))

scala akka-stream

5
推荐指数
1
解决办法
726
查看次数

上传资源文件时,createBlockOutputStream 中 Spark HDFS 异常

我正在尝试在集群中运行我的 JAR yarn-cluster,但一段时间后出现异常。INFO失败之前的最后一个是Uploading resource。我已经检查了所有安全组,成功hsdf ls但仍然收到错误。

./bin/spark-submit --class MyMainClass --master 纱线簇 /tmp/myjar-1.0.jar myjarparameter

16/01/21 16:13:51 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
16/01/21 16:13:52 INFO client.RMProxy: Connecting to ResourceManager at yarn.myserver.com/publicip:publicport
16/01/21 16:13:53 INFO yarn.Client: Requesting a new application from cluster with 10 NodeManagers
16/01/21 16:13:53 INFO yarn.Client: Verifying our application has not requested more than the maximum memory capability of the cluster (13312 MB per …
Run Code Online (Sandbox Code Playgroud)

hadoop hadoop-yarn apache-spark

3
推荐指数
1
解决办法
4161
查看次数

Git rebase:强制推或拉推

我们正在公司里讨论毕业后该做什么git rebase。之后你rebase需要将更改推送到远程origin,但是当 git 不允许时我们应该怎么做呢?实际上,我们正在讨论当分支已经被推送时我们最常用的两种方法:

1 .git push -uf origin branch

原因:只有origin. 树将是flat

|
|
|
Run Code Online (Sandbox Code Playgroud)

2 .

git push -u origin branch
! [rejected]
  hint: Updates where rejected because the tip of your current branch is behind
  hint: Updates were rejected because the tip of your current branch is behind
  hint: "git pull ...") before pushing again.
git pull origin branch
git push -u origin branch
Run Code Online (Sandbox Code Playgroud)

原因:它将创建一个名为“Merged origin/branch intobranch …

git version-control github

2
推荐指数
1
解决办法
2977
查看次数