小编Ale*_*dar的帖子

内联常量意味着什么?

我正在阅读本文,其中有这段代码:

object ChildActor {

  final val Name = "child-actor"

  def apply(value: Int): Props = Props(new ChildActor(value))
}
Run Code Online (Sandbox Code Playgroud)

和一个说明:

当定义常量final并以大写字母开头时,Scala编译器将内联它们。

我不明白 我知道方法内联,其中为方法调用消除了新的堆栈框架。但是,对编译器内联一个常量意味着什么,您可以澄清一下吗?

scala

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

如何使用标识符等于Scala语言关键字来命名方法参数?

所以我试着宣布这个简单的案例类

case class Association(id: Option[Long], type: String, name: String, description: Option[String], uri: URI, additonalInfo: String){

}
Run Code Online (Sandbox Code Playgroud)

但它不会使用此消息进行编译:

- identifier expected but    'type' found.
Run Code Online (Sandbox Code Playgroud)

这当然是因为"type"是一个保留的Scala关键字.我认为由于某些原因我可以通过提供'类型(符号)来解决这个问题,但它仍然无法编译.

那么我怎样才能真正将我的参数标记为"类型"?请不要让我失望告诉我这不能在Scala中完成:)

scala

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

Apache Spark UI显示的存储内存比--driver-memory选项中设置的少

我正在运行本地传递2G的spark-shell作为驱动程序内存:

alex@POSITRON /ssd2/spark-2.2.0-bin-hadoop2.7/bin $ bash spark-shell --master local --driver-memory 2G
Run Code Online (Sandbox Code Playgroud)

在运行之后,我进入spark UI的“ Environment”选项卡,然后看到我的设置已生效:

Spark UI Environment选项卡

然后,我转到“执行程序”选项卡,那里显示出只有956MB似乎是有效的设置:

Spark UI执行器选项卡

您能否弄清楚这个956MB值的来源是因为我感觉我不正确地理解配置选项或UI图形?

apache-spark

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

为什么Play 2.3应用程序在启动时使用application.conf中的MySQL设置给我"找不到驱动程序:[com.mysql.jdbc.Driver]"?

activatorplay-scala模板的帮助下创建了一个测试Play 2.3应用程序:

activator new test play-scala
Run Code Online (Sandbox Code Playgroud)

这是build.sbt:

name := """test"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
 jdbc,
 anorm,
 cache,
 ws
)
Run Code Online (Sandbox Code Playgroud)

application.conf中,我将MySQL设置为应用程序的数据库:

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost:3306/*******?characterEncoding=UTF-8"
db.default.user=root
db.default.password="********"
Run Code Online (Sandbox Code Playgroud)

当我输入activator run控制台时,它在localhost上启动服务器,端口9999就好了.但是,当我在浏览器中打开应用程序时,出现以下错误:

Configuration error
Driver not found: [com.mysql.jdbc.Driver]
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

playframework typesafe-activator playframework-2.3

0
推荐指数
1
解决办法
2223
查看次数

如何跳过包装尝试参数已经是Try-instance?

假设我有一个包装块的方法Try:

def wrapToTry[T](arg: =>T):Try[T] = Try(arg)

那么如果arg传递的话已经是一个实例Try[U]?我希望在这种情况下包装方法只返回arg自己而不包装.到目前为止,我想出的唯一方法是:

def wrapToTry[T,U](arg: =>T):Try[U] = if(arg.isInstanceOf[Try[U]]) arg.asInstanceOf[Try[U]] else Try(arg).asInstanceOf[Try[U]]

我真的不喜欢它,并试图弄清楚如何解决它.首先我试着超载:

def wrapToTry[T](arg: =>T):Try[T] = Try(arg)

def wrapToTry[T](arg: =>Try[T]):Try[T] = arg
Run Code Online (Sandbox Code Playgroud)

但由于编译错误导致类型擦除,因此无法编译

Error:(10, 7) double definition:
def wrapToTry[T](arg: => T): scala.util.Try[T] at line 8 and
def wrapToTry[T](arg: => scala.util.Try[T]): scala.util.Try[T] at line 10
have same type after erasure: (arg: Function0)scala.util.Try
  def wrapToTry[T](arg: =>Try[T]):Try[T] = arg
      ^
Run Code Online (Sandbox Code Playgroud)

好的,我明白了,这是因为参数是按名称,经验教训.然后我的想法是使用以下代码段中的证据创建方法的重载版本:

object Test {
  import scala.util.Try
  import scala.util.Success

  def wrapToTry[T](arg: =>T):Try[T] …
Run Code Online (Sandbox Code Playgroud)

scala

0
推荐指数
1
解决办法
107
查看次数

如何基于通配符/正则表达式条件在Spark中加入2个数据框?

我有2个数据框df1df2。假设有一location列中df1可能包含常规URL或带有通配符的URL,例如:

  • stackoverflow.com/questions/*
  • * .cnn.com
  • cnn.com/*/politics

该数据帧秒df2url场可能仅含有不带通配符有效的URL。

我需要连接这两个数据框,就像在连接条件中df1.join(df2, $"location" matches $"url")有魔术matches运算符一样。

经过一番谷歌搜索后,我仍然没有找到一种方法来实现这一目标。您将如何解决此类问题?

scala apache-spark

0
推荐指数
1
解决办法
2334
查看次数