Scala 我可以对列执行哪些操作
我有一张桌子Scala 我可以对列执行哪些操作,scala,apache-spark,apache-spark-sql,Scala,Apache Spark,Apache Spark Sql,我有一张桌子 DEST_COUNTRY_NAME ORIGIN_COUNTRY_NAME count United States Romania 15 United States Croatia 1 United States Ireland 344 我将上述内容转换为一个DataFrame val flightData2015 = spark .read .option("inferSchema", "true")//infers the input schema autom
DEST_COUNTRY_NAME ORIGIN_COUNTRY_NAME count
United States Romania 15
United States Croatia 1
United States Ireland 344
我将上述内容转换为一个DataFrame
val flightData2015 = spark
.read
.option("inferSchema", "true")//infers the input schema automatically from data
.option("header", "true")//uses the first line as names of columns.
.csv("/data/flight-data/csv/2015-summary.csv");
使用col
函数,我只能从DataFrame
中获取一列
scala> data.col("count");
res70: org.apache.spark.sql.Column = count
但我注意到列中没有列出任何操作。我可以在列
上执行任何操作,例如max
、show
等
我试图在count
列上运行max
函数,但仍然没有看到任何结果
scala> max(dataDS.col("count"));
res78: org.apache.spark.sql.Column = max(count)
如何对
列执行操作?无任何操作。列不是分布式数据结构,也不绑定到特定数据
相反,列是要在数据集
的特定上下文中进行计算的表达式,如选择
、筛选
或agg
,无任何操作。列不是分布式数据结构,也不绑定到特定数据
相反,列是要在数据集
的特定上下文中进行计算的表达式,如选择
、筛选
或agg
,,您可以
同样在中,那些$“name”
对象是列
对象
因此,您可以执行flightData2015.select($“count”>1.show()
,只会得到两行
如果您想找到一的最大值,那么您需要以不同的方式从数据帧中选择它
像这样的
// TODO: import sql functions
flightData2015.select(max($"count"))
你可以
同样在中,那些$“name”
对象是列
对象
因此,您可以执行flightData2015.select($“count”>1.show()
,只会得到两行
如果您想找到一的最大值,那么您需要以不同的方式从数据帧中选择它
像这样的
// TODO: import sql functions
flightData2015.select(max($"count"))
谢谢我特别喜欢你解释上下文的方式。谢谢。我特别喜欢你解释上下文的方式。