yunqingmoswu commented on code in PR #6655: URL: https://github.com/apache/inlong/pull/6655#discussion_r1034231078
########## inlong-sort/sort-connectors/base/src/main/java/org/apache/inlong/sort/base/dirty/sink/s3/S3DirtySink.java: ########## @@ -0,0 +1,270 @@ +/* + * 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.inlong.sort.base.dirty.sink.s3; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.apache.commons.lang3.StringUtils; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.formats.common.TimestampFormat; +import org.apache.flink.formats.json.JsonOptions.MapNullKeyMode; +import org.apache.flink.formats.json.RowDataToJsonConverters; +import org.apache.flink.formats.json.RowDataToJsonConverters.RowDataToJsonConverter; +import org.apache.flink.runtime.util.ExecutorThreadFactory; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.types.DataType; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.inlong.sort.base.dirty.DirtyData; +import org.apache.inlong.sort.base.dirty.sink.DirtySink; +import org.apache.inlong.sort.base.dirty.utils.FormatUtils; +import org.apache.inlong.sort.base.util.LabelUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.flink.table.data.RowData.createFieldGetter; + +/** + * S3 dirty sink that is used to sink dirty data to s3 + * + * @param <T> + */ +public class S3DirtySink<T> implements DirtySink<T> { + + private static final long serialVersionUID = 1L; + + private static final Logger LOG = LoggerFactory.getLogger(S3DirtySink.class); + + private final Map<String, List<String>> batchMap = new HashMap<>(); + private final S3Options s3Options; + private final AtomicLong readInNum = new AtomicLong(0); + private final AtomicLong writeOutNum = new AtomicLong(0); + private final AtomicLong errorNum = new AtomicLong(0); + private final DataType physicalRowDataType; + private final RowData.FieldGetter[] fieldGetters; + private RowDataToJsonConverter converter; + private long batchBytes = 0L; + private int size; + private transient volatile boolean closed = false; + private transient volatile boolean flushing = false; + private transient ScheduledExecutorService scheduler; + private transient ScheduledFuture<?> scheduledFuture; + private transient S3Helper s3Helper; + + public S3DirtySink(S3Options s3Options, DataType physicalRowDataType) { + this.s3Options = s3Options; + this.physicalRowDataType = physicalRowDataType; + final LogicalType[] logicalTypes = physicalRowDataType.getChildren() + .stream().map(DataType::getLogicalType).toArray(LogicalType[]::new); + this.fieldGetters = new RowData.FieldGetter[logicalTypes.length]; + for (int i = 0; i < logicalTypes.length; i++) { + fieldGetters[i] = createFieldGetter(logicalTypes[i], i); Review Comment: It is already like this. -- 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]
