{"record":{"id":"5a210056ccfbaadf","repo":"apache/beam","slug":"the-relative-error-must-be-positive","errorCode":null,"errorMessage":"The relative error must be positive","messagePattern":"The relative error must be positive","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sketching/src/main/java/org/apache/beam/sdk/extensions/sketching/SketchFrequencies.java","lineNumber":383,"sourceCode":"        throw new IllegalArgumentException(\n            \"Coder must be deterministic to perform this sketch.\" + e.getMessage(), e);\n      }\n      return new CountMinSketchFn<>(coder, 0.01, 0.999);\n    }\n\n    /**\n     * Returns a new {@link CountMinSketchFn} combiner with new precision accuracy parameters {@code\n     * epsilon} and {@code confidence}.\n     *\n     * <p>Keep in mind that the lower the {@code epsilon} value, the greater the width, and the\n     * greater the confidence, the greater the depth.\n     *\n     * @param epsilon the error relative to the total number of distinct elements\n     * @param confidence the confidence in the result to not exceed the relative error\n     */\n    public CountMinSketchFn<InputT> withAccuracy(double epsilon, double confidence) {\n      if (epsilon <= 0D) {\n        throw new IllegalArgumentException(\"The relative error must be positive\");\n      }\n\n      if (confidence <= 0D || confidence >= 1D) {\n        throw new IllegalArgumentException(\"The confidence must be between 0 and 1\");\n      }\n      return new CountMinSketchFn<>(inputCoder, epsilon, confidence);\n    }\n\n    @Override\n    public Sketch<InputT> createAccumulator() {\n      return Sketch.create(epsilon, confidence);\n    }\n\n    @Override\n    public Sketch<InputT> addInput(Sketch<InputT> accumulator, InputT element) {\n      accumulator.add(element, inputCoder);\n\n      return accumulator;","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sketching/src/main/java/org/apache/beam/sdk/extensions/sketching/SketchFrequencies.java#L365-L401","documentation":"SketchFrequencies.CountMinSketchFn.withAccuracy validates the requested relative error epsilon; it must be strictly positive because a zero or negative error is meaningless for a Count-Min Sketch (the width of the sketch is derived as ceil(2/epsilon)). An epsilon <= 0 throws this IllegalArgumentException immediately at pipeline construction time.","triggerScenarios":"Calling withAccuracy(0, 0.99) or withAccuracy(-0.01, 0.99), or accidentally passing a computed epsilon that evaluates to 0 (e.g. integer division or an uninitialized config value cast to double).","commonSituations":"Accuracy parameters read from config files/flags where a zero or negative default leaked through; typos like withAccuracy(0D, confidence); unit confusion producing negative values.","solutions":["Pass a positive epsilon, e.g. withAccuracy(0.01, 0.999) for 1% relative error.","Validate config-derived epsilon values before building the pipeline and fail fast with a clear message.","Sanity-check computations that produce epsilon (avoid integer division truncating to 0)."],"exampleFix":"// before\nsketch.withAccuracy(0, 0.999); // throws\n// after\nsketch.withAccuracy(0.01, 0.999); // 1% relative error, 99.9% confidence","handlingStrategy":"validation","validationCode":"if (!(epsilon > 0D)) throw new IllegalArgumentException(\"epsilon must be > 0, got \" + epsilon);\nsketch.withAccuracy(epsilon, confidence);","typeGuard":null,"tryCatchPattern":"try { sketch.withAccuracy(eps, conf); } catch (IllegalArgumentException e) { /* fall back to default accuracy */ }","preventionTips":["Validate config-derived epsilon before pipeline construction","Beware integer division truncating epsilon to 0","Use named constants (e.g. DEFAULT_EPSILON = 0.01) instead of ad-hoc literals"],"tags":["java","beam","sketching","count-min-sketch","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}