如何在apache spark中同时使用dataset.select和selectExpr(How to use both dataset.select and selectExpr in apach

编程入门 行业动态 更新时间:2024-10-22 20:23:57
如何在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 30

I 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" )

更多推荐

本文发布于:2023-08-04 12:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   apache   spark   selectExpr   select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!