SparkSQL读写kudu小记

在操作之前首先要有相应的依赖


      org.apache.kudu
      kudu-spark2_2.11
      1.8.0
      

SparkSQL读取Kudu(Java语言描述)

public static Dataset getDatasetFromKudu(String tableName, SparkSession sparkSession) {
        SQLContext sqlContext = sparkSession.sqlContext();
        Dataset load = sqlContext
                .read()
                .format("org.apache.kudu.spark.kudu")
                .option("kudu.master", "192.168.1.126:7051,192.168.1.207:7051,192.168.1.208:7051")
                .option("kudu.table", tableName)
                .load();
        return load;
}

SparkSQL将DataFrame存入Kudu(Scala语言描述)

def saveData2Kudu(tableName : String, sparkSession: SparkSession, dataset: DataFrame) = {
    val kuduContext = new KuduContext("192.168.1.126:7051,192.168.1.207:7051,192.168.1.208:7051",sparkSession.sparkContext)
    kuduContext.upsertRows(dataset,tableName)
    true
}

 

 

你可能感兴趣的:(大数据)