我们都知道Parquet的基于列式存储的文件详情参看:https://blog.csdn.net/weixin_39043567/article/details/89874304
虽然log文件是有一定的规律,但是不够规整,我们可以规整后写入到parquet文件中,使用时直接spark sql就可以都进来进行相应的操作。
那么我们怎么把需要处理的log文件写成parquet文件呢?本文提供两种常用的简单方式:
1、采用Row类进行实现
object LogToParquet {
def main(args: Array[String]): Unit = {
//判断参数输入是否正确
if (args.length != 3) {
println("参数有误")
sys.exit()
}
//接收参数
val Array(logInputPath, compressionCode, resultOutputPath) = args
val conf = new SparkConf()
conf.setMaster("xx")
.setAppName("xx")
.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
.set("spark.sql.parquet.compression.codec", compressionCode)
val sc = new SparkContext(conf)
val ss = ne