我已经使用Scala和Spark SQL创建了一个数据框。我想从表中获得第一个值,但是我将其放在方括号[]中。我可以不带括号就得到值吗?
代码:
val sigh = sqlContext.sql("""SELECT DISTINCT accountId FROM table""")
sigh.show()
sigh.select("accountId").first()
结果:
sigh: org.apache.spark.sql.DataFrame = [accountId: string]
+----------+
| accountId|
+----------+
|1370244502|
+----------+
res54: org.apache.spark.sql.Row = [1370244502]
预期结果
sigh: org.apache.spark.sql.DataFrame = [accountId: string]
+----------+
| accountId|
+----------+
|1370244502|
+----------+
res54: org.apache.spark.sql.Row = 1370244502
答案 0 :(得分:0)
first
返回一个Row对象,您可以使用getString
方法从该行中提取元素作为字符串:
sigh.select("accountId").first.getString(0)