如何提高Spark的小数精度?

Ros*_*wis 3 python scala bigdata apache-spark spark-dataframe

我有一个大型的DataFrame,由大约550列的双精度数和两列的long(id)组成。550列正在从csv中读取,我添加了两个id列。我对数据所做的唯一其他事情是将某些csv数据从字符串更改为双精度(“ Inf”->“ 0”,然后将列强制转换为双精度)并将NaN替换为0:

df = df.withColumn(col.name + "temp", 
                             regexp_replace(
                                 regexp_replace(df(col.name),"Inf","0")
                                 ,"NaN","0").cast(DoubleType))
df = df.drop(col.name).withColumnRenamed(col.name + "temp",col.name)
df = df.withColumn("timeId", monotonically_increasing_id.cast(LongType))
df = df.withColumn("patId", lit(num).cast(LongType))
df = df.na.fill(0)
Run Code Online (Sandbox Code Playgroud)

计数时,出现以下错误:

IllegalArgumentException: requirement failed: Decimal precision 6 exceeds max precision 5
Run Code Online (Sandbox Code Playgroud)

有成千上万的行,我正在从多个csvs中读取数据。如何提高小数精度?还有其他可能发生的事情吗?当我阅读某些csv时,只会收到此错误。他们可以拥有比其他小数更多的小数吗?