【发布时间】:2019-10-31 02:24:34
【问题描述】:
我有一个 org.apache.spark.sql.types.DataType 对象列表,例如,val tps = [FloatType, LongType, FloatType, DoubleType],
我从这样的数据框中收到:
val tps = dataFrame.schema
.filter(f => f.dataType.isInstanceOf[NumericType])
.map(f => f.dataType)
对于此列表中的每种类型,我需要创建一个具有默认值的相应类型的对象:[0.0, 0l, 0.0, 0.0]。
我该怎么做?
我试过了
tps.map(t => t.getClass.newInstance())
,但是没有成功,因为私有成员(can not access a member of class org.apache.spark.sql.types.LongType$ with modifiers "private"),而且因为这个语句试图创建DataType的对象,我需要它们对应类型的对象。
我是 scala 的新手,有人可以帮忙吗?
【问题讨论】:
标签: scala apache-spark types