Mappings determine how your various inputs will be mapped into your target data warehouse by defining which event fields are replicated into which tables and columns. To manage your mappings programmatically rather than via the UI, you can use the examples below.
Mappings contain the following information:
name: Name of the Event Type
origInputLabel: Name of the first input to push data to this mapping
schemaUrls: A reference passed along by the input that supplies more data about self
usingDefaultMappingMode: Using default mapping mode.
mappingMode: If not using the default mapping mode, use this value instead. Flexible, Auto-mapped, or Strict.
See information on mapping modes for unmapped fields here: https://app.alooma.com/#/mapping-mode.
state: State of the Mapping (MAPPED, UNMAPPED)
In the code example above,
mapping['mapping']['isDiscarded']means a mapping exists, but the event is discarded
isDiscarded: See above, the event is mapped, but also discarded
schema: Destination schema of the mapping table
tableName: The table the data is loaded into
outputId: (Not Currently Used)
consolidation: Not necessary for "Append Only" sources
consolidatedSchema: Destination schema of the consolidated table
consolidatedTableName: Destination table name (must be identical structure to mapping)
consolidationKeys: List of Primary Keys used in consolidation (default from schemaUrls)
Contains all the information around fields in the data and how they translate to columns in the target data warehouse
Contains a list of field objects (dicts) with information regarding the field
Get all event types (NOTE: an event type is a subset of a mapping and does not contain the fields structure)
Get a specific mapping
Set mapping objects after making changes
Delete event type (NOTE: this does not drop the tables)
See the examples below for usage.
EVENT_TYPE = '<name of mapping>' api = alooma.Client(ALOOMA_USERNAME, ALOOMA_PASSWORD, account_name=ACCOUNT_NAME) ## Get Specific Event Type with all Info mapping = api.get_mapping(EVENT_TYPE) # Returns the full mapping (dictionary) with all fields
""" Retrieve All Event Types """ ## Retrieve All Event Types with a Subset of Total Data events = api.get_event_types() # Returns a list of dictionaries (basically, a list of mapping objects but without the fields section) # this one cannot be used in set_mapping() # Print All Event Types print '\n'.join([e['name'] for e in events])
""" Rename or Move an Event Type """ EVENT_TYPE = '<event_type>' NEW_EVENT_TYPE = '<new_event_type>' mapping = api.get_mapping(EVENT_TYPE) mapping['name'] = NEW_EVENT_TYPE # Copy Mapping to NEW_EVENT_TYPE api.set_mapping(mapping, NEW_EVENT_TYPE) # Delete Old Event Type (if desired) # NOTE: Avoid keeping duplicates of event types api.delete_event_type(EVENT_TYPE)