[ https://issues.apache.org/jira/browse/FLINK-9569?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16516912#comment-16516912 ]
ASF GitHub Bot commented on FLINK-9569: --------------------------------------- Github user sihuazhou commented on a diff in the pull request: https://github.com/apache/flink/pull/6151#discussion_r196366033 --- Diff: flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSerializer.java --- @@ -105,41 +108,54 @@ /** The currently accessing thread, set and checked on debug level only. */ private transient volatile Thread currentThread; - // ------------------------------------------------------------------------ + // ----------------------- instantiation methods -------------------------- /** * Creates a new AvroSerializer for the type indicated by the given class. - * This constructor is intended to be used with {@link SpecificRecord} or reflection serializer. - * For serializing {@link GenericData.Record} use {@link AvroSerializer#AvroSerializer(Class, Schema)} + * + * <p>This constructor is expected to be used only with {@link GenericRecord}. + * For {@link SpecificRecord} or reflection serializer use {@link AvroSerializer#forNonGeneric(Class)}. + * + * @param schema the explicit schema to use for generic records. */ - public AvroSerializer(Class<T> type) { - checkArgument(!isGenericRecord(type), - "For GenericData.Record use constructor with explicit schema."); - this.type = checkNotNull(type); - this.schemaString = null; + public static AvroSerializer<GenericRecord> forGeneric(Schema schema) { + return new AvroSerializer<>(GenericRecord.class, schema); --- End diff -- Should we do checking for schema to make sure it not null here? > Confusing construction of AvroSerializers for generic records > ------------------------------------------------------------- > > Key: FLINK-9569 > URL: https://issues.apache.org/jira/browse/FLINK-9569 > Project: Flink > Issue Type: Improvement > Components: Type Serialization System > Reporter: Tzu-Li (Gordon) Tai > Assignee: Tzu-Li (Gordon) Tai > Priority: Major > > The {{AvroSerializer}} currently has a {{AvroSerializer(Class<T> type, Schema > schema)}} public constructor when used for generic records. > This is a bit confusing, because when using the \{{AvroSerializer}}, the type > to be serialized should always be a {{GenericData.Record}} type. > We should either: > - have a separate subclass of {{AvroSerializer}}, say > {{GenericRecordAvroSerializer}} that is a {{AvroSerializer<GenericRecord>}}, > or > - follow a similar approach to the instantiation methods in the > {{AvroDeserialiationSchema}}. -- This message was sent by Atlassian JIRA (v7.6.3#76005)