All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.ververica.connectors.odps.source.BaseODPSStreamSource Maven / Gradle / Ivy

There is a newer version: 1.17-vvr-8.0.8
Show newest version
/*
 * 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 com.alibaba.ververica.connectors.odps.source;

import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.core.io.GenericInputSplit;
import org.apache.flink.core.io.InputSplit;
import org.apache.flink.table.data.RowData;
import org.apache.flink.util.Preconditions;

import com.alibaba.ververica.connectors.common.source.AbstractParallelSource;
import com.alibaba.ververica.connectors.common.source.SourceUtils;
import com.alibaba.ververica.connectors.odps.OdpsConf;
import com.alibaba.ververica.connectors.odps.schema.ODPSColumn;
import com.alibaba.ververica.connectors.odps.util.OdpsUtils;
import com.aliyun.odps.tunnel.TableTunnel;

import java.io.IOException;
import java.util.List;

/**
 * Base class for odps source function.
 */
public abstract class BaseODPSStreamSource extends AbstractParallelSource> {

	/** columns to prune. */
	protected ODPSColumn[] selectedColumns;

	protected TypeInformation rowDataTypeInfo;

	/** odps config. */
	protected final OdpsConf odpsConf;

	protected transient TableTunnel tunnel;

	protected transient int maxParallelism;

	protected final long retryTimes;

	protected final String tableName;

	protected final long sleepTimeMs;

	public BaseODPSStreamSource(
		OdpsConf odpsConf,
		String tableName,
		ODPSColumn[] selectedColumns,
		TypeInformation rowDataTypeInfo,
		long sleepTimeMs,
		long retryTimes) {
		Preconditions.checkNotNull(odpsConf, "ODPS configuration can not be null.");
		this.odpsConf = odpsConf;
		this.tableName = tableName;
		this.selectedColumns = selectedColumns;
		this.rowDataTypeInfo = rowDataTypeInfo;
		setInitInputSplitInMaster(false);
		this.sleepTimeMs = sleepTimeMs;
		this.retryTimes = retryTimes;
	}

	@Override
	public void initOperator(Configuration config) throws IOException {
		tunnel = OdpsUtils.createTableTunnel(odpsConf);
	}

	@Override
	public List getPartitionList() throws Exception {
		// TODO to be implemented.
		return null;
	}

	@Override
	public InputSplit[] createInputSplitsForCurrentSubTask(int numberOfParallelSubTasks, int indexOfThisSubTask) throws IOException {
		maxParallelism = getRuntimeContext().getNumberOfParallelSubtasks();

		List assignedSplits =
			SourceUtils.modAssign(this.toString(), numberOfParallelSubTasks, indexOfThisSubTask, maxParallelism);

		InputSplit[] result = new InputSplit[assignedSplits.size()];

		for (int i = 0; i < result.length; i++) {
			result[i] = new GenericInputSplit(assignedSplits.get(i), maxParallelism);
		}
		return result;
	}

	@Override
	public TypeInformation getProducedType() {
		return rowDataTypeInfo;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy