import uuid


def load_table(service, source_schema, source_csv,
               projectId, datasetId, tableId, num_retries=5):
    """
    Starts a job to load a bigquery table from CSV

    Args:
        service: an initialized and authorized bigquery
        google-api-client object
        source_schema: a valid bigquery schema,
        see https://cloud.google.com/bigquery/docs/reference/v2/tables
        source_csv: the fully qualified Google Cloud Storage location of
        the data to load into your table

    Returns: a bigquery load job, see
    https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load
    """

    # Generate a unique job_id so retries
    # don't accidentally duplicate query
    job_data = {
        'jobReference': {
            'projectId': projectId,
            'job_id': str(uuid.uuid4())
        },
        'configuration': {
            'load': {
                'sourceUris': [source_csv],
                'schema': {
                    'fields': source_schema
                },
                'destinationTable': {
                    'projectId': projectId,
                    'datasetId': datasetId,
                    'tableId': tableId
                }
            }
        }
    }

    return service.jobs().insert(
        projectId=projectId,
        body=job_data).execute(num_retries=num_retries)