Spark Dataframe中的Column在计算时会基于某个Dataframe实例。
然而,有时候Column实例独立于Datafame存在,这让人很疑惑,实际上,Spark sql中的Column对象有以下存在方式:
df("columnName") // On a specific DataFrame.
col("columnName") // A generic column no yet associcated with a DataFrame.
col("columnName.field") // Extracting a struct field
col("`a.column.with.dots`") // Escape `.` in column names.
$"columnName" // Scala short hand for a named column.
expr("a + 1") // A column that is constructed from a parsed SQL Expression.
lit("abc") // A column that produces a literal (constant) value.
可见,Column实例是可单独存在的,会在被使用时,和调用的dataframe相关联。
Column的一些操作和函数可见:
http://spark.apache.org/docs/1.5.1/api/scala/index.html#org.apache.spark.sql.Column
参考文献(很尴尬,1.5.1没有对column的说明,所以用了1.6.0,可能存在方式上会有些出入):
http://spark.apache.org/docs/1.6.0/api/scala/index.html#org.apache.spark.sql.Column
本文深入解析了Spark DataFrame中Column的多种存在形式及其实现原理,包括df('columnName')、col('columnName')等,并探讨了Column实例如何在计算时与DataFrame实例关联。此外,还提供了Column操作和函数的参考链接。
2276

被折叠的 条评论
为什么被折叠?



