{"record":{"id":"4708bbd8db1deb2c","repo":"prestodb/presto","slug":"invalid-function-argument-4708bb","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/UnweightedReservoirSampleStateStrategy.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 java.lang.Math.toIntExact;\nimport static java.lang.String.format;\n\npublic class UnweightedReservoirSampleStateStrategy\n        implements DifferentialEntropyStateStrategy\n{\n    private final UnweightedDoubleReservoirSample reservoir;\n\n    public UnweightedReservoirSampleStateStrategy(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 >= UnweightedDoubleReservoirSample.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, UnweightedDoubleReservoirSample.MAX_SAMPLES_LIMIT));\n        }\n\n        reservoir = new UnweightedDoubleReservoirSample(toIntExact(maxSamples));\n    }\n\n    private UnweightedReservoirSampleStateStrategy(UnweightedReservoirSampleStateStrategy other)\n    {\n        reservoir = other.reservoir.clone();\n    }\n\n    private UnweightedReservoirSampleStateStrategy(UnweightedDoubleReservoirSample 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/UnweightedReservoirSampleStateStrategy.java#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"-- before\nSELECT differential_entropy(x, 1.0, :max_samples) FROM t; -- :max_samples = 0\n-- after\nSELECT differential_entropy(x, 1.0, 10000) FROM t;","handlingStrategy":"validation","validationCode":"-- max_samples must be > 0\nSELECT :max_samples > 0 AS valid; -- or application-side assert maxSamples > 0","typeGuard":"boolean isValidMaxSamples(long maxSamples) { return maxSamples > 0; }","tryCatchPattern":null,"preventionTips":["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"],"tags":["presto","udf","argument-validation","differential-entropy"],"backgroundTag":"invalid-function-arguments","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"}