我正在通过以下方式从phoenix加载数据:
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)
1条答案
按热度按时间x4shl7ld1#
你可以这样做。它回来了
Array[Any]
````val array = df.select("distance").rdd.map(r => r(0)).collect()