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 unweighted reservoir-sampling strategy of differential_entropy requires the max_samples parameter to be strictly positive. The constructor validates this before creating the reservoir sample; a zero or negative value would make sampling impossible, so Presto throws INVALID_FUNCTION_ARGUMENT at aggregation setup.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/differentialentropy/UnweightedReservoirSampleStateStrategy.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 java.lang.Math.toIntExact;
import static java.lang.String.format;
public class UnweightedReservoirSampleStateStrategy
implements DifferentialEntropyStateStrategy
{
private final UnweightedDoubleReservoirSample reservoir;
public UnweightedReservoirSampleStateStrategy(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 >= UnweightedDoubleReservoirSample.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, UnweightedDoubleReservoirSample.MAX_SAMPLES_LIMIT));
}
reservoir = new UnweightedDoubleReservoirSample(toIntExact(maxSamples));
}
private UnweightedReservoirSampleStateStrategy(UnweightedReservoirSampleStateStrategy other)
{
reservoir = other.reservoir.clone();
}
private UnweightedReservoirSampleStateStrategy(UnweightedDoubleReservoirSample reservoir)View on GitHub (pinned to 55bb57d202)
Solutions
- Pass a positive integer literal for max_samples (a few thousand is typical)
- Check any bound application parameter for 0 or negative defaults and correct it
- Validate inputs before the query: WHERE :max_samples > 0 or application-side checks
- Use a constant rather than a per-row expression that can be <= 0
Example fix
-- before SELECT differential_entropy(x, 1.0, :max_samples) FROM t; -- :max_samples = 0 -- after SELECT differential_entropy(x, 1.0, 10000) FROM t;
Defensive patterns
Strategy: validation
Validate before calling
-- max_samples must be > 0 SELECT :max_samples > 0 AS valid; -- or application-side assert maxSamples > 0
Type guard
boolean isValidMaxSamples(long maxSamples) { return maxSamples > 0; } Prevention
- Never pass 0 or negative defaults as max_samples from application parameters
- Use a fixed positive literal (e.g. 10000) instead of a computed expression
- Validate bound parameters before issuing the query
When it happens
Trigger: Calling differential_entropy(x, 1.0, max_samples) where max_samples is a literal 0, a negative number, or a non-constant expression that evaluates to <= 0 for some group.
Common situations: Parameterized queries where an application passes 0 as a default/placeholder; sign errors in computed values; using a column that is 0 for some rows as max_samples in a grouped query.
Related errors
- array1 and array2 cannot be null and should have same length
- arrayOffset is negative
- positionCount is negative
- positionCount is negative
- ids length is less than positionCount
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/4708bbd8db1deb2c.
Report an issue: GitHub.