TyrantLucifer commented on code in PR #4049: URL: https://github.com/apache/incubator-seatunnel/pull/4049#discussion_r1096690832
########## seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/sink/HbaseSinkWriter.java: ########## @@ -0,0 +1,189 @@ +/* + * 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.seatunnel.connectors.seatunnel.hbase.sink; + +import org.apache.seatunnel.api.table.type.SeaTunnelDataType; +import org.apache.seatunnel.api.table.type.SeaTunnelRow; +import org.apache.seatunnel.api.table.type.SeaTunnelRowType; +import org.apache.seatunnel.common.exception.CommonErrorCode; +import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter; +import org.apache.seatunnel.connectors.seatunnel.hbase.config.HbaseParameters; +import org.apache.seatunnel.connectors.seatunnel.hbase.exception.HbaseConnectorException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.BufferedMutator; +import org.apache.hadoop.hbase.client.BufferedMutatorParams; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; +import org.apache.hadoop.hbase.client.Durability; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.util.Bytes; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class HbaseSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> { + + private static final String ALL_COLUMNS = "all_columns"; + + private final Configuration hbaseConfiguration = HBaseConfiguration.create(); + + private final Connection hbaseConnection; + + private final BufferedMutator hbaseMutator; + + private final Admin hbaseAdmin; + + private final SeaTunnelRowType seaTunnelRowType; + + private final HbaseParameters hbaseParameters; + + private final List<Integer> rowkeyColumnIndexes; + + private final int versionColumnIndex; + + private String defaultFamilyName = "value"; + + public HbaseSinkWriter(SeaTunnelRowType seaTunnelRowType, + HbaseParameters hbaseParameters, + List<Integer> rowkeyColumnIndexes, + int versionColumnIndex) throws IOException { + this.seaTunnelRowType = seaTunnelRowType; + this.hbaseParameters = hbaseParameters; + this.rowkeyColumnIndexes = rowkeyColumnIndexes; + this.versionColumnIndex = versionColumnIndex; + + if (hbaseParameters.getFamilyNames().size() == 1) { + defaultFamilyName = hbaseParameters.getFamilyNames().getOrDefault(ALL_COLUMNS, "value"); + } + + // initialize hbase configuration + hbaseConfiguration.set("hbase.zookeeper.quorum", hbaseParameters.getZookeeperQuorum()); + if (hbaseParameters.getHbaseExtraConfig() != null) { + hbaseParameters.getHbaseExtraConfig().forEach(hbaseConfiguration::set); + } + // initialize hbase connection + hbaseConnection = ConnectionFactory.createConnection(hbaseConfiguration); + // initialize hbase admin + hbaseAdmin = hbaseConnection.getAdmin(); Review Comment: Thank you for your review. This parameter will be used to support save mode feature of sink connectors. But this feature is in the process of development. You can refer to https://github.com/apache/incubator-seatunnel/pull/4022 get more details. If you think at this stage we need remove useless parameters, I will delete it. -- 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]
