sample method

Pipeline sample({
  1. int? documents,
  2. double? percentage,
  3. Map<String, Object?>? rawOptions,
})

Keeps a random sample of the inputs: either a number of documents, or a percentage of them between 0 and 1. Exactly one must be given.

Implementation

Pipeline sample({
  int? documents,
  double? percentage,
  Map<String, Object?>? rawOptions,
}) {
  if ((documents == null) == (percentage == null)) {
    throw ArgumentError(
      'sample() needs exactly one of documents and percentage.',
    );
  }
  return _append(
    Stage(
      'sample',
      args: <pb.Value Function(PipelineEncoder)>[
        (_) => documents != null
            ? integerValue(documents)
            : doubleValue(percentage!),
        (_) => stringValue(documents != null ? 'documents' : 'percent'),
      ],
      rawOptions: rawOptions,
    ),
  );
}