JingsongLi commented on a change in pull request #12004: URL: https://github.com/apache/flink/pull/12004#discussion_r422752473
########## File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/read/TimestampedHiveInputSplit.java ########## @@ -0,0 +1,232 @@ +/* + * 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.read; + +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInfoFactory; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeutils.SimpleTypeSerializerSnapshot; +import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot; +import org.apache.flink.api.common.typeutils.base.TypeSerializerSingleton; +import org.apache.flink.api.java.typeutils.runtime.DataInputViewStream; +import org.apache.flink.api.java.typeutils.runtime.DataOutputViewStream; +import org.apache.flink.core.memory.DataInputView; +import org.apache.flink.core.memory.DataOutputView; +import org.apache.flink.streaming.api.functions.source.TimestampedInputSplit; +import org.apache.flink.util.FlinkRuntimeException; +import org.apache.flink.util.InstantiationUtil; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Type; +import java.util.Map; +import java.util.Objects; + +/** + * A {@link HiveTableInputSplit} with {@link TimestampedInputSplit}. + * Kryo serializer can not deal with hadoop split, need specific type information factory. + */ +@TypeInfo(TimestampedHiveInputSplit.SplitTypeInfoFactory.class) +public class TimestampedHiveInputSplit extends HiveTableInputSplit implements TimestampedInputSplit { + + private static final long serialVersionUID = 1L; + + /** The modification time of the file this split belongs to. */ + private final long modificationTime; + + /** + * The state of the split. This information is used when + * restoring from a checkpoint and allows to resume reading the + * underlying file from the point we left off. + * */ + private Serializable splitState; + + public TimestampedHiveInputSplit( + long modificationTime, + HiveTableInputSplit split) { + super( + split.getSplitNumber(), + split.getHadoopInputSplit(), + split.getJobConf(), + split.getHiveTablePartition()); + this.modificationTime = modificationTime; + } + + @Override + public void setSplitState(Serializable state) { + this.splitState = state; + } + + @Override + public Serializable getSplitState() { + return this.splitState; + } + + @Override + public long getModificationTime() { + return modificationTime; + } + + @Override + public int compareTo(TimestampedInputSplit o) { + TimestampedHiveInputSplit split = (TimestampedHiveInputSplit) o; + int modTimeComp = Long.compare(this.modificationTime, split.modificationTime); + if (modTimeComp != 0L) { + return modTimeComp; + } + + int pathComp = this.hiveTablePartition.getStorageDescriptor().compareTo( Review comment: It is a short cut for comparing. If the sd is same, `SplitNumber` must be different. ---------------------------------------------------------------- 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: us...@infra.apache.org