avro-random-generator icon indicating copy to clipboard operation
avro-random-generator copied to clipboard

Failure when generating array of type long

Open ikstewa opened this issue 1 year ago • 1 comments

When attempting to generate an array of type long using 'options' the generations fails with the following error:

java.lang.RuntimeException: Invalid option for array schema: type org.apache.avro.generic.GenericData$Array, value '[1, 2, 3]'
    at io.confluent.avro.random.generator.Generator.parseOptions(Generator.java:505)
    at io.confluent.avro.random.generator.Generator.generateOption(Generator.java:612)
    at io.confluent.avro.random.generator.Generator.generateObject(Generator.java:373)
    at io.confluent.avro.random.generator.Generator.generateRecord(Generator.java:1345)
    at io.confluent.avro.random.generator.Generator.generateObject(Generator.java:402)
    at io.confluent.avro.random.generator.Generator.generate(Generator.java:367)

Example schema:

{
  "namespace": "ksql",
  "name": "testobj",
  "type": "record",
  "fields": [
    {
      "name": "my_long_array",
      "type": {
        "type": "array",
        "items": "long",
        "arg.properties": {
          "options": [
            [ 1, 2, 3 ]
          ]
        }
      }
    }
  ]
}

ikstewa avatar Sep 09 '23 20:09 ikstewa

I think this is because wrapOption should be recursive for complex types but isn't right now. So, in this case, the values of the options array get parsed as a Java Collection<Integer>, which doesn't match the expected type for the schema (should be a Collection<Long>).

C0urante avatar Sep 10 '23 17:09 C0urante