Spark读取kudu,将Row类型Rdd转成其它类型

import org.apache.kudu.spark.kudu.KuduContext
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

import scala.collection.mutable.ArrayBuffer

object Spark_kudu {

  val kuduMasters = "192.168.1.102:7051"
  val tableName = "people"

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    val option = Map("kudu.master" -> kuduMasters, "kudu.table" -> tableName)
    val spark = SparkSession.builder().appName("KuduApp").master("local[*]").config(conf).getOrCreate()
 
    val kc = new KuduContext(kuduMasters, spark.sparkContext)
    val buffer: ArrayBuffer[String] = ArrayBuffer()
    val peerinfoDF = spark.read.options(option).format("kudu")
      .load().select("id", "gender","name")
      .where("gender = 1")
      .rdd
      .map(row=>{
        row.getAs[String]("id")   //将本来获取到的Row类型转成了String类型
        row.getAs[Int]("gender")  //将本来获取到的Row类型转成了int类型
        row.getAs("name")       //没有指定获取的类型,所以得到Row类型
      }).collect()

    spark.close()
  }
}

 

你可能感兴趣的:(Spark读取kudu,将Row类型Rdd转成其它类型)