zolyfarkas / avro

Mirror of Apache Avro
Apache License 2.0
16 stars 11 forks source link

Deleted methods with no replacement? #8

Closed gregohree closed 1 year ago

gregohree commented 2 years ago

While upgrading from version 1.9.0.11p to 1.10.0.8p, the org.apache.avro.LogicalType class appears to have methods deleted, with no mention of how to replace them. For example, #getLogicalTypeName() has been removed. However, in that case, I see in the code that the method was simply a wrapper for #getName(), so no issue there, although I would like some sort of deprecation message before it simply breaks.

There is another method that has been removed from LogicalType called #serialize() which I don't know how to resolve. We use this method and it has been removed with no deprecation. I checked the CHANGES.md document and the commit message as well, with no luck.

The change happened here. This is our usage:

    private static void writeLogicalType(final Schema schema, final JsonGenerator writer, final Object value)
            throws IOException {
        // We are - do we have a logical type defined?
        LogicalType logicalType = schema.getLogicalType();
        if (logicalType != null) {
            String typeName = logicalType.getLogicalTypeName(); // method no longer exists, will switch to "getName()"
            // Convert the logical type and write - we assume these are implicitly primitives
            if (DecimalEncoder.OPTIMIZED_JSON_DECIMAL_WRITE && "decimal".equals(typeName)) {
                writer.writeNumber((java.math.BigDecimal) value);
            } else if (DecimalEncoder.OPTIMIZED_JSON_DECIMAL_WRITE && "bigint".equals(typeName)) {
                writer.writeNumber((java.math.BigInteger) value);
            } else {
                Object serialized = logicalType.serialize(value); // method no longer exists, replacement?
                writer.writeObject(serialized);
            }
        } else {
            // Write the best value we can find
            writeJsonSimpleDataValue(value, writer);
        }
    }
zolyfarkas commented 2 years ago

In version 1.10.0.8p I have changed the LogicalType implementation to be the same(with extensions) as the official avro logical type implementation.

For historical context, the logical types implementation in this fork predates the official implementation as such it was quite different. But as avro implemented logical types, this divergence needed to be reduced to make maintenance easier.

getLogicalTypeName was eliminated, you have to now use: LogicalType.getName.

for serialize/deserialize, see org.apache.avro.Conversion

here is an example: https://github.com/zolyfarkas/avro-logical-types/blob/main/fork/src/main/java/org/spf4j/avro/logical_types/converters/BigIntegerConverter.java

hope it helps.