@classmethod
    def split_input(cls, mapper_spec):
        shard_count = mapper_spec.shard_count

        # Grab the input parameters for the split
        params = input_readers._get_params(mapper_spec)
        logging.info("Params: %r", params)

        db = params['db']
        # Unpickle the query
        app, model = params['model'].split('.')
        model = apps.get_model(app, model)

        # Grab the lowest pk
        query = model.objects.using(db).all()
        query = query.order_by('pk')

        try:
            first_id = query.values_list('pk', flat=True)[:1][0]

            query = query.order_by('-pk')
            last_id = query.values_list('pk', flat=True)[:1][0]
        except __HOLE__:
            return [DjangoInputReader(0, 0, params['model'], db=db)]

        pk_range = last_id - first_id

        logging.info("Query range: %s - %s = %s", first_id, last_id, pk_range)

        if pk_range < shard_count or shard_count == 1:
            return [DjangoInputReader(first_id-1, last_id, params['model'], db=db)]

        readers = []
        max_shard_size = int(float(pk_range) / float(shard_count))
        if pk_range % shard_count:
            max_shard_size += 1

        shard_id = 1
        # Splitting could be much smarter by taking a __scatter__ sample and
        # clustering, which is how the DatastoreInputWriter from the mapreduce
        # splits on pks
        for i in itertools.count(first_id-1, max_shard_size):
            if i >= last_id:
                break

            shard_start_id = i
            shard_end_id = i + max_shard_size
            if shard_end_id > last_id:
                shard_end_id = last_id

            logging.info("Creating shard: %s - %s", shard_start_id, shard_end_id)
            reader = DjangoInputReader(shard_start_id, shard_end_id, params['model'], db=db)
            reader.shard_id = shard_id
            readers.append(reader)
            shard_id += 1
        return readers
dataset/ETHPy150Open potatolondon/djangae/djangae/contrib/mappers/readers.py/DjangoInputReader.split_input