Skip to content
Advertisement

Spark SQL Row_number() PartitionBy Sort Desc

I’ve successfully create a row_number() partitionBy by in Spark using Window, but would like to sort this by descending, instead of the default ascending. Here is my working code:

JavaScript

That gives me this result:

JavaScript

And here I add the desc() to order descending:

JavaScript

And get this error:

AttributeError: ‘WindowSpec’ object has no attribute ‘desc’

What am I doing wrong here?

Advertisement

Answer

desc should be applied on a column not a window definition. You can use either a method on a column:

JavaScript

or a standalone function:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement