afedulov commented on code in PR #19588: URL: https://github.com/apache/flink/pull/19588#discussion_r863717635
########## flink-core/src/main/java/org/apache/flink/api/connector/source/lib/GeneratorSource.java: ########## @@ -0,0 +1,245 @@ +/* + * 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.api.connector.source.lib; + +import org.apache.flink.annotation.Public; +import org.apache.flink.api.common.functions.MapFunction; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.connector.source.Boundedness; +import org.apache.flink.api.connector.source.Source; +import org.apache.flink.api.connector.source.SourceReader; +import org.apache.flink.api.connector.source.SourceReaderContext; +import org.apache.flink.api.connector.source.SplitEnumerator; +import org.apache.flink.api.connector.source.SplitEnumeratorContext; +import org.apache.flink.api.connector.source.lib.util.IteratorSourceEnumerator; +import org.apache.flink.api.connector.source.lib.util.IteratorSourceReader; +import org.apache.flink.api.java.typeutils.ResultTypeQueryable; +import org.apache.flink.core.io.SimpleVersionedSerializer; +import org.apache.flink.core.memory.DataInputDeserializer; +import org.apache.flink.core.memory.DataInputView; +import org.apache.flink.core.memory.DataOutputSerializer; +import org.apache.flink.core.memory.DataOutputView; +import org.apache.flink.util.NumberSequenceIterator; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static org.apache.flink.util.InstantiationUtil.serializeObject; +import static org.apache.flink.util.Preconditions.checkArgument; +import static org.apache.flink.util.Preconditions.checkNotNull; + +@Public +public class GeneratorSource<OUT> + implements Source<OUT, NumberSequenceSplit<OUT>, Collection<NumberSequenceSplit<OUT>>>, + ResultTypeQueryable<OUT> { + + private static final long serialVersionUID = 1L; + + /** The end number in the sequence, inclusive. */ + private final long count; + + private final TypeInformation<OUT> typeInfo; + + public final MapFunction<Long, OUT> mapFunction; + + public final Boundedness boundedness; + + public long getCount() { + return count; + } + + private GeneratorSource( + MapFunction<Long, OUT> mapFunction, long count, TypeInformation<OUT> typeInfo) { + this.mapFunction = checkNotNull(mapFunction); + checkArgument(count > 0, "count must be > 0"); + this.count = count; + this.typeInfo = typeInfo; + boundedness = + count == Long.MAX_VALUE ? Boundedness.BOUNDED : Boundedness.CONTINUOUS_UNBOUNDED; + } + + public static <OUT> GeneratorSource<OUT> from( + MapFunction<Long, OUT> mapFunction, long count, TypeInformation<OUT> typeInfo) { Review Comment: It was Arvid's proposition, since it has to be serializable. -- 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]
