[Resolved] Hi Team, quick question regarding trans...
# troubleshoot
c
[Resolved] Hi Team, quick question regarding transformers:
Copy code
add_dataset_tags
What kind of output must my user defined function provide? A str or list of strings leads to errors. Thank you Example:
Copy code
import logging

import datahub.emitter.mce_builder as builder
from datahub.metadata.schema_classes import (
    DatasetSnapshotClass,
    TagAssociationClass,
)

def custom_tags(current: DatasetSnapshotClass):
    """ Returns tags to associate to a dataset depending on custom logic

    This function receives a DatasetSnapshotClass, performs custom logic and returns
    a list of TagAssociationClass-wrapped tags.

    Args:
        current (DatasetSnapshotClass): Single DatasetSnapshotClass object

    Returns:
        List of TagAssociationClass objects.
    """

    tag_strings = []

    ### Add custom logic here
    tag_strings.append('custom1')
    tag_strings.append('custom2')
    
    tag_strings = [builder.make_tag_urn(tag=n) for n in tag_strings]
    tags = [TagAssociationClass(tag=tag) for tag in tag_strings]
    
    <http://logging.info|logging.info>(f"Tagging dataset {current.urn} with {tag_strings}.")
    return tags
Maybe @gray-shoe-75895 or @mammoth-bear-12532 have some pointers here?
m
Hi @clean-crayon-15379: it’s not a super ideal interface… but here’s what the contract is:
Copy code
get_tags_to_add:         Callable[[DatasetSnapshotClass], List[TagAssociationClass]]
which means your function will get a
DatasetSnapshotClass
as input and must return a list of
TagAssociationClass
as output
1
c
Fantastic, thank you very much!
I got so far, but did not create the list as expected, I'll do it today
Short question on top: OK to PR to the documentation following your guidelines?
m
Will be very welcome!!