πŸ“„ By AnswerΒΆ

operators.balancers.qa.by_answer

type: DeterministicBalancer
fields: 
  - reference_fields/answer
[source]

Explanation about DeterministicBalancerΒΆ

A class used to balance streams deterministically.

For each instance, a signature is constructed from the values of the instance in specified input β€˜fields’. By discarding instances from the input stream, DeterministicBalancer maintains equal number of instances for all signatures. When also input β€˜max_instances’ is specified, DeterministicBalancer maintains a total instance count not exceeding β€˜max_instances’. The total number of discarded instances is as few as possible.

Args:
fields (List[str]):

A list of field names to be used in producing the instance’s signature.

max_instances (Optional, int):

overall max.

Usage:

balancer = DeterministicBalancer(fields=["field1", "field2"], max_instances=200) balanced_stream = balancer.process(stream)

Example:

When input [{"a": 1, "b": 1},{"a": 1, "b": 2},{"a": 2},{"a": 3},{"a": 4}] is fed into DeterministicBalancer(fields=["a"]) the resulting stream will be: [{"a": 1, "b": 1},{"a": 2},{"a": 3},{"a": 4}]

Read more about catalog usage here.