【六】Spark SQL中SparkSession的使用

Spark2.X中Spark SQL的入口点:SparkSession。

项目目录

【六】Spark SQL中SparkSession的使用_第1张图片

pom.xml


  4.0.0
  com.sid.com
  sparksqltrain
  1.0-SNAPSHOT
  2008
  
    2.11.8
    2.2.0
  

  
    
      scala-tools.org
      Scala-Tools Maven2 Repository
      http://scala-tools.org/repo-releases
    
  

  
    
      scala-tools.org
      Scala-Tools Maven2 Repository
      http://scala-tools.org/repo-releases
    
  

  
    
    
      org.scala-lang
      scala-library
      ${scala.version}
    
    
    
      org.apache.spark
      spark-sql_2.11
      ${spark.version}
    
    
    
      org.apache.spark
      spark-hive_2.11
      ${spark.version}
    


  

  
    src/main/scala
    src/test/scala
    
      
        org.scala-tools
        maven-scala-plugin
        
          
            
              compile
              testCompile
            
          
        
        
          ${scala.version}
          
            -target:jvm-1.5
          
        
      
      
        org.apache.maven.plugins
        maven-eclipse-plugin
        
          true
          
            ch.epfl.lamp.sdt.core.scalabuilder
          
          
            ch.epfl.lamp.sdt.core.scalanature
          
          
            org.eclipse.jdt.launching.JRE_CONTAINER
            ch.epfl.lamp.sdt.launching.SCALA_CONTAINER
          
        
      
    
  
  
    
      
        org.scala-tools
        maven-scala-plugin
        
          ${scala.version}
        
      
    
  

SparkSessionTest.scala
package com.sid.com

import org.apache.spark.sql.SparkSession

/**
  * SparkSession的使用
  * */
object SparkSessionTest {
  def main(args: Array[String]): Unit = {
    val path = args(0)
    val spark = SparkSession.builder().appName("SparkSessionTest").master("local[2]").getOrCreate()

    val people = spark.read.json(path)
    people.show()

    spark.stop()
  }
}

people.json

{"name":"zhangsan","age":30}
{"name":"lisi","age":31}
{"name":"wangwu","age":32}
{"name":"sid","age":32}
 

运行

【六】Spark SQL中SparkSession的使用_第2张图片

【六】Spark SQL中SparkSession的使用_第3张图片

你可能感兴趣的:(spark,SQL)