Event Object
ON THIS PAGE
The event object in transformation carries the properties and metadata of the event as populated by source.
For reference, we will assume the following event for examples in this doc
{
"event_name": "users",
"properties": {
"id":56712434,
"first_name": "John",
"last_name": "Doe",
"age": 42,
"is_active": true,
"last_logged_in": 1507893200464
}
}
There are two main components of the object:
event_name
: The name of the event type. This value is visible in the Schema Mapper for you to map it to a destination table.properties
: Properties of the event in form of key-value pairs (dict). These properties are populated by the source. Properties of a given event can be manipulated in Transformations Code to add, edit or delete fields in any way you want.
Here is complete API Reference to the event
object.
Event(string: eventname, dict: properties) - Event
Constructs a new event object with given name and properties
getEventName() - string
returns the event name of the event. i.e. users
getProperties() - dict
returns a dict of all the properties of the event
setProperties(dict: properties)
set new properties to an the event
rename(string: new_event_name)
rename an event with new name of choice
isString(string: fieldname) - boolean
returns true if the value of the specified field name is present and is a string
isNumber(string: fieldname) - boolean
returns true if the value of the specified field name is present and is a number
isBoolean(string: fieldname) - boolean
returns true if the value of the specified field name is present and is a boolean
isTimestamp(string: fieldname) - boolean
returns true if the value of the specified field name is present and is a timestamp/datetime
isDate(string: fieldname) - boolean
returns true if the value of the specified field name is present and is a date. Please note that for datetime values it will return false
isTime(string: fieldname) - boolean
returns true if the value of the specified field name is present and is a time value. Please note that for datetime values it will return false
getType( string: fieldname ) - string
returns type of the value of specified field name
from io.hevo.api import Event
def transform(event):
eventName = event.getEventName()
properties = event.getProperties()
Type = event.getType('last_logged_in')
...
getPrimaryKeyFields() - string[]
returns the list of fields which are primary keys in the event.
setPrimaryKeyFields(string[]: fieldnames)
sets the specified list of field names as the primary key of the event.