【发布时间】:2020-02-24 08:59:41
【问题描述】:
我尝试获取 spark sql 查询的结果并在 Scala 中为它们做一些计算。
val sql_DF = spark.sql("SELECT count(distinct(my_id)) total_id FROM some_ids_table ")
val total_ids = sql_DF.select("total_id").first().toSeq.asInstanceOf[Seq[Double]][0]
val sql_DF01 = spark.sql("SELECT count(distinct(other_id)) other_ids FROM some_ids_table where column_value1 = 1")
val other_id_1 = sql_DF01.select("other_ids").first().toSeq.asInstanceOf[Seq[Double]][0]
println(other_id_1/total_ids)
我收到错误:
error: identifier expected but integer literal found.
val total_ids = sql_DF.select("total_id").first().toSeq.asInstanceOf[Seq[Double]][0]
如何将 sql 查询行中的结果转换为 double 以便我可以对它们进行一些数学计算? 例如
other_ids / total_ids
谢谢
【问题讨论】:
标签: sql scala apache-spark