I’d like to store records of orders which, like the getting started example, have an order ID, and a price. I’ll then want to query them sorted first by descending price, and then by ascending order ID. So I can’t just use an index of price and order ID and query it in reverse order, because then the order IDs would be backwards.
As best as I can tell, my only option is to write a
FunctionKeyExpression which can negate numeric values before they’re stored, and then use that in the index. (And also use it as part of the sort when querying.)
I’ve written that function, and it appears to be working. Now I just want to check, does that seem reasonable? Was there a better way? Will there be any problem with using that function in the primary key index? (I want the records clustered by price, as my most common operation will be “find the X highest paying orders and process some of them”)
I’ve put my code up in a gist in case anyone would care to take a look. https://gist.github.com/jkominek/4d7248b9eba86d39aea5489d2f60f72b