Documentation

Managing Mappings Programmatically

Abstract

SummaryAn overview of mappings, including what they are, what they contain, and how to work with them using various mapping functions: get, edit, delete.

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.

Mapping information

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.

Note

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

mapping:

  • 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)

fields:

  • 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

Mapping functions

Get all event types (NOTE: an event type is a subset of a mapping and does not contain the fields structure)

Copy
api.get_event_types()

Get a specific mapping

Copy
api.get_mapping('event_type')

Set mapping objects after making changes

Copy
api.set_mapping(mapping, 'event_type')

Delete event type (NOTE: this does not drop the tables)

Copy
api.delete_event_type('event_type')

See the examples below for usage.

Getting a mapping
Copy
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
Get a list of all Event Types
Copy
""" 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
Copy
""" 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)

Search results

    No results found