使用typedcolumn选择Spark Dataset [英] Spark Dataset select with typedcolumn
本文介绍了使用typedcolumn选择Spark Dataset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查看spark数据集上的select()
函数,生成了各种函数签名:
Looking at the select()
function on the spark DataSet there are various generated function signatures:
(c1: TypedColumn[MyClass, U1],c2: TypedColumn[MyClass, U2] ....)
这似乎暗示着我应该能够直接引用MyClass的成员并输入安全,但是我不确定如何...
This seems to hint that I should be able to reference the members of MyClass directly and be type safe, but I'm not sure how...
ds.select("member")
当然可以工作..似乎ds.select(_.member)
可能也可以以某种方式工作?
ds.select("member")
of course works .. seems like ds.select(_.member)
might also work somehow?
推荐答案
在用于select
的Scala DSL中,有很多方法可以识别Column
:
In the Scala DSL for select
, there are many ways to identify a Column
:
- 从符号中:
'name
- 通过字符串:
$"name"
或col(name)
- 从表达式中:
expr("nvl(name, 'unknown') as renamed")
- From a symbol:
'name
- From a string:
$"name"
orcol(name)
- From an expression:
expr("nvl(name, 'unknown') as renamed")
要从Column
获取TypedColumn
,只需使用myCol.as[T]
.
例如:ds.select(col("name").as[String])
这篇关于使用typedcolumn选择Spark Dataset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文