我正在关注http://spark.apache.org/docs/latest/sql-programming-guide.html
输入后:
val df = spark.read.json("examples/src/main/resources/people.json")
// Displays the content of the DataFrame to stdout
df.show()
// +----+-------+
// | age| name|
// +----+-------+
// |null|Michael|
// | 30| Andy|
// | 19| Justin|
// +----+-------+
我有一些问题,我没有看到答案。
首先,什么是$ -notation?如在
df.select($"name", $"age" + 1).show()
其次,我可以从第二行获取数据(我不知道第二行中的数据是什么)。
第三,你如何用spark sql读取彩色图像?
4,我仍然不确定spark中的数据集和数据帧之间有什么区别。变量df是一个数据帧,所以我可以将“Michael”改为整数5吗?我可以在数据集中执行此操作吗?
$
不是注释。它是a method call(new ColumnName("name")
的捷径)。1)对于问题1,$
符号用作选择列并在其上应用函数的快捷方式。例如:
df.select($"id".isNull).show
这可以是其他明智的写作
df.select(col("id").isNull)
2)Spark没有索引,但是对于原型设计,你可以使用df.take(10)(i)
,其中i
可能是你想要的元素。注意:每次对基础数据进行分区时,行为可能会有所不同。