OrientDB metadata attributes

243 views Asked by At

I'm trying orientdb with python. I have created a couple of vertices and I noticed that if I prepend their properties name with @, when I search them on the estudio web app, those properties show up in the metadata section. Thats interesting, so i went and tried to query vertices filtering by a metadata property id that i created. When doing so:

select from V where @id = somevalue

I get a huge error msg. I couldnt find a way of querying those custom metadata properties.

1

There are 1 answers

0
neRok On

Your problem is with python/pyorient (I am presuming you are using pyorient based upon your other questions).

Pyorient attempts to map the database fields to object attributes, but python docs say the valid characters for identifiers are the same as in Python 2.x: the uppercase and lowercase letters A through Z, the underscore _ and, except for the first character, the digits 0 through 9. (source). Thus, you cannot use '@' as a field name and expect pyorient to work.


I went and took a quick peek at pyorient source code, and it turns out the problem is even bigger than above... pyorient/types.py

elif key[0:1] == '@':
    # special case dict
    # { '@my_class': { 'accommodation': 'hotel' } }
    self.__o_class = key[1:]
    for _key, _value in content[key].items():
        self.__o_storage[_key] = _value

So pyorient presumes any record field that begins with an '@' character is followed by a class/cluster name, and then a dict of fields. I suppose you could post to the pyorient issue queue and suggest that the above elif section should check if content[key] is a dict, or a "simple value". If it were a dict, it should be handled like it currently is, otherwise it should be handled like a field, but have the @ stripped from it.

Ultimately, not using the @ symbol in your field names will be the easiest solution.