1. 批任务整体流程:
import org.apache.spark.sql.SparkSession
import org.slf4j.LoggerFactory//高性能日志
object test{
private val LOGGER = LoggerFactory.getLogger(this.getClass)
def main(args: Array[String]): Unit = {
args.foreach(x => Util.infoLog(LOGGER, s"****args: ${x} ****")
)
val inputSql=args(0)
val inputSchema=args(1).split(",")
val defaultPartitions=args(2).toInt
val sc = SparkSession.builder().enableHiveSupport().getOrCreate()
import sc.implicits._
try{
val inputDocsDF = sc.sql(inputSql).repartition(defaultPartitions)
.rdd.map {
row =>
val docSql = row.toSeq.asInstanceOf[Seq[String]].toArray
//.toBuffer.asInstanceOf[ArrayBuffer[String]] //可变长度,适用于schema要增加的情况
docSql
//做正式处理
}
} finally {
if (null != sc) {
//清空persist的rdd
sc.sparkContext.getPersistentRDDs.foreach(x => x._2.unpersist())//rdd,dataframe都适用,
Spark SQL处理与HDFS文件操作:从读取到写入Hive详解

本文档详细介绍了如何使用Apache Spark进行SQL查询,包括从HDFS加载数据、RDD转换为DataFrame,以及将结果写入Hive表。重点展示了批任务流程、数据预处理和数据持久化管理。
最低0.47元/天 解锁文章
1784

被折叠的 条评论
为什么被折叠?



