Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No implicits found for parameter evidence

I have a line of code in a scala app that takes a dataframe with one column and two rows, and assigns them to variables start and end:

val Array(start, end) = datesInt.map(_.getInt(0)).collect()

This code works fine when run in a REPL, but when I try to put the same line in a scala object in Intellij, it inserts a grey (?: Encoder[Int]) before the .collect() statement, and show an inline error No implicits found for parameter evidence$6: Encoder[Int]

I'm pretty new to scala and I'm not sure how to resolve this.

like image 340
Cam Avatar asked Apr 08 '20 11:04

Cam


People also ask

Why do I get No implicit value for evidence Parameter error?

No Implicit Value for Evidence Parameter Error In the case where TypeInformation could not be created, programs fail to compile with an error stating “could not find implicit value for evidence parameter of type TypeInformation”. A frequent reason if that the code that generates the TypeInformation has not been imported.

What are implicit parameters in Scala?

Implicit parameters are the parameters that are passed to a function with implicit keyword in Scala, which means the values will be taken from the context in which they are called. In simpler terms, if no value or parameter is passed to a method or function, then the compiler will look for implicit value and pass it further as the parameter.

What is an implicit keyword in Python?

When implicit keyword used in the parameter scope of the function, all the parameters are marked as implicit. Note: A method can only contain one implicit keyword. implicit val name = "world!"

What happens if a parameter is not passed explicitly in Scala?

In simpler terms, if no value or parameter is passed to a method or function, then the compiler will look for implicit value and pass it further as the parameter. For example, changing an integer variable to a string variable can be done by a Scala compiler rather than calling it explicitly.


1 Answers

Spark needs to know how to serialize JVM types to send them from workers to the master. In some cases they can be automatically generated and for some types there are explicit implementations written by Spark devs. In this case you can implicitly pass them. If your SparkSession is named spark then you miss following line:

import spark.implicits._

As you are new to Scala: implicits are parameters that you don't have to explicitly pass. In your example map function requires Encoder[Int]. By adding this import, it is going to be included in the scope and thus passed automatically to map function.

Check Scala documentation to learn more.

like image 133
bottaio Avatar answered Oct 20 '22 01:10

bottaio