有没有一种方法可以指定spark中浮点数的精度,最好是在将RDD写入文件之前,这样在计算时精度不会丢失?在
最小工作示例
sqlCtxt = HiveContext(sc)
fulldata = sqlCtxt.jsonFile(DATA_FILE)
fulldata.registerTempTable("fulldata")
newcpulists = sqlCtxt.sql('SELECT xxx FROM fulldata')
def reduceSumPerc(x,y):
#some reducefunction
def mapfunc(x):
#some map function
reducedresult = newcpulists.map(mapfunc).reduceByKey(reduceSumPerc)
# I want to reduce the precision just at this line, before writing to file.
reducedresult.coalesce(1, True).saveAsTextFile(RESULT_PATH)
这样的操作不在火花范围内。由于}调用{},所以您只需使用standard Python formatting tools手动格式化输出字符串,例如:
saveAsTextFile
只需对非unicode数据调用unicode
,对{相关问题 更多 >
编程相关推荐