Joining two dataframes without a common column

add an index column to both dataframe using the below code df1.withColumn(“id1”,monotonicallyIncreasingId) df2.withColumn(“id2”,monotonicallyIncreasingId) then join both the dataframes using the below code and drop the index column df1.join(df2,col(“id1”)===col(“id2″),”inner”) .drop(“id1″,”id2”)

Scala-Spark Dynamically call groupby and agg with parameter values

Your code is almost correct – with two issues: The return type of your function is DataFrame, but the last line is aggregated.show(), which returns Unit. Remove the call to show to return aggregated itself, or just return the result of agg immediately DataFrame.groupBy expects arguments as follows: col1: String, cols: String* – so you … Read more

How to vectorize DataFrame columns for ML algorithms?

You can simply foldLeft over the Array of columns: val transformed: DataFrame = df.columns.foldLeft(df)((df, arg) => str(arg, df)) Still, I will argue that it is not a good approach. Since src discards StringIndexerModel it cannot be used when you get new data. Because of that I would recommend using Pipeline: import org.apache.spark.ml.Pipeline val transformers: Array[org.apache.spark.ml.PipelineStage] … Read more

Futures / Success race

The use case is the first successful completion: scala> :pa // Entering paste mode (ctrl-D to finish) def firstSuccessOf[T](fs: Future[T]*)(implicit x: ExecutionContext): Future[T] = { val p = Promise[T]() val count = new java.util.concurrent.atomic.AtomicInteger(fs.size) def bad() = if (count.decrementAndGet == 0) { p tryComplete new Failure(new RuntimeException(“All bad”)) } val completeFirst: Try[T] => Unit = … Read more

Is there a simple example of how to generate verilog from Chisel3 module?

Thank you for your interest in Chisel! We generally encourage people to use our chisel-template repo as a starting point for Chisel3 projects: https://github.com/ucb-bar/chisel-template If you want to do the most barebones possible thing. Create this build.sbt and put it in the root directory for your project. scalaVersion := “2.13.8” addCompilerPlugin(“edu.berkeley.cs” % “chisel3-plugin” % “3.5.3” … Read more

Multiple parameter closure argument type not inferred

See this scala-debate thread for a discussion of what’s going on here. The problem is that Scala’s type inference happens per parameter list, not per parameter. As Josh Suereth notes in that thread, there’s a good reason for the current approach. If Scala had per-parameter type inference, the compiler couldn’t infer an upper bound across … Read more

Scala variable argument list with call-by-name possible?

You have to use zero-argument functions instead. If you want, you can implicit def byname_to_noarg[A](a: => A) = () => a and then def foo(s: (() => Any)*) = s.foreach(a => println(a())) scala> foo(“fish”, Some(7), {println(“This still happens first”); true }) This still happens first fish Some(7) true