Importing spark.implicits._ in scala

前端 未结 8 1171
感情败类
感情败类 2020-12-25 09:33

I am trying to import spark.implicits._ Apparently, this is an object inside a class in scala. when i import it in a method like so:

def f() = {
  val spark          


        
8条回答
  •  佛祖请我去吃肉
    2020-12-25 10:28

    I think the GitHub code in SparkSession.scala file can give you a good hint:

          /**
           * :: Experimental ::
           * (Scala-specific) Implicit methods available in Scala for converting
           * common Scala objects into [[DataFrame]]s.
           *
           * {{{
           *   val sparkSession = SparkSession.builder.getOrCreate()
           *   import sparkSession.implicits._
           * }}}
           *
           * @since 2.0.0
           */
          @Experimental
          object implicits extends SQLImplicits with Serializable {
            protected override def _sqlContext: SQLContext = SparkSession.this.sqlContext
          }
    

    here "spark" in "spark.implicits._" is just the sparkSession object we created.

    Here is another reference!

提交回复
热议问题