我正在通过以下方式从凤凰城加载数据:
val tableDF = sqlContext.phoenixTableAsDataFrame("Hbtable", Array("ID", "distance"), conf = configuration)
并希望对列值distance
执行以下计算:
val list=Array(10,20,30,40,10,20,0,10,20,30,40,50,60)//list of values from the column distance
val first=list(0)
val last=list(list.length-1)
var m = 0;
for (a <- 0 to list.length-2) {
if (list(a + 1) < list(a) && list(a+1)>=0)
{
m = m + list(a)
}
}
val totalDist=(m+last-first)
答案 0 :(得分:0)
你可以这样做。它返回Array[Any]
`val array = df.select("distance").rdd.map(r => r(0)).collect()
如果要正确获取数据类型,则可以使用。它返回Array[Int]
val array = df.select("distance").rdd.map(r => r(0).asInstanceOf[Int]).collect()