apache/beam · error · ValueError
Either size or error should be set. Received
Error message
Either size or error should be set. Received {}. What it means
The same mutual-exclusion rule as 3836: parse_input_params raises ApproximateUnique._NO_VALUE_ERR_MSG ('Either size or error should be set. Received {}.') when NEITHER size nor error is provided. At least one parameter must be present to define the estimator.
Solutions
- Pass exactly one of size or error to ApproximateUnique.
- Validate configuration before building the pipeline so missing fields fail early with a clear message.
- Default one parameter explicitly in your wrapper, e.g. error=0.02.
Example fix
// before beam.ApproximateUnique() // after beam.ApproximateUnique(error=0.02)
Defensive patterns
Strategy: validation
Validate before calling
assert size is not None or error is not None, \
'ApproximateUnique requires size or error'
if size is None and error is None:
error = 0.02 # default Type guard
def has_estimation_param(size, error) -> bool:
return size is not None or error is not None Try / catch
try:
t = beam.ApproximateUnique(size=size, error=error)
except ValueError as e:
if 'Either size or error' in str(e):
t = beam.ApproximateUnique(error=0.02) # sensible default
else:
raise Prevention
- Always pass an explicit error or size to ApproximateUnique.
- Use keyword arguments so renamed config keys fail validation, not silently arrive as None.
- Default the parameter in your pipeline template schema.
When it happens
Trigger: beam.ApproximateUnique() with no arguments; a config/transform spec where the key holding size/error was renamed or dropped so the value arrives as None.
Common situations: Dynamic configuration where the field name changed (e.g. 'sample_size' vs 'size'), leaving both unset; template fills missing optional parameters.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- ApproximateUnique needs a size >= 16 for an error <= 0.50…
- ApproximateUnique needs an estimation error between 0.01…
- Either size or error should be set. Received
- A BigQuery table or a query must be specified
- A cluster_identifier should be Optional[Union[str…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/5a69748f5b408ee0.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/transforms/stats.py:124
def parse_input_params(size=None, error=None):
"""
Check if input params are valid and return sample size.
:param size: an int not smaller than 16, which we would use to estimate
number of unique values.
:param error: max estimation error, which is a float between 0.01 and 0.50.
If error is given, sample size will be calculated from error with
_get_sample_size_from_est_error function.
:return: sample size
:raises:
ValueError: If both size and error are given, or neither is given, or
values are out of range.
"""
if None not in (size, error):
raise ValueError(ApproximateUnique._MULTI_VALUE_ERR_MSG % (size, error))
elif size is None and error is None:
raise ValueError(ApproximateUnique._NO_VALUE_ERR_MSG)
elif size is not None:
if not isinstance(size, int) or size < 16:
raise ValueError(ApproximateUnique._INPUT_SIZE_ERR_MSG % (size))
else:
return size
else:
if error < 0.01 or error > 0.5:
raise ValueError(ApproximateUnique._INPUT_ERROR_ERR_MSG % (error))
else:
return ApproximateUnique._get_sample_size_from_est_error(error)
@staticmethod
def _get_sample_size_from_est_error(est_err):
"""
:return: sample size
Calculate sample size from estimation error
"""View on GitHub (pinned to 12126d8942)