FAQ Database Discussion Community


Scala: Using the App trait

scala,scala-2.10
I have an app that extends App and a trait that implements an option parser. All the trait needs is that some class or trait in the runtime mix provides: val args: Array[String] If I declare: trait OptionParser extends App {...} All is fine but that rules out any other...

Traversing multiple JSON arrays in Play/Scala

json,scala,playframework,playframework-2.0,scala-2.10
{ "location":{ "residents":[{ "renting":[{ "name":"John Doe" "pets":"2" },{ "name":"Jane Smith" "pets":"2" }] }] } } I can successfully traverse location with this - val json = ... val rentReads = (__ \ 'location).read[String] val rentResult = json.validate[String](rentReads) rentResult match { case s: JsSuccess[String] => Ok(s.get) case e: JsError => Ok("Errors:...

Scala type mismatch with generics

scala,generics,scala-2.10,type-mismatch
I'm really new to Scala and I'm try to convert some JSF controller to Scala to do some test. The code is the following: abstract class BaseListBean[TENTITY <: AnyRef, TID <: AnyRef] extends Serializable { @BeanProperty var current:TENTITY = _ @BeanProperty var lazyDataModel: LazyDataModel[TENTITY] = _ def initLazyDataModel(): LazyDataModel[TENTITY] =...

How to instantiate a Scala object using reflection

scala,reflection,scala-2.10,scala-2.11,scala-reflect
I have some code that uses reflection to instantiate a Java or Scala class, allowing a user to specify the name: Assume that loadIt below is a hypothetical method defined using this approach. def getInstance(name:String, jar:String) = { val c:Class[_] = loadIt(name, jar) // load class from the jar c.newInstance.asInstanceOf[AnyRef]...

Omit input data of map function in Scala

scala,apache-spark,scala-collections,scala-2.10
I am learning Spark source code, and get confused on the following code: /** * Return a new RDD containing the distinct elements in this RDD. */ def distinct(numPartitions: Int)(implicit ord: Ordering[T] = null): RDD[T] = map(x => (x, null)).reduceByKey((x, y) => x, numPartitions).map(_._1) What is the input data for...

How to enable SQL on SchemaRDD via the JDBC interface? (is it even possible ?)

hive,apache-spark,scala-2.10,apache-spark-sql
UPDATING the problem statement We are using spark 1.2.0 (Hadoop 2.4). We have defined SchemaRDDs using data files in HDFS and would like to enable querying these as tables via HiveServer2. We are encountering runtime exceptions while trying to saveAsTable and would like guidance on how to proceed. Source code:...

Suppressing @unchecked warning for a higher-kinded existential type

scala,scala-2.10,higher-kinded-types
In Scala 2.10, given class Foo[F[_]], I can't write scala> x.isInstanceOf[Foo[_]] <console>:10: error: _$1 takes no type parameters, expected: one x.isInstanceOf[Foo[_]] ^ or scala> x.isInstanceOf[Foo[_[_]]] <console>:11: error: _$1 does not take type parameters x.isInstanceOf[Foo[_[_]]] ^ I can write x.isInstanceOf[Foo[F] forSome { type F[_]] }, which gives an unchecked warning. I've...

Scala inheritance in function signature

scala,inheritance,scala-2.10
I have trait X { } class Y extends X Trait A{ def run(x:X){ /////// } } Class B extends A{ def run(y:Y) } However scala complains at B's run function I am confused on how method signature works inheritance. class B should have a method of signature X, but...