可以将与头记录长度不同的记录放入 bad_record 目录 [英] Possible to put records that aren't same length as header records to bad_record directory
本文介绍了可以将与头记录长度不同的记录放入 bad_record 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将文件读入这样的数据帧
I am reading a file into a dataframe like this
val df = spark.read
.option("sep", props.inputSeperator)
.option("header", "true")
.option("badRecordsPath", "/mnt/adls/udf_databricks/error")
.csv(inputLoc)
文件是这样设置的
col_a|col_b|col_c|col_d
1|first|last|
2|this|is|data
3|ok
4|more||stuff
5|||
现在,spark 会将所有这些读取为可接受的数据.但是,我希望 3|ok
被标记为错误记录,因为它的大小与标题大小不匹配.这可能吗?
Now, spark will read all of this as acceptable data. However, I want 3|ok
to be marked as a bad record because it's size does not match the header size. Is this possible?
推荐答案
val a = spark.sparkContext.textFile(pathOfYourFile)
val size = a.first.split("\\|").length
a.filter(i => i.split("\\|",-1).size != size).saveAsTextFile("/mnt/adls/udf_databricks/error")
这篇关于可以将与头记录长度不同的记录放入 bad_record 目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文