ruanwenjun commented on code in PR #5084:
URL: https://github.com/apache/seatunnel/pull/5084#discussion_r1382733547
##########
seatunnel-dist/release-docs/LICENSE:
##########
@@ -220,7 +220,8 @@ The text of each license is the standard Apache 2.0 license.
(Apache License 2.0) aircompressor (io.airlift:aircompressor:0.10 -
http://github.com/airlift/aircompressor)
(Apache License, Version 2.0) Apache Yetus - Audience Annotations
(org.apache.yetus:audience-annotations:0.11.0 -
https://yetus.apache.org/audience-annotations)
(The Apache Software License, Version 2.0) Apache Avro
(org.apache.avro:avro:1.8.2 - http://avro.apache.org)
- (Apache License, Version 2.0) Apache Commons Codec
(commons-codec:commons-codec:1.13 -
https://commons.apache.org/proper/commons-codec/)
+ (The Apache Software License, Version 2.0) Apache Avro
(org.apache.avro:avro:1.11.1 - http://avro.apache.org)
Review Comment:
Can we use one Avro version here? I find there is already exist `1.8.2`
##########
seatunnel-formats/seatunnel-format-avro/src/main/java/org/apache/seatunnel/format/avro/AvroSerializationSchema.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.format.avro;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.format.avro.exception.AvroFormatErrorCode;
+import org.apache.seatunnel.format.avro.exception.SeaTunnelAvroFormatException;
+
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.io.BinaryEncoder;
+import org.apache.avro.io.DatumWriter;
+import org.apache.avro.io.EncoderFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public class AvroSerializationSchema implements SerializationSchema {
+
+ private static final long serialVersionUID = 4438784443025715370L;
+
+ private final ByteArrayOutputStream out;
+ private final BinaryEncoder encoder;
+ private final RowToAvroConverter converter;
+ private final DatumWriter<GenericRecord> writer;
+
+ public AvroSerializationSchema(SeaTunnelRowType rowType) {
+ this.out = new ByteArrayOutputStream();
+ this.encoder = EncoderFactory.get().binaryEncoder(out, null);
+ this.converter = new RowToAvroConverter(rowType);
+ this.writer = this.converter.getWriter();
+ }
+
+ @Override
+ public byte[] serialize(SeaTunnelRow element) {
+ GenericRecord record = converter.convertRowToGenericRecord(element);
+ try {
+ out.reset();
+ writer.write(record, encoder);
+ encoder.flush();
+ return out.toByteArray();
+ } catch (IOException e) {
+ throw new SeaTunnelAvroFormatException(
+ AvroFormatErrorCode.SERIALIZATION_ERROR, e.toString());
Review Comment:
```suggestion
throw new SeaTunnelAvroFormatException(
AvroFormatErrorCode.SERIALIZATION_ERROR, e);
```
Do we need to throw the exception stack here?
--
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]