def _run_query(query, records):
  """Executes query on the given set of records as a single sample.

  Args:
    query: A PrivateQuery to run.
    records: An iterable containing records to pass to the query.

  Returns:
    The result of the query.
  """
  global_state = query.initial_global_state()
  params = query.derive_sample_params(global_state)
  sample_state = query.initial_sample_state(global_state, next(iter(records)))
  for record in records:
    sample_state = query.accumulate_record(params, sample_state, record)
  result, _ = query.get_query_result(sample_state, global_state)
  return result