Retrieve the Type for a Value

Last updated on Jun 30, 2023
Definition: getType(value: object) → str
Description: Returns the data type of a value stored in a variable
Parameters: value: The value for which you want to determine the type
Returns: The data type of the value as a string

The following script takes the value of the variable in the <someNumber> field and utilizes the getType function to determine its data type. It assigns the returned type as a string to the new field, <type>.

These data types can be helpful to assess any necessary modifications to the raw data.

Note: Replace the placeholder values in the script with your own.

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()

    <someNumber> = <value of the variable>
    properties['type'] = Utils.getType(<someNumber>)
        ...

Sample Transformation

Consider the following two fields:

  • address - contains street, state, and country details
  • id - contains identification details

The gettype function extracts the data types of the id and address fields and stores them in the id_type and address_type fields, respectively.

from io.hevo.api import Event
from io.hevo.api import Utils


def transform(event):
    properties = event.getProperties()

    id_type = Utils.getType(properties['id'])
    properties['id_type'] = id_type

    address_type = Utils.getType(properties['address'])
    properties['address_type'] = address_type

    return event

Sample Output

The id_type and address_type fields are created and the data types of the id and address fields are stored in these, respectively.

Sample Output - Retrieve the Type for a Value



Revision History

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

Date Release Description of Change
Jun-26-2023 NA New document.

Tell us what went wrong