如何在apache spark中同时使用dataset.select和selectExpr(How to use both dataset.select and selectExpr in apache spark)
我想使用Spark(2.2)数据集提供下面提到的数据
Name Age Age+5 A 10 15 B 5 10 C 25 30我尝试使用以下内容:
dataset.select( dataset.col("Name"), dataset.col("Age), dataset.col( dataset.selectExpr("Age"+5).toString() ) );这会抛出异常,因为找不到Age列。
I want below mentioned data using Spark (2.2) dataset
Name Age Age+5 A 10 15 B 5 10 C 25 30I tried using the following :
dataset.select( dataset.col("Name"), dataset.col("Age), dataset.col( dataset.selectExpr("Age"+5).toString() ) );This throws exception as Age column not found.
最满意答案
selectExpr具有以下定义:
public Dataset<Row> selectExpr(String... exprs)它需要varargs String作为参数。 所以,你可以使用:
dataset.selectExpr( "Name", "Age", "Age+5" )selectExpr has the definition :
public Dataset<Row> selectExpr(String... exprs)It takes varargs String as it's parameter. So, you can just use :
dataset.selectExpr( "Name", "Age", "Age+5" )更多推荐
发布评论