Modify the Primary Keys of an Event
Definition: | setPrimaryKeyFields([fieldnames]: List[str] ) → None |
Description: | Sets the specified fields as the new primary keys for the Event. Note: You cannot set the primary key for an Event Type created through Transformations. However, you can use the Schema Mapper page of your Pipeline and set the primary key for that Event Type. |
Parameters: | fieldnames: The list of fields to be set as primary keys for the Event. |
Returns: | No return value, which is indicated by None . |
The following script sets the primary key of the Event:
from io.hevo.api import Event
def transform(event):
event.setPrimaryKeyFields(['<new_field_name1>','<new_field_name2>',...])
return event
Sample Transformation
The script below demonstrates how this method can be used. It:
-
Sets the primary keys of the Event to a composite key comprising the
ID
andStudent Name
fields. -
Retrieves the new primary keys.
-
Adds the
new_pk_fields
property to the Event.
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 Transformation adds the list of primary key fields for the Event as a new property called new_pk_fields
.
Last updated on Jun 30, 2023