Spark: “expr” 是什么意思?

huangapple go评论57阅读模式
英文:

Spark : what does "expr" mean?

问题

我正在学习使用Java中的Spark,我注意到要添加一列,我们可以使用

dataset.withColumn("name", expr(something))

我想知道expr的语法是什么?它是正则表达式吗?我在手册中没有找到相关信息。

谢谢。

英文:

I'm learning Spark in Java, I noticed that to add a column we can use

dataset.withColumn("name", expr(something))

I want to know what is the syntaxe of expr ? Is it a regular expression ? I didn't find manual on this.

Thank you.

答案1

得分: 3

# 以下是要翻译的内容:

# 函数 'expr' 需要一个包含一段定义列的 SQL 语句的字符串。例如:

val df = List("1AB","2XX","3Y").toDF("id")
df.withColumn("first2OfID", expr("substr(id,1,2)")).show

+---+----------+
| id|first2OfID|
+---+----------+
|1AB|        1A|
|2XX|        2X|
| 3Y|        3Y|
+---+----------+
英文:

The function 'expr' expects a string that contains a bit of SQL that defines a column. For example:

val df = List("1AB","2XX","3Y").toDF("id")
df.withColumn("first2OfID", expr("substr(id,1,2)")).show

+---+----------+
| id|first2OfID|
+---+----------+
|1AB|        1A|
|2XX|        2X|
| 3Y|        3Y|
+---+----------+

huangapple
  • 本文由 发表于 2020年9月16日 03:08:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/63908377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定