Skip to content

[Bug]: floatValueExtractor judge float and double equality directly #29912

Description

@gabry-lab

What happened?

  static ValueExtractor<Float> floatValueExtractor() {
    return ValidatingValueExtractor.<Float>builder()
        .setExtractor(JsonNode::floatValue)
        .setValidator(
            jsonNode ->
                jsonNode.isFloat()

                    // Either floating number which allows lossless conversion to float
                    || (jsonNode.isFloatingPointNumber()
                        && jsonNode.doubleValue() == (double) (float) jsonNode.doubleValue())

                    // Or an integer number which allows lossless conversion to float
                    || (jsonNode.isIntegralNumber()
                        && jsonNode.canConvertToInt()
                        && jsonNode.asInt() == (int) (float) jsonNode.asInt()))
        .build();
  }

a double value is converted to float and then converted to double again, the result value is never not equal to its original value.

Issue Priority

Priority: 1 (data loss / total loss of function)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Samza Runner
  • Component: Twister2 Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions