pyspark中是否有Substr oracle等效功能

时间:2019-01-22 14:55:04

标签: pyspark-sql

Pyspark中的以下语句引发了一个问题         .select('Substr(trim(Name),-3))')

    .select ('Substr(trim(Name), -3))')

     .select ('Substr(trim(Name), -3))')

输入数据为RAMS 123,预期输出为123

1 个答案:

答案 0 :(得分:0)

substr()方法在pyspark中可用。

myDf = sqlContext.createDataFrame([('Alex',"30"),("Hitesh R","34"),("David B","35")],("Name","Age"))

myDf.show()

+--------+---+
|    Name|Age|
+--------+---+
|    Alex| 30|
|Hitesh R| 34|
| David B| 35|
+--------+---+

myDf.select(myDf['Name'].substr(-3,3)).show()

+----------------------+                                                        
|substring(Name, -3, 3)|
+----------------------+
|                   lex|
|                   h R|
|                   d B|
+----------------------+