Modify the Primary Keys of an Event

Last updated on Jun 30, 2023
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:

  1. Sets the primary keys of the Event to a composite key comprising the ID and Student Name fields.

  2. Retrieves the new primary keys.

  3. 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.

Set Primary Key Fields



Revision History

Refer to the following table for the list of key updates made to this page:

Date Release Description of Change
Apr-10-2023 NA Updated the page to add a note regarding setting the primary key through the Schema Mapper page.
Feb-14-2023 NA New document.

Tell us what went wrong