Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 我可以对列执行哪些操作_Scala_Apache Spark_Apache Spark Sql - Fatal编程技术网

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"))

谢谢我特别喜欢你解释上下文的方式。谢谢。我特别喜欢你解释上下文的方式。