{"record":{"id":"247a0fbf939b9faa","repo":"prestodb/presto","slug":"invalid-function-argument-247a0f","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"In differential_entropy UDF, max samples must be positive: %s","messagePattern":"In differential_entropy UDF, max samples must be positive: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/differentialentropy/WeightedReservoirSampleStateStrategy.java","lineNumber":33,"sourceCode":"\nimport com.facebook.presto.spi.PrestoException;\nimport io.airlift.slice.SliceInput;\nimport io.airlift.slice.SliceOutput;\n\nimport static com.facebook.presto.operator.aggregation.differentialentropy.EntropyCalculations.calculateFromSamplesUsingVasicek;\nimport static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;\nimport static com.google.common.base.Verify.verify;\nimport static java.lang.String.format;\n\npublic class WeightedReservoirSampleStateStrategy\n        implements DifferentialEntropyStateStrategy\n{\n    private final WeightedDoubleReservoirSample reservoir;\n\n    public WeightedReservoirSampleStateStrategy(long maxSamples)\n    {\n        if (maxSamples <= 0) {\n            throw new PrestoException(\n                    INVALID_FUNCTION_ARGUMENT,\n                    format(\"In differential_entropy UDF, max samples must be positive: %s\", maxSamples));\n        }\n        if (maxSamples >= WeightedDoubleReservoirSample.MAX_SAMPLES_LIMIT) {\n            throw new PrestoException(\n                    INVALID_FUNCTION_ARGUMENT,\n                    format(\"In differential_entropy UDF, max samples  must be capped: max_samples=%s, cap=%s\", maxSamples, WeightedDoubleReservoirSample.MAX_SAMPLES_LIMIT));\n        }\n\n        reservoir = new WeightedDoubleReservoirSample((int) maxSamples);\n    }\n\n    private WeightedReservoirSampleStateStrategy(WeightedReservoirSampleStateStrategy other)\n    {\n        reservoir = other.reservoir.clone();\n    }\n\n    private WeightedReservoirSampleStateStrategy(WeightedDoubleReservoirSample reservoir)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/differentialentropy/WeightedReservoirSampleStateStrategy.java#L15-L51","documentation":"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.","triggerScenarios":"Constructing WeightedReservoirSampleStateStrategy with maxSamples <= 0, i.e. calling differential_entropy(...) with a max_samples argument of 0 or a negative number.","commonSituations":"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.","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."],"exampleFix":"// before\nSELECT differential_entropy(x, w, s, 0);\n// after\nSELECT differential_entropy(x, w, s, 1000);","handlingStrategy":"validation","validationCode":"-- reject non-positive max_samples before the call\nSELECT * FROM cfg WHERE max_samples IS NULL OR max_samples <= 0; -- must be empty","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["presto","aggregation","invalid-argument","differential-entropy"],"backgroundTag":"invalid-aggregation-parameter-value","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}