1
votes

I have an Avro schema with some fields defined as decimal logical type. From that schema I generate classes using avro-maven-plugin (using version 1.9.0). I would like to avoid generating ByteBuffer type and use BigDecimal instead.

I found in older questions (like here) to use version 1.8.2. I tried that and then upraged to 1.9.0 and still can't get proper datatype.

Schema:

{
            "name": "TUR_ID",
            "type": [
              "null",
              "bytes"
            ],
            "default": null,
            "logicalType": "decimal",
            "precision": 16,
            "scale": 0
}

Plugin config in pom.xml:

            <plugin>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro-maven-plugin</artifactId>
                <version>${avro.version}</version>
                <executions>
                    <execution>
                        <id>schemas</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>schema</goal>
                            <goal>protocol</goal>
                            <goal>idl-protocol</goal>
                        </goals>
                        <configuration>
                            <stringType>String</stringType>
                            <enableDecimalLogicalType>true</enableDecimalLogicalType>
                            <sourceDirectory>${project.basedir}/src/main/resources/</sourceDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

The actual output is @Deprecated public java.nio.ByteBuffer TUR_ID; and I would like to get @Deprecated public java.math.BigDecimal TUR_ID;.

2
have you found a way to fix this? I'm having the same issueRumal
Nope, I stayed with the ByteBuffer...qmtq

2 Answers

1
votes
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
    <execution>
        <phase>generate-sources</phase>
        <goals>
            <goal>schema</goal>
            <goal>idl-protocol</goal>
        </goals>
        <configuration>
         <enableDecimalLogicalType>true</enableDecimalLogicalType>
        </configuration>
    </execution>
</executions>

1
votes

Try changing your schema to:

    {
        "name": "TUR_ID",
        "default": null,
        "type": ["null", {
          "type": "bytes",
          "logicalType": "decimal",
          "precision": 16,
          "scale": 0
        }]
    }