Datatamer / tamr-client

Programmatically interact with Tamr
https://tamr-client.readthedocs.io
Apache License 2.0
11 stars 25 forks source link

TC: AttributeMapping dataclass with create/read/delete functions #482

Closed skalish closed 3 years ago

skalish commented 3 years ago

↪️ Pull Request

This PR adds the AttributeMapping dataclass and functions for creating and deleting, as well as getting all attribute mappings from a project.

Important note: This implementation memo-izes fetched Attributes when making the get_all call. This should probably be inspected closely.

Open questions:

Closes #479

💻 Examples

import tamr_client as tc

my_project = Project(...)  # my Tamr project
my_input_attr = Attribute(...)  # an existing attribute of an input dataset of `project`
my_unified_attr = Attribute(...)  # an existing attribute of the unified dataset of `project`

# Create a new attribute mapping
new_attr_mapping = tc.schema_mapping.attribute_mapping.create(my_project, input_attribute=my_input_attr, unified_attribute=my_unified_attr)

# Get all attribute mappings of my project
all_attr_mappings =  tc.schema_mapping.attribute_mapping.get_all(my_project)  # this is a list
print(new_attr_mapping in all_attr_mappings)  # my new mapping should be in there

# Delete my attribute mapping
tc.schema_mapping.attribute_mapping.delete(new_attr_mapping)

# Extension: I want to completely unmap `my_input_attr`
for mapping in tc.schema_mapping.attribute_mapping.get_all(my_project):
    if mapping.input_attribute_url == my_input_attr.url:
        tc.schema_mapping.attribute_mapping.delete(mapping)

✔️ PR Todo

github-actions[bot] commented 3 years ago

:tada: This PR is included in version 1.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: