dalelane opened a new pull request, #23395:
URL: https://github.com/apache/flink/pull/23395

   ## What is the purpose of the change
   
   Initially proposed in https://issues.apache.org/jira/browse/FLINK-33058 
   
   Avro supports two serialization encoding methods: binary and JSON (cf. [Avro 
docs](https://avro.apache.org/docs/1.11.1/specification/#encodings))
   
   flink-avro currently has a hard-coded assumption that Avro data is 
binary-encoded (and cannot process Avro data that has been JSON-encoded).
   
   This pull request introduces a new optional format option to flink-avro: 
`avro.encoding`
   It supports two options: 'binary' and 'json'. 
   It unset, it will default to 'binary' to maintain compatibility/consistency 
with current behaviour. 
   
   
   ## Brief change log
   
   Flink uses Avro 
`[Decoder](https://avro.apache.org/docs/1.8.2/api/java/org/apache/avro/io/Decoder.html)`
 and 
`[Encoder](https://avro.apache.org/docs/1.8.2/api/java/org/apache/avro/io/Encoder.html)`
 classes for deserializing/serializing Avro data. 
   
   However it was hard-coding the use of factory classes to only use the 
binary-encoding implementations of these abstract classes.  
(`DecoderFactory.get().binaryDecoder` and 
`EncoderFactory.get().directBinaryEncoder`)
   
   In this pull request, I'm using the value of the new `avro.encoding` option 
to create the JSON Decoder/Encoder classes where appropriate. 
   
   ## Verifying this change
   
   This change modified existing tests by re-running all of the tests that 
perform Avro serialization/deserialization to repeat the test using both binary 
and avro encoding. 
   
   This verifies that the existing binary behaviour is unaffected by the new 
option, as well as the new JSON support.
   
   I've also manually verified the new support using Flink SQL such as:
   
   ```sql
   CREATE TABLE JSONAVRORAW
   (
       ... my columns ...
   )
   WITH (
       'connector' = 'kafka',
       'topic' = 'MY.TOPIC',
       'properties.bootstrap.servers' = 'localhost:9092',
       'properties.group.id' = 'my-group',
       'scan.startup.mode' = 'earliest-offset',
       'format' = 'avro',
       'avro.encoding' = 'json'
   );
   ```
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: yes
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): yes
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? yes
     - If yes, how is the feature documented? update to the Avro format page to 
explain the new option
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to