title: PySpark takeOrdered Multiple Fields (Ascending and Descending)
body: <p>The takeOrdered Method from pyspark.RDD gets the N elements from an RDD ordered in ascending order or as specified by the optional key function as described here <a href="https://spark.apache.org/docs/2.2.1/api/python/pyspark.html#pyspark.RDD" rel="nofollow noreferrer">pyspark.RDD.takeOrdered</a>. The example shows the following code with one key:</p>
  
  <pre><code>&gt;&gt;&gt; sc.parallelize([10, 1, 2, 9, 3, 4, 5, 6, 7], 2).takeOrdered(6, key=lambda x: -x)
  [10, 9, 7, 6, 5, 4]
  </code></pre>
  
  <p>Is it also possible to define more keys e.g. x,y,z for data that has 3 columns? </p>
  
  <p>The keys should be in different order such as x= asc, y= desc, z=asc. That means if the first value x of two rows are equal then the second value y should be used in descending order.</p>