Event Object
On This Page
The event
object in a transformation carries the properties and metadata of the Event as provided by the Source.
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
: The properties of the Event in the form of key-value pairs (dict).
For example:
{
"event_name": "users",
"properties": {
"id":56712434,
"first_name": "John",
"last_name": "Doe",
"age": 42,
"is_active": true,
"last_logged_in": 1507893200464
}
}
Properties of a given Event can be manipulated using the Transformations code to add, edit, or delete fields in any way you want.
The following is the complete API Reference to the event object.
Event(string: eventname, dict: properties) - Event
Description: Constructs a new event
object from an existing Event with given name and properties.
Example:
The following transformation creates two separate Events, subject
and marks
with the same properties as the original Event.
from io.hevo.api import Event
def transform(event):
# Get properties from the event #
properties = event.getProperties()
# Create two events (electronics, phones) from the original event
subject = Event('subject', properties)
marks = Event('marks', properties)
# return an array of new events
return [subject, marks]
Sample output:
Two separate Events subject
and marks
are created.
getEventName() - string
Description: Returns the name of the Event.
Example:
The following transformation retrieves the Event name, and if it is discontinued_products
, filters the Event.
from io.hevo.api import Event
def transform(event):
# Get event name from the event
eventName = event.getEventName()
if eventName == 'activity':
return None
return event
Sample output:
The Event is filtered as Event name is activity.
getProperties() - dict
Description: Returns a dictionary (key-valyue pairs) of all the properties of the Event.
Example:
The following transformation retrieves the dictionary of the properties and modifies the value of a specific property.
from io.hevo.api import Event
def transform(event):
# Get properties from the event
properties = event.getProperties()
# Normalize marks to between 0 and 50
properties['Marks'] = properties['Marks'] * .5
return event
Sample output:
The value of the property Marks
is updated.
setProperties(dict: properties)
Description: Sets new properties for the Event.
Example:
The following transformation fetches the existing properties of an Event and sets new properties for it by modifying and adding to the existing ones.
from io.hevo.api import Event
def transform(event):
# Get properties from the event
properties = event.getProperties()
new_properties = {}
new_properties['Student Name'] = properties['Student Name']
new_properties['Marks'] = properties['Marks'] * 0.9
new_properties['School_ID'] = '1'
# Set a dictionary as the properties
event.setProperties(new_properties)
return event
Sample output:
A new set of properties is assigned to the Event, and some of the earlier properties are retained with modified values.
rename(string: new_event_name)
Description: Renames an Event with a new name of choice.
Example:
The following transformation picks Events with name as Student.Sheet1
and renames them to Results.Student.Sheet1
.
from io.hevo.api import Event
def transform(event):
# Get event name from the event #
eventName = event.getEventName()
# Update the eventName
# (This is how it will appear in the destination)
if eventName == 'Student.Sheet1':
event.rename('Results.' + eventName)
return event
Sample output:
The Event Student.Sheet1
is renamed.
isString(string: fieldname) - boolean
Description: Returns True if the value of the specified property is a string.
Example:
The following transformation code checks if the value of the property routing_number
is of type String and converts it into Number.
from io.hevo.api import Event
def transform(event):
properties = event.getProperties()
# Check if a field 'routing_number' is String
if event.isString('routing_number'):
properties['routing_number'] = int(properties['routing_number'])
return event
Sample output:
The data type of the property routing_number
is changed from String to Number.
isNumber(string: fieldname) - boolean
Description: Returns True if the value of the specified property is present and is a number.
Example:
The following transformation checks if the value of the property Marks
is of type Number and updates it to a new value, else deletes the property.
def transform(event):
properties = event.getProperties()
# Check if a field 'Marks' is Numeric
if event.isNumber('Marks'):
properties['Marks'] = properties['Marks'] * 0.6
else:
del properties['Marks']
return event
Sample output:
-
If the value of the property
Marks
is numeric, it is modified: -
If the value of the property
Marks
is a string, it is dropped from the Event.
isBoolean(string: fieldname) - boolean
Description: Returns True if the value of the specified property is present and is boolean.
Example:
The following transformation checks if the property available is boolean and updates its value.
from io.hevo.api import Event
def transform(event):
properties = event.getProperties()
# Check if a field 'available' is Boolean
if event.isBoolean('available'):
properties['available'] = 'Yes'
return event
Sample output:
isTimestamp(string: fieldname) - boolean
Description: Returns True if the value of the specified property is present and is a timestamp or datetime.
Example:
The following transformation updates the value of the property has_valid_report
as True if the property report_at
is of type Timestamp or Datetime.
from io.hevo.api import Event
def transform(event):
properties = event.getProperties()
# Check if a field 'report_at' is a Timestamp/Datetime
if event.isTimestamp('report_at'):
properties['has_valid_report'] = True
else:
properties['has_valid_report'] = False
return event
Sample output:
If the property report_at
is of type Timestamp, a new property has_valid_report
with the value True is added to the Event.
isDate(string: fieldname) - boolean
Description: Returns True if the value of the specified field name is present and is a date.
Note: For datetime values, the function returns False.
Example:
The following transformation adds a property has_valid_report
and assigns it the value True if the report_at property
is of type Date.
from io.hevo.api import Event
def transform(event):
properties = event.getProperties()
# Check if a field 'report_at' is a Date
if event.isDate('report_at'):
properties['has_valid_report'] = True
else:
properties['has_valid_report'] = False
return event
Sample output:
If the property report_at
is of type Date, a new property has_valid_report
with the value True is added to the Event.
isTime(string: fieldname) - boolean
Description: Returns True if the value of the specified field name is present and is a time value.
Note: For datetime values, the function returns False.
Example:
The following transformation adds a property has_valid_updated_ts
and assigns it the value True if the updated_ts property
is of type Time, else assigns the value False.
from io.hevo.api import Event
def transform(event):
properties = event.getProperties()
# Check if a field 'updated_ts' is a Time field
if event.isTime('updated_ts'):
properties['has_valid_updated_ts'] = True
else:
properties['has_valid_updated_ts'] = False
return event
Sample output:
If the property updated_ts
of type Time, a new property has_valid_updated_ts
with the value True is added to the Event.
getType( string: fieldname ) - string
Description: Returns the Type of the value of specified field name.
Example:
The following transformation checks for the data type of the property revenue and adds that as a new property to the Event.
from io.hevo.api import Event
def transform(event):
eventName = event.getEventName()
properties = event.getProperties()
Type = event.getType('Marks')
properties['type'] = Type
return event
Sample output:
A new property type is added to the Event to indicate the data type of the property Marks
.
getPrimaryKeyFields() - string[]
Description: Returns the list of fields which are primary keys in the Event.
Example:
The following transformation fetches the list of properties that are primary keys in the Event.
from io.hevo.api import Event
def transform(event):
# Fetches the current set of primary keys for a given record
pk_fields = event.getPrimaryKeyFields()
properties = event.getProperties()
properties['existing_pk_fields'] = pk_fields
return event
Sample output:
The list of primary keys for the Event are added as a new property called existing_pk_fields
.
setPrimaryKeyFields(string[]: fieldnames)
Description: Sets the specified list of field names as the primary key of the Event.
Example:
The following transformation sets the specified properties of an Event as the primary keys.
from io.hevo.api import Event
def transform(event):
# Set a field (or a list of fields) as the primary key
event.setPrimaryKeyFields(['ID', 'Student Name'])
properties = event.getProperties()
properties['new_pk_fields'] = event.getPrimaryKeyFields()
return event
Sample output:
The properties ID
and Student Name
are marked as primary keys for the Event.
Revision History
Refer to the following table for the list of key updates made to this page:
Date | Release | Description of Change |
---|---|---|
Apr-25-2022 | NA | Updates the screenshots to reflect the latest UI. |