python 2.7 - How can I use 64 bit unsigned integers as entity keys in App Engine's datastore and retain sort order? -


i have unsigned 64 bit integers use app engine datastore keys. unfortunately ndb datastore api seems allow signed 64 bit integers max size of pow(2, 63).

i two's complement integers rely on sort order in datastore queries want 0xffffffffffffffff coming after 0x0 in ascending sort order not before . believe happen if two's complement 64 bit unsigned integers 0xffffffffffffffff interpreted -1 datastore index , 0x0 interpreted 0 example.

i change each unsigned 64 bit key integer string or hex string take lot more space in datastore keeping keys 64 bit integers.

thanks tim hoffman , guido van rossum answer cannot use 64 bit unsigned integers entity keys in app engine's datastore , retain sort order.

if don't care sort order two's complement unsigned 64 bit integer , use that.

in end changed unsigned 64 bit integer fixed width hex string , saved key seemed convenient @ expense of space.

the functions use this:

def to_hex_string(unsigned_64bit_int):     return '{:016x}'.format(my_unsigned_64bit_int)  def to_unsigned_64bit_int(hex_string):     return int(hex_string, 16) 

if space critical guido van rossum suggested using base-64 encoding preserves sort order. not sure if python base64 module encoders preserve sort order.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -