title: How to extract number from string column?
body: <p>My requirement is to retrieve the order number from the comment column which is in a column <code>comment</code> and always starts with <code>R</code>. The order number should be added as a new column to the table.</p>
  
  <p>Input data:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>I have tried it in spark-sql, the query I am using is given below:</p>
  
  <pre><code>val r = sqlContext.sql("select substring(comment, PatIndex('%[0-9]%',comment, length(comment))) as number from A")
  </code></pre>
  
  <p>However, I'm getting the following error:</p>
  
  <pre><code>org.apache.spark.sql.AnalysisException: undefined function PatIndex; line 0 pos 0
  </code></pre>