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 t开发者_开发百科o ask instead of trying blindly.
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.
Not sure how it would look in Java, but in GQL/python:
gql = "SELECT * FROM MyObj WHERE __key__ >= Key('MyObj', :1) " + \
"AND __key__ <= Key('MyObj', :2)"
query = db.GqlQuery(gql, 'banana-', u'banana-' + u'\ufffd')
would match banana-
to banana-Z...Z
(and then some).
I'm more likely to use the filter syntax though.
精彩评论