code: def _auto(method, fields, count, percent, key_field, ascending):
      if method == 'limit':
        return Sampling.default(fields=fields, count=count)
      elif method == 'random':
        return Sampling.random(fields=fields, percent=percent, count=count)
      elif method == 'hashed':
        return Sampling.hashed(fields=fields, field_name=key_field, percent=percent, count=count)
      elif method == 'sorted':
        return Sampling.sorted(fields=fields, field_name=key_field, ascending=ascending, count=count)
      else:
        raise Exception('Unsupported sampling method: %s' % method)