开发者

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

开发者 https://www.devze.com 2023-02-23 14:08 出处:网络
Out key space on google app engine is structured like banana-a3fadawsgdg banana-hrgsgsgsdgs banana-regsgsdgsgg

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消