【问题标题】:Apache Zeppelin not returning aggregate dataApache Zeppelin 不返回聚合数据
【发布时间】:2017-03-28 19:26:32
【问题描述】:

我正在运行 Apache Spark 2.0.1 和 Apache Zeppelin 0.6.2。

在 Zeppelin 中,我有以下段落:

val df = sqlContext
  .read
  .format("org.apache.spark.sql.cassandra")
  .options(Map( "table" -> "iot_data2", "keyspace" -> "iot" ))
  .load()

import org.apache.spark.sql.functions.{avg,round}

val ts = $"updated_time".cast("long")

val interval = (round(ts / 3600L) * 3600.0).cast("timestamp").alias("time")

df.groupBy($"a", $"b", $"date_bucket", interval).avg("t").createOrReplaceTempView("iot_avg")

下一段我试图绘制图表,但 avg("t") 的值始终为 0:

%sql
select time,avg("t") as avg_t from ble_temp_avg where a = '${a}' and b = '${b}' group by time order by time

我认为我遗漏了一些非常明显的东西,但作为 Spark 和 Zeppelin 的新用户,我只是不知道它是什么。

【问题讨论】:

    标签: apache-spark apache-zeppelin


    【解决方案1】:

    这似乎在我重写段落后起作用:

    在第一段:

    val df = sqlContext
      .read
      .format("org.apache.spark.sql.cassandra")
      .options(Map( "table" -> "iot_data2", "keyspace" -> "iot" ))
      .load()
    
    import org.apache.spark.sql.functions.{avg,round}
    
    val ts = $"updated_time".cast("long")
    
    val interval = (round(ts / 3600L) * 3600.0).cast("timestamp").alias("time")
    
    df.select($"a", $"b", $"date_bucket", interval, $"t").createOrReplaceTempView("iot_avg")
    

    在第二段中:

    %sql
    select time,avg(t) as avg_t from iot_avg where a = 'test1' and b = 'test2' group by time order by time
    

    【讨论】:

      猜你喜欢
      • 2018-11-19
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-06
      相关资源
      最近更新 更多