Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
coderzc opened this issue Jun 14, 2022 · 6 comments
Closed

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

coderzc opened this issue Jun 14, 2022 · 6 comments
Labels

Comments

@coderzc
Copy link
Member

coderzc commented Jun 14, 2022

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.

@eolivelli
Copy link
Contributor

how does this work with other Schema types ?

@coderzc
Copy link
Member Author

coderzc commented Jun 15, 2022

how does this work with other Schema types ?

@eolivelli it only work with the avro schema

@coderzc
Copy link
Member Author

coderzc commented Jun 16, 2022

@eolivelli Do you have any questions about this proposal?

@eolivelli
Copy link
Contributor

LGTM thanks

@coderzc
Copy link
Member Author

coderzc commented Jun 17, 2022

@congbobo184
Copy link
Contributor

congbobo184 commented Jun 21, 2022 via email

@coderzc coderzc closed this as completed Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 participants