如何在 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
列未找到。
selectExpr
有定义:
public Dataset<Row> selectExpr(String... exprs)
它采用可变参数字符串作为参数。所以,你可以只使用 :
dataset.selectExpr( "Name", "Age", "Age+5" )
我想要下面提到的使用 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
列未找到。
selectExpr
有定义:
public Dataset<Row> selectExpr(String... exprs)
它采用可变参数字符串作为参数。所以,你可以只使用 :
dataset.selectExpr( "Name", "Age", "Age+5" )