JingsongLi commented on a change in pull request #13915:
URL: https://github.com/apache/flink/pull/13915#discussion_r517235323



##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveSourceSplitSerializer.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.flink.connectors.hive;
+
+import org.apache.flink.connector.file.src.FileSourceSplit;
+import org.apache.flink.connector.file.src.FileSourceSplitSerializer;
+import org.apache.flink.connectors.hive.read.HiveSourceSplit;
+import org.apache.flink.core.io.SimpleVersionedSerializer;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/**
+ * SerDe for {@link HiveSourceSplit}.
+ */
+public class HiveSourceSplitSerializer implements 
SimpleVersionedSerializer<HiveSourceSplit> {
+
+       private static final int VERSION = 1;
+
+       public static final HiveSourceSplitSerializer INSTANCE = new 
HiveSourceSplitSerializer();
+
+       private HiveSourceSplitSerializer() {
+       }
+
+       @Override
+       public int getVersion() {
+               return VERSION;
+       }
+
+       @Override
+       public byte[] serialize(HiveSourceSplit split) throws IOException {
+               checkArgument(split.getClass() == HiveSourceSplit.class, 
"Cannot serialize subclasses of HiveSourceSplit");
+
+               ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+               try (ObjectOutputStream outputStream = new 
ObjectOutputStream(byteArrayOutputStream)) {
+                       serialize(outputStream, split);
+               }
+               return byteArrayOutputStream.toByteArray();
+       }
+
+       @Override
+       public HiveSourceSplit deserialize(int version, byte[] serialized) 
throws IOException {
+               if (version == 1) {
+                       try (ObjectInputStream inputStream = new 
ObjectInputStream(new ByteArrayInputStream(serialized))) {
+                               return deserializeV1(inputStream);
+                       }
+               } else {
+                       throw new IOException("Unknown version: " + version);
+               }
+       }
+
+       private void serialize(ObjectOutputStream outputStream, HiveSourceSplit 
split) throws IOException {
+               byte[] superBytes = 
FileSourceSplitSerializer.INSTANCE.serialize(new FileSourceSplit(

Review comment:
       > but FileSourceSplitSerializer doesn't accept sub-classes.
   
   Oh, that is.




----------------------------------------------------------------
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.

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


Reply via email to