如何计算汇总统计上卡桑德拉表星火数据帧? [英] How to compute summary statistic on Cassandra table with Spark DataFrame?
本文介绍了如何计算汇总统计上卡桑德拉表星火数据帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图得到一些卡桑德拉/ SPARK数据的最小,最大意思,但我需要用JAVA做。
I'm trying to get the min, max mean of some Cassandra/SPARK data but I need to do it with JAVA.
import org.apache.spark.sql.DataFrame;
import static org.apache.spark.sql.functions.*;
DataFrame df = sqlContext.read()
.format("org.apache.spark.sql.cassandra")
.option("table", "someTable")
.option("keyspace", "someKeyspace")
.load();
df.groupBy(col("keyColumn"))
.agg(min("valueColumn"), max("valueColumn"), avg("valueColumn"))
.show();
编辑以显示工作版本:
确保把围绕someTable和someKeyspace
EDITED to show working version: Make sure to put " around the someTable and someKeyspace
推荐答案
刚刚导入您的数据作为数据帧
并应用所需的聚合:
Just import your data as a DataFrame
and apply required aggregations:
import org.apache.spark.sql.DataFrame;
import static org.apache.spark.sql.functions.*;
DataFrame df = sqlContext.read()
.format("org.apache.spark.sql.cassandra")
.option("table", someTable)
.option("keyspace", someKeyspace)
.load();
df.groupBy(col("keyColumn"))
.agg(min("valueColumn"), max("valueColumn"), avg("valueColumn"))
.show();
其中, someTable
和 someKeyspace
分别存储表名和密钥空间。
where someTable
and someKeyspace
store table name and keyspace respectively.
这篇关于如何计算汇总统计上卡桑德拉表星火数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文