OrientDB Team is working on SQL language to provide more powerful functions to works against types. Since OrientDB can work in schema-less mode, it's hard to know the real type of a value. For example when you work with numbers, you could have different type stored. How to know if a number is a Long or an Integer?
Here comes the new type() method (all these methods are available on 2.0-SNAPSHOT, "develop" branch), that returns the OrientDB type of a value. Let's try it against the ROLES property of OUser class.
select roles.type() from ouser
NOTE: .type() method works on the SQL pipeline, so it doesn't access to the stored type, but the type loaded in memory and in case of SET, LIST and MAP sometimes can't distinguish between EMBEDDED types and LINK types.
When you want to know the respective Java class, you can use the method .javaType(), example:
select roles.javaType() from ouser
Now we can access to the type it would be cool to convert values at the fly. OrientDB already has few methods to to this:
But we've implemented a generic convert() method to convert values dynamically.
convert() accepts as unique, mandatory, parameter the OrientDB type (OType enumeration) or any Java type recognized by OrientDB. Example using the STRING OrientDB type:
select roles.convert(STRING) from ouser
And the same using the Java type:
select roles.convert(java.lang.String) from ouser
Since the type is an EMBEDDEDSET, the more interesting thing is converting into a list to get the first value. Example:
select roles.convert(EMBEDDEDLIST) from ouser
CEO at Orient Technologies the Company behind OrientDB