【问题标题】:Apache Spark SQL is taking forever to count billion rows from Cassandra?Apache Spark SQL 需要永远从 Cassandra 计算十亿行?
【发布时间】:2017-04-08 07:36:21
【问题描述】:

我有以下代码

我调用 spark-shell 如下

./spark-shell --conf spark.cassandra.connection.host=170.99.99.134 --executor-memory 15G --executor-cores 12 --conf spark.cassandra.input.split.size_in_mb=67108864

代码

scala> val df = spark.sql("SELECT test from hello") // Billion rows in hello and test column is 1KB

df: org.apache.spark.sql.DataFrame = [test: binary]

scala> df.count

[Stage 0:>   (0 + 2) / 13] // I dont know what these numbers mean precisely.

如果我按如下方式调用 spark-shell

./spark-shell --conf spark.cassandra.connection.host=170.99.99.134

代码

val df = spark.sql("SELECT test from hello") // This has about billion rows

scala> df.count


[Stage 0:=>  (686 + 2) / 24686] // What are these numbers precisely?

这两个版本都不起作用 Spark 一直在运行,我已经等待了超过 15 分钟但没有任何响应。关于可能出现的问题以及如何解决此问题的任何想法?

我使用的是 Spark 2.0.2 和 spark-cassandra-connector_2.11-2.0.0-M3.jar

【问题讨论】:

  • 如果有十亿行,您可能不得不等待 2 或 3 个小时才能得到大致的答案。

标签: apache-spark apache-spark-sql spark-cassandra-connector


【解决方案1】:

Dataset.count 很慢,因为它在涉及外部数据源时不是很聪明。它将查询重写为(很好):

SELECT COUNT(1) FROM table

但不是将COUNT 向下推,而是执行:

SELECT 1 FROM table

针对源(在您的情况下它将获取十亿个),然后在本地聚合以获得最终结果。您看到的数字是任务计数器。

CassandraRDD 上有一个优化的cassandraCount 操作:

sc.cassandraTable(keyspace, table).cassandraCount

关于服务器端操作的更多信息可以在the documentation找到。

【讨论】:

    猜你喜欢
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多