예제 #1
0
def import_dataset(host,
                   protocol,
                   port,
                   username,
                   password,
                   dataset_name,
                   csv_filepath,
                   id_field,
                   description,
                   create_json=True):

    start = datetime.datetime.now()

    csv_filepath = is_valid_file(csv_filepath)

    # Create dataset
    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.create_dataset(dataset_name,
                                      csv_filepath,
                                      id_field,
                                      description=description)
    print(response.json())

    # Upload records
    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.update_dataset(dataset_name=dataset_name,
                                      file_name=csv_filepath,
                                      id_field=id_field,
                                      create_json=create_json)
    print(response.json())

    end = datetime.datetime.now()
    duration = round((end - start).seconds / 60, 3)
    print('Completed in {duration} minutes'.format(duration=duration))
예제 #2
0
def import_clusters(host,
                    protocol,
                    port,
                    username,
                    password,
                    unified_dataset_name,
                    cluster_name_field,
                    recipe_id,
                    csv_filepath,
                    json_filepath,
                    unique_id_column_name,
                    tamr_cluster_id_col,
                    encoding,
                    create_json=True):

    if create_json:
        json_filepath = get_cluster_json(csv_filepath,
                                         json_filepath,
                                         unified_dataset_name,
                                         unique_id_column_name,
                                         tamr_cluster_id_col,
                                         recipe_id,
                                         encoding=encoding)
    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.import_clusters(
            unified_dataset_name=unified_dataset_name,
            cluster_name_field=cluster_name_field,
            recipe_id=recipe_id,
            json_filepath=json_filepath)
    return response
예제 #3
0
def split_cluster(host, protocol, port, username, password,
                  unified_dataset_name, cluster_name_field, json_file_path):

    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.split_cluster(unified_dataset_name=unified_dataset_name,
                                     cluster_name_field=cluster_name_field,
                                     json_file_path=json_file_path)
    return response
예제 #4
0
def assign_clusters(host, protocol, port, username, password,
                    unified_dataset_name, usernames, cluster_ids):

    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.assign_clusters(
            unified_dataset_name=unified_dataset_name,
            usernames=usernames,
            cluster_ids=cluster_ids)
    return response
예제 #5
0
def merge_clusters(host, protocol, port, username, password,
                   unified_dataset_name, cluster_name_field, target_cluster_id,
                   cluster_ids_to_merge):

    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.merge_clusters(
            unified_dataset_name=unified_dataset_name,
            cluster_name_field=cluster_name_field,
            target_cluster_id=target_cluster_id,
            cluster_ids_to_merge=cluster_ids_to_merge)
    return response
예제 #6
0
def create_dataset(host, protocol, port, username, password, dataset_name,
                   csv_filepath, id_field, description):

    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.create_dataset(dataset_name=dataset_name,
                                      file_path=is_valid_file(csv_filepath),
                                      id_field=id_field,
                                      delimiter=',',
                                      encoding='utf-8',
                                      description=description)
    return response
예제 #7
0
def get_records_in_cluster(host,
                           protocol,
                           port,
                           username,
                           password,
                           unified_dataset_name,
                           cluster_id,
                           sort_by_spend='false',
                           limit=100):

    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.get_records_in_cluster(
            unified_dataset_name=unified_dataset_name,
            cluster_id=cluster_id,
            sort_by_spend=sort_by_spend,
            limit=limit)
    return response
예제 #8
0
def upsert_records(host,
                   protocol,
                   port,
                   username,
                   password,
                   dataset_name,
                   csv_filepath,
                   id_field,
                   create_json=True):

    # Check valid path
    csv_filepath = is_valid_file(csv_filepath)

    # Update dataset
    with TamrAPI(host, protocol, port, username, password) as api:
        update_response = api.update_dataset(dataset_name=dataset_name,
                                             csv_filepath=csv_filepath,
                                             id_field=id_field,
                                             create_json=create_json)
    print(update_response.json())
예제 #9
0
def get_cluster_ids(host,
                    protocol,
                    port,
                    username,
                    password,
                    unified_dataset_name,
                    query='',
                    offset='',
                    limit='',
                    sort='',
                    cluster_ids='',
                    name=''):

    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.get_cluster_ids(
            unified_dataset_name=unified_dataset_name,
            query=query,
            offset=offset,
            limit=limit,
            sort=sort,
            cluster_ids=cluster_ids,
            name=name)
    return response
예제 #10
0
def get_assigned_clusters(host, protocol, port, username, password):

    with TamrAPI(host, protocol, port, username, password) as api:
        response = api.get_assigned_clusters()
    return response