xamde xamde - 1 month ago 8
Java Question

What is the highest possible key string in a range query on GAE/J?

Out key space on google app engine is structured like
banana-a3fadawsgdg
banana-hrgsgsgsdgs
banana-regsgsdgsgg
tomato-fsfg33424ff
tomato-dsfgsgasdgs

i.e. there is a type and a unique part encoded into one string (no this is not the GAE kind, its a type that we made up).
Now the question is how to retreive all banana-...... keys with a GAE range query.

For this I need the lowest possible key, maybe 'banana-00000000000' and the highhest possible key, maybe 'bananna-zzzzzzzzzz'. However, since there is unicode, much funkier code points might have to be used. And, since this is appengine, it makes sense to ask instead of trying blindly.

Answer

You probably don't need to know the highest possible key.

For a range query you can use banana. as the upper bound (. being the ASCII/unicode character immediately following -).

If you do need to know the highest possible key then firstly it depends how many characters are allowed in the second part (if it's variable then pick the largest number it can be), then IIRC 0xFFFF can legally appear in UCS-2/UTF-16, but isn't a defined codepoint so might be rejected. So try that instead of z, and if it works then it works. Failing that U+FFFD (replacement character) is probably close enough to the top of the BMP, since U+FFFE is deliberately unassigned in order that the BOM U+FEFF can be used to indicate endian-ness.

I don't know if/how Datastore handles non-BMP codepoints in key string comparisons.

Comments