I am loading data from phoenix through this:
我正在通过以下方式从凤凰城加载数据:
val tableDF = sqlContext.phoenixTableAsDataFrame("Hbtable", Array("ID", "distance"), conf = configuration)
and want to carry out the following computation on the column values 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 个解决方案
#1
0
You can do something like this. It returns Array[Any]
你可以做这样的事情。它返回Array [Any]
`val array = df.select("distance").rdd.map(r => r(0)).collect()
If you want to get the data type properly, then you can use. It returns the Array[Int]
如果要正确获取数据类型,则可以使用。它返回Array [Int]
val array = df.select("distance").rdd.map(r => r(0).asInstanceOf[Int]).collect()
#1
0
You can do something like this. It returns Array[Any]
你可以做这样的事情。它返回Array [Any]
`val array = df.select("distance").rdd.map(r => r(0)).collect()
If you want to get the data type properly, then you can use. It returns the Array[Int]
如果要正确获取数据类型,则可以使用。它返回Array [Int]
val array = df.select("distance").rdd.map(r => r(0).asInstanceOf[Int]).collect()