prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
In differential_entropy UDF, max samples must be positive: %s
What it means
The weighted reservoir sampling strategy for differential_entropy requires a strictly positive max_samples because the reservoir must be able to hold at least one sample. The constructor rejects zero or negative capacities up front with INVALID_FUNCTION_ARGUMENT rather than failing later during aggregation.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/differentialentropy/WeightedReservoirSampleStateStrategy.java:33
import com.facebook.presto.spi.PrestoException;
import io.airlift.slice.SliceInput;
import io.airlift.slice.SliceOutput;
import static com.facebook.presto.operator.aggregation.differentialentropy.EntropyCalculations.calculateFromSamplesUsingVasicek;
import static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
import static com.google.common.base.Verify.verify;
import static java.lang.String.format;
public class WeightedReservoirSampleStateStrategy
implements DifferentialEntropyStateStrategy
{
private final WeightedDoubleReservoirSample reservoir;
public WeightedReservoirSampleStateStrategy(long maxSamples)
{
if (maxSamples <= 0) {
throw new PrestoException(
INVALID_FUNCTION_ARGUMENT,
format("In differential_entropy UDF, max samples must be positive: %s", maxSamples));
}
if (maxSamples >= WeightedDoubleReservoirSample.MAX_SAMPLES_LIMIT) {
throw new PrestoException(
INVALID_FUNCTION_ARGUMENT,
format("In differential_entropy UDF, max samples must be capped: max_samples=%s, cap=%s", maxSamples, WeightedDoubleReservoirSample.MAX_SAMPLES_LIMIT));
}
reservoir = new WeightedDoubleReservoirSample((int) maxSamples);
}
private WeightedReservoirSampleStateStrategy(WeightedReservoirSampleStateStrategy other)
{
reservoir = other.reservoir.clone();
}
private WeightedReservoirSampleStateStrategy(WeightedDoubleReservoirSample reservoir)View on GitHub (pinned to 55bb57d202)
Solutions
- Pass a max_samples value of at least 1 (typically a few thousand for meaningful entropy estimates).
- Fix the expression producing max_samples so it cannot evaluate to 0 or a negative number.
- Add a CHECK/CASE guard in the query or coerce non-positive values to a sane default before aggregation.
Example fix
// before SELECT differential_entropy(x, w, s, 0); // after SELECT differential_entropy(x, w, s, 1000);
Defensive patterns
Strategy: validation
Validate before calling
-- reject non-positive max_samples before the call SELECT * FROM cfg WHERE max_samples IS NULL OR max_samples <= 0; -- must be empty
Prevention
- Validate configured max_samples > 0 at query-assembly time
- Use COALESCE(cfg.max_samples, 1000) with a positive default
- Add unit coverage for parameter-validation paths
When it happens
Trigger: Constructing WeightedReservoirSampleStateStrategy with maxSamples <= 0, i.e. calling differential_entropy(...) with a max_samples argument of 0 or a negative number.
Common situations: Passing a computed max_samples expression that evaluates to 0 (e.g. an empty/zero-valued column or bad default); typos such as -1 used as a sentinel.
Related errors
- DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION
- DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION
- Timeout is negative
- GENERIC_INSUFFICIENT_RESOURCES
- INVALID_FUNCTION_ARGUMENT
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/247a0fbf939b9faa.
Report an issue: GitHub.