本文介绍了如何使用 Spark DataFrame 计算 Cassandra 表的汇总统计数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取一些 Cassandra/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
推荐答案
只需将您的数据作为 DataFrame
导入并应用所需的聚合:
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.
这篇关于如何使用 Spark DataFrame 计算 Cassandra 表的汇总统计数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!