【问题标题】:How to use both dataset.select and selectExpr in apache spark如何在 apache spark 中同时使用 dataset.select 和 selectExpr
【发布时间】:2017-11-22 06:24:32
【问题描述】:

我想要下面提到的使用 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 列。

【问题讨论】:

    标签: apache-spark apache-spark-dataset


    【解决方案1】:

    selectExpr 有定义:

    public Dataset<Row> selectExpr(String... exprs)
    

    它以可变参数字符串作为参数。所以,你可以使用:

    dataset.selectExpr( "Name", "Age", "Age+5" )
    

    【讨论】:

    • 它就像select,但定义不同。
    猜你喜欢
    • 1970-01-01
    • 2017-11-18
    • 2019-01-08
    • 2010-09-09
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    相关资源
    最近更新 更多