hailin0 commented on code in PR #3229:
URL: 
https://github.com/apache/incubator-seatunnel/pull/3229#discussion_r1013584595


##########
seatunnel-connectors-v2/connector-cassandra/src/main/java/org/apache/seatunnel/connectors/seatunnel/cassandra/sink/CassandraSinkWriter.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.cassandra.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.utils.ExceptionUtils;
+import 
org.apache.seatunnel.connectors.seatunnel.cassandra.client.CassandraClient;
+import 
org.apache.seatunnel.connectors.seatunnel.cassandra.config.CassandraConfig;
+import 
org.apache.seatunnel.connectors.seatunnel.cassandra.util.TypeConvertUtil;
+import 
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+
+import com.datastax.oss.driver.api.core.CqlSession;
+import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
+import com.datastax.oss.driver.api.core.cql.BatchStatement;
+import com.datastax.oss.driver.api.core.cql.BoundStatement;
+import com.datastax.oss.driver.api.core.cql.ColumnDefinitions;
+import com.datastax.oss.driver.api.core.cql.PreparedStatement;
+import com.datastax.oss.driver.api.core.type.DataType;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@Slf4j
+public class CassandraSinkWriter extends AbstractSinkWriter<SeaTunnelRow, 
Void> {
+
+    private final CassandraConfig cassandraConfig;
+    private final SeaTunnelRowType seaTunnelRowType;
+    private final ColumnDefinitions tableSchema;
+    private final CqlSession session;
+    private BatchStatement batchStatement;
+    private List<BoundStatement> boundStatementList;
+    private List<CompletionStage<AsyncResultSet>> completionStages;
+    private final PreparedStatement preparedStatement;
+    private final AtomicInteger counter = new AtomicInteger(0);
+
+    public CassandraSinkWriter(CassandraConfig cassandraConfig, 
SeaTunnelRowType seaTunnelRowType, ColumnDefinitions tableSchema) {
+        this.cassandraConfig = cassandraConfig;
+        this.seaTunnelRowType = seaTunnelRowType;
+        this.tableSchema = tableSchema;
+        this.session = CassandraClient.getCqlSessionBuilder(
+            cassandraConfig.getHost(),
+            cassandraConfig.getKeyspace(),
+            cassandraConfig.getUsername(),
+            cassandraConfig.getPassword(),
+            cassandraConfig.getDatacenter()).build();
+        this.batchStatement = 
BatchStatement.builder(cassandraConfig.getBatchType()).build();
+        this.boundStatementList = new ArrayList<>();
+        this.completionStages = new ArrayList<>();
+        this.preparedStatement = session.prepare(initPrepareCQL());
+    }
+
+    @Override
+    public void write(SeaTunnelRow row) throws IOException {
+        BoundStatement boundStatement = this.preparedStatement.bind();
+        addIntoBatch(row, boundStatement);
+        if (counter.getAndIncrement() >= cassandraConfig.getBatchSize()) {

Review Comment:
   May increase the probability of missing data, but can do this first



-- 
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]

Reply via email to