Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PIP-177: Add the classLoader field for SchemaDefinition #16058

@coderzc

Description

@coderzc

Mailing list thread: https://lists.apache.org/thread/ydslz3h8ymjjwm5ng02kwszmc5j5hy30

Motivation

Now, don‘t register logical type conversions when use SchemaDefinition.<T>builder().withJsonDef() to create the schema, beacase it without classLoader param. (e.g: #15899)

See:

public AvroReader(Schema writerSchema, Schema readerSchema, ClassLoader classLoader,
boolean jsr310ConversionEnabled) {
this.schema = readerSchema;
if (classLoader != null) {
ReflectData reflectData = new ReflectData(classLoader);
AvroSchema.addLogicalTypeConversions(reflectData, jsr310ConversionEnabled);
this.reader = new ReflectDatumReader<>(writerSchema, readerSchema, reflectData);
} else {
this.reader = new ReflectDatumReader<>(writerSchema, readerSchema);
}
}

We can add the classLoader field for SchemaDefinition, user can manually pass a classLoader to register logical type conversions

Goal

This proposes to add the classLoader field for SchemaDefinition. When using SchemaDefinition.<T>builder().withJsonDef() to create the schema it must manually specify a classLoader otherwise, the converter will not work.

The priority of the classLoader field will be higher than by the pojoClass.getClassLoader().

API Changes

public class SchemaDefinitionBuilder {
    //....

    /**
     * Set schema of pojo classLoader.
     *
     * @param classLoader pojo classLoader
     *
     * @return schema definition builder
     */
    SchemaDefinitionBuilder<T> withClassLoader(ClassLoader classLoader);
}
public class SchemaDefinition {
    //....

    /**
     * Get pojo classLoader.
     *
     * @return pojo schema
     */
    ClassLoader getClassLoader();
}

Implementation

Add the classloader field for SchemaDefinition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions