title: import of implicits in Spark not working
body: <p>I'm trying to create a trait to load data from hive table into typed Dataset. Here's the code :</p>
  
  <pre><code>import org.apache.spark.sql.{Dataset, Row, SparkSession}
  
  trait PartitionedHiveTableLoader[T] {
    def context: String
    def table: String
    def returnEntity: Row =&gt; T
    def load(sparkSession: SparkSession, token: String): Dataset[T] = {
      import sparkSession.implicits._
      sparkSession.sql(s"SELECT * from $context.$table where d = $token").
        map(returnEntity(_))
    }
    def load(sparkSession: SparkSession, lowBound: String, upperBound: String, includeLow: Boolean = true, includeUpper: Boolean = true): Dataset[T] = {
      import sparkSession.implicits._
      sparkSession.sql(s"SELECT * " +
        s"from $context.$table " +
        s"where d &gt;${if(includeLow)"=" else ""} $lowBound " +
        s"and d&lt;${if(includeUpper)"=" else ""} $upperBound").
        map(returnEntity(_))
    }
  }
  </code></pre>
  
  <p>Then this trait is used with Object as follow :</p>
  
  <pre><code>import org.apache.spark.sql.Row
  
  object FreeUsersRightsLoader extends {} with PartitionedHiveTableLoader[FreeUsersRightsEntity] {
    def context: String = "analytics"
    def table: String =  "free_users_rights"
    def returnEntity: Row =&gt; FreeUsersRightsEntity = x =&gt; FreeUsersRightsDataset(x)
  }
  </code></pre>
  
  <p>But when I compile it with mvn package, I have the following error : </p>
  
  <blockquote>
    <p>error: Unable to find encoder for type stored in a Dataset.  Primitive types (Int, String, etc) and Product types (case classes) are supported by importing spark.implicits._  Support for serializing other types will be added in future releases.</p>
  </blockquote>
  
  <p>But I imported spark.implicits in every methods ...
  Does anybody know what the problem is ?</p>