LeonBein commented on a change in pull request #15109: URL: https://github.com/apache/flink/pull/15109#discussion_r592568727
########## File path: flink-connectors/flink-connector-hbase/src/main/java/org/apache/flink/connector/hbase/source/enumerator/HBaseSplitEnumerator.java ########## @@ -0,0 +1,158 @@ +/* + * 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.connector.hbase.source.enumerator; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.connector.source.SplitEnumerator; +import org.apache.flink.api.connector.source.SplitEnumeratorContext; +import org.apache.flink.connector.hbase.source.split.HBaseSourceSplit; +import org.apache.flink.connector.hbase.util.HBaseConfigurationUtil; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; + +import javax.annotation.Nullable; + +import java.io.IOException; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Queue; + +/** The enumerator class for Hbase source. */ +@Internal +public class HBaseSplitEnumerator + implements SplitEnumerator<HBaseSourceSplit, Collection<HBaseSourceSplit>> { + private final SplitEnumeratorContext<HBaseSourceSplit> context; + private final Queue<HBaseSourceSplit> remainingSplits; + private final String table; + private final byte[] serializedConfig; + + public HBaseSplitEnumerator( + SplitEnumeratorContext<HBaseSourceSplit> context, + byte[] serializedConfig, + String table) { + this.context = context; + this.remainingSplits = new ArrayDeque<>(); + this.table = table; + this.serializedConfig = serializedConfig; + } + + @Override + public void start() { + Configuration hbaseConfiguration = + HBaseConfigurationUtil.deserializeConfiguration(this.serializedConfig, null); + try (Connection connection = ConnectionFactory.createConnection(hbaseConfiguration); + Admin admin = connection.getAdmin()) { + ColumnFamilyDescriptor[] colFamDes = + admin.getDescriptor(TableName.valueOf(this.table)).getColumnFamilies(); + List<HBaseSourceSplit> splits = new ArrayList<>(); + + int parallelism = context.currentParallelism(); + int colFamilies = colFamDes.length; + + if (parallelism > colFamilies) { + for (ColumnFamilyDescriptor colFamDe : colFamDes) { + splits.add( + new HBaseSourceSplit( + // TODO find better pattern than 1234 + String.format("1234%s", new String(colFamDe.getName())), Review comment: dcda880d1174aad22c7fbb6fb553f7579a860bd6 ---------------------------------------------------------------- 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]
