Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

ISSUE-20092: [Bug] Pulsar client AUTO_CONSUME "double" as "BigDecimal" in JSON schemas #5720

Open
2 tasks done
sijie opened this issue Apr 14, 2023 · 0 comments
Open
2 tasks done
Labels

Comments

@sijie
Copy link
Member

sijie commented Apr 14, 2023

Original Issue: apache#20092


Search before asking

  • I searched in the issues and found nothing similar.

Version

Pulsar client 2.10.3, 2.10.2, 2.10.1. Please note the behavior was correct with 2.8.3 and 2.10.0 and regressed starting with 2.10.1

Minimal reproduce step

Run the below program to create a topic with a JSON schema that has an optional double field. Please note the behavior is correct if the field is not optional

public static void main(String[] args) throws PulsarClientException {
        final PulsarClient client = PulsarClient.builder()
                //.serviceUrl("pulsar://localhost:65093")
                .serviceUrl("pulsar://localhost:6650")
                .build();

        RecordSchemaBuilder schemaBuilder = SchemaBuilder.record("myrecord");
        schemaBuilder.field("xdouble").type(SchemaType.DOUBLE).optional();
        SchemaInfo schemaInfo = schemaBuilder.build(SchemaType.JSON);
        GenericSchema<GenericRecord> schema = Schema.generic(schemaInfo);
        GenericRecordBuilder builder = schema.newRecordBuilder();
        builder.set("xdouble", 1.0d);
        GenericRecord record = builder.build();

        Producer<GenericRecord> producer = client.newProducer(schema)
                .topic("persistent://public/default/json-topic3")
                .create();
        producer.send(record);

        Consumer<GenericRecord> consumer = client.newConsumer(Schema.AUTO_CONSUME())
                .topic("persistent://public/default/json-topic3")
                .subscriptionName("my-subscription2")
                .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
                .subscribe();

        var message = consumer.receive();
        var value = ((JsonNode)message.getValue().getNativeObject()).get("xdouble").numberValue();
        assertTrue("expected double, got " + value.getClass() , value instanceof Double);
        //consumer.acknowledge(message);

        client.close();
    }

What did you expect to see?

The assertion should pass

What did you see instead?

Exception in thread "main" java.lang.AssertionError: expected double, got class java.math.BigDecimal
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.example.SimpleConsumer.main(SimpleConsumer.java:63)

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@sijie sijie added the type/bug label Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant