Tutorial 2 Types - abstractfactory/openmetadata GitHub Wiki
Types in Open Metadata mimic the behaviour of variables in dynamic programming languages, such as Python. When a value is associated with a variable, the type is inferred by the value.
>>> my_int = 5 # This is an int
>>> my_string = "String" # This is a string
Altering the value would alter the associated type to a variable.
>>> my_int = "String" # No longer an int
>>> my_string = 5 # No longer a string
In Open Metadata, the same applies.
>>> import openmetadata as om
>>> marcus = om.Location('/home/marcus')
>>> height = om.Entry('height', value=1.87, parent=location)
Here, the entry height
is of type float. How can you tell? By looking at the value; which is a float. You can also ask the entry directly, to see whether or not its true.
>>> print height.type
string
Supported Types
At the time of this writing, the most common types are supported.
- String
- Text
- Integer
- Float
- Boolean
What is the difference between String
and Text
? Physically none, but once interpreted by say a graphical user interface, Text
may be associated with a larger editor than String
. Other types are supported as well.
- Flag
- Class
- ID
Flag is a value-less entry and is useful in situations where the mere presence of an entry is what matters, not its value.
>>> maya_startup_flag = om.Entry('-hideConsole', parent=maya)
Class
and ID
are used in cQuery to distinguish resources from one another; they too are valueless.
Collections also have their corresponding type.
- List
- Dict
On the radar, we've also got a few more interesting ones.
- Vector
- Point
- Matrix
Head over to the specification for a full list of intended formats. http://rfc.abstractfactory.io/spec/10/
Working with types
I mentioned earlier that Text
and String
were the same, so how can you create Text
entries?
>>> om.Entry('myText', value="Abra Kadabra", parent=marcus)
I also mentioned that type is inferred by the value, and the value here is clearly of type string. To solve this, we mimic the behaviour of files on disk - we utilise the suffix.
>>> om.Entry('myText.text', value="Abra Kadabra", parent=marcus)
Now we've explicitly identified myText
as being of type Text
and Open Metadata will write it as such. Alternatively, you may specify type via the flag type
. (implemented in version 0.5.7)
>>> om.Entry('myText', value="Abra Kadabra", parent=marcus, type='text')