spark+kudu 例子

 
  
//读取kudu
 
  
sqlContext.read.options(Map("kudu.master" -> "data.hadoop:5071", "kudu.table" -> "testable"))
  .kudu.show()

 
  
    val rdd = sc.textFile("file:///C:\\Users\\mykudu.txt").map(_.split("\t")).map(t =>
      MyKudu(t(0), t(1), t(2).toInt)
    )
    import sqlContext.implicits._
    val mydf = rdd.toDF();
    mydf.registerTempTable("test1")

//
    //写入第一种方式
    val opt = new CreateTableOptions();
    val list = new java.util.ArrayList[String];
    list.add("name")
    list.add("sex")
    list.add("age")

    opt.setRangePartitionColumns(list);

    kuduContext.createTable("test1", mydf.schema, Seq("name"), opt)
    kuduContext.writeRows(mydf, "test1", false)

    //写入第二种方式
    sqlContext.sql("select * from test1").show()
    println("==========================================='''''")
    kuduContext.writeRows(sqlContext.sql("select * from test1").collect().iterator, schema(), "test", false)

你可能感兴趣的:(kudu)