title: Hive query for row number
body: <p>I am working on pyspark, need to write a query which reads data from hive table and returns a pyspark dataframe containing all the columns and row number.</p>
  
  <p>This is what I tried :</p>
  
  <pre><code>SELECT *, ROW_NUMBER() OVER () as rcd_num FROM schema_name.table_name
  </code></pre>
  
  <p>This query works fine in hive, but when I run it from a pyspark script it throws the following error:</p>
  
  <pre><code>Window function row_number() requires window to be ordered, please add ORDER BY clause. For example SELECT row_number()(value_expr) OVER (PARTITION BY window_partition ORDER BY window_ordering) from table;
  </code></pre>
  
  <p>Please suggest some solution.</p>
  
  <p>Note: I do not wish to order the rows in any particular order, I just need row numbers for all the rows present in the table without any sorting or ordering.</p>
  
  <p>Using spark 2.1</p>