Avro架构和生成文件中的十进制数据类型支持 [英] Decimal Datatype Support in Avro Schema and Generated Files
问题描述
此问题与Avro 1.8.1版有关.
This question concerns Avro version 1.8.1.
我们的AVRO模式中有以下字段:
We have the following field in our AVRO schema:
"name" : "sale_price",
"type" : ["bytes", "null"],
"logicalType": "decimal",
"precision": 18,
"scale": 17,
如您所见,该字段的逻辑类型已定义为decimal
.
As you can see, the logicalType of the field has been defined as decimal
.
但是,当我们使用avro-maven-plugin
时,它不会在生成的Java源文件中生成正确的数据类型.
而是生成java.nio.ByteBuffer
.
您将如何在Java文件中生成正确的数据类型?
But when we use the avro-maven-plugin
, it does not generate the correct data type within the generated Java source files.
Instead it generates, java.nio.ByteBuffer
.
How would you have the correct data type generated within the Java files?
这是我们的插件配置:
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<stringType>String</stringType>
<enableDecimalLogicalType>true</enableDecimalLogicalType>
</configuration>
</plugin>
推荐答案
如果要使用BigDecimal,则需要使用1.8.2版,并将具有true
值的enableDecimalLogicalType
参数添加到pom文件中:
If you want BigDecimal you need to use version 1.8.2 and add enableDecimalLogicalType
parameter with true
value to your pom file:
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-avro-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${basedir}/generated-sources/main/java/</outputDirectory>
<enableDecimalLogicalType>true</enableDecimalLogicalType>
</configuration>
</execution>
</executions>
有关更多信息,请检查以下问题: https://issues.apache.org/jira/browse/AVRO-1847
For more info, check this issue: https://issues.apache.org/jira/browse/AVRO-1847
这篇关于Avro架构和生成文件中的十进制数据类型支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!