My requirement is to retrieve the order number from the comment column which is in a column comment and always starts with R. The order number should be added as a new column to the table.
Input data:
code,id,mode,location,status,comment AS-SD,101,Airways,hyderabad,D,order got delayed R1657 FY-YT,102,Airways,Delhi,ND,R7856 package damaged TY-OP,103,Airways,Pune,D,Order number R5463 not received Expected output:
AS-SD,101,Airways,hyderabad,D,order got delayed R1657,R1657 FY-YT,102,Airways,Delhi,ND,R7856 package damaged,R7856 TY-OP,103,Airways,Pune,D,Order number R5463 not received,R5463 I have tried it in spark-sql, the query I am using is given below:
val r = sqlContext.sql("select substring(comment, PatIndex('%[0-9]%',comment, length(comment))) as number from A") However, I'm getting the following error:
org.apache.spark.sql.AnalysisException: undefined function PatIndex; line 0 pos 0