<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _get_datasets(dataset_ids):
 """ Get all the datasets in a list of dataset IDS. This must be done in chunks of 999, as sqlite can only handle 'in' with < 1000 elements. """


    dataset_dict = {}

    datasets = []
    if len(dataset_ids) > qry_in_threshold:
        idx = 0
        extent =qry_in_threshold
        while idx < len(dataset_ids):
            log.info("Querying %s datasets", len(dataset_ids[idx:extent]))
            rs = db.DBSession.query(Dataset).filter(Dataset.id.in_(dataset_ids[idx:extent])).all()
            datasets.extend(rs)
            idx = idx + qry_in_threshold

            if idx + qry_in_threshold > len(dataset_ids):
                extent = len(dataset_ids)
            else:
                extent = extent + qry_in_threshold
    else:
        datasets = db.DBSession.query(Dataset).filter(Dataset.id.in_(dataset_ids))


    for r in datasets:
        dataset_dict[r.id] = r

    log.info("Retrieved %s datasets", len(dataset_dict))

    return dataset_dict