{"record":{"id":"8b4372fe9213fa8f","repo":"apache/beam","slug":"floating-point-encodings-are-not-guaranteed-to-be-floatcoder","errorCode":null,"errorMessage":"Floating point encodings are not guaranteed to be deterministic.","messagePattern":"Floating point encodings are not guaranteed to be deterministic\\.","errorType":"exception","errorClass":"NonDeterministicException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/FloatCoder.java","lineNumber":70,"sourceCode":"    try {\n      return Float.intBitsToFloat(BitConverters.readBigEndianInt(inStream));\n    } catch (EOFException | UTFDataFormatException exn) {\n      // These exceptions correspond to decoding problems, so change\n      // what kind of exception they're branded as.\n      throw new CoderException(exn);\n    }\n  }\n\n  /**\n   * {@inheritDoc}\n   *\n   * @throws NonDeterministicException always. Floating-point operations are not guaranteed to be\n   *     deterministic, even if the storage format might be, so floating point representations are\n   *     not recommended for use in operations that require deterministic inputs.\n   */\n  @Override\n  public void verifyDeterministic() throws NonDeterministicException {\n    throw new NonDeterministicException(\n        this, \"Floating point encodings are not guaranteed to be deterministic.\");\n  }\n\n  /**\n   * {@inheritDoc}\n   *\n   * @return {@code true}. This coder is injective.\n   */\n  @Override\n  public boolean consistentWithEquals() {\n    return true;\n  }\n\n  /**\n   * {@inheritDoc}\n   *\n   * @return {@code true}. {@link FloatCoder#getEncodedElementByteSize} returns a constant.\n   */","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/FloatCoder.java#L52-L88","documentation":"FloatCoder.verifyDeterministic() unconditionally throws NonDeterministicException because floating-point encodings cannot be relied on to be byte-for-byte deterministic (storage format aside, FP semantics like NaN payloads and signed zeros make representations unsuitable for operations needing deterministic inputs). Beam requires deterministic coders for grouping, state, and cross-run keying.","triggerScenarios":"Using FloatCoder (or DoubleCoder) as the element coder for a PCollection/key coder in any context that calls verifyDeterministic, e.g. GroupByKey, CoGroupByKey, Combine perKey, stateful DoFns, or explicitly calling coder.verifyDeterministic().","commonSituations":"Grouping a PCollection of floats/doubles keyed or valued with FloatCoder; building a KV coder whose key coder is FloatCoder; using FloatCoder in a SetCoder/MapCoder requiring deterministic element coders.","solutions":["Use an integral or string representation instead: encode the float as a FixedBytesCoder of its IEEE-754 bits, or key on a normalized string.","Wrap the float in a custom Coder whose verifyDeterministic() succeeds and whose encode() writes a canonical byte representation (e.g. normalize -0.0 and NaN first).","Restructure the pipeline so float values are not used as grouping keys (key on an id, value on the float)."],"exampleFix":"// before\npipeline.apply(GroupByKey.create()) // PCollection<KV<Float, ...>> -> throws\n// after\nPCollection<KV<String, ...>> grouped =\n    pc.apply(MapElements.into(kvOf(strings(), floats())).via(f -> KV.of(String.valueOf(f), f)))\n      .apply(GroupByKey.create());","handlingStrategy":"fallback","validationCode":"try { FloatCoder.of().verifyDeterministic(); } catch (Coder.NonDeterministicException e) { /* switch to deterministic coder */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use raw Float/Double coders for grouping keys or stateful operations.","Prefer keying on ids/strings and carrying floats as values.","Run coder.verifyDeterministic() in pipeline unit tests before shuffle stages."],"tags":["java","apache-beam","coders","determinism","floating-point"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}