我在Spark 2.2中打开了几个“ csv”文件,但是当我执行“计数”操作时,它返回10000000条记录,而实际上它是6000000条记录,当我在python或Alteryx中使用Pandas对其进行检查时,它会给出正确的记录数字。
scala> val df=spark.read.format("com.databricks.spark.csv").option("header", "true").option("inferSchema","true").option("encoding", "UTF-8").load("/detalle/*.csv")
df: org.apache.spark.sql.DataFrame = [KEY: string, UNIQ: string ... 101 more fields]
scala> df.count
res13: Long = 10093371
答案 0 :(得分:0)
Despues de mucho buscar y probar, encontre la respuesta en este post:
Reading csv files with quoted fields containing embedded commas
La linea final quedo de la siguiente forma:
val df = spark.read.format("com.databricks.spark.csv").option("wholeFile", true).option("multiline",true).option("header", true).option("inferSchema", "true").option("delimiter", ",").option("encoding", "ISO-8859-1").option("charset", "ISO-8859-1").option("quote", "\"").option("escape", "\"").load("*.csv")
Thanks!