dingxin-tech commented on code in PR #3254:
URL: https://github.com/apache/flink-cdc/pull/3254#discussion_r1845910112


##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-maxcompute/src/main/java/org/apache/flink/cdc/connectors/maxcompute/utils/MaxComputeUtils.java:
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.cdc.connectors.maxcompute.utils;
+
+import org.apache.flink.cdc.common.event.TableId;
+import org.apache.flink.cdc.common.utils.StringUtils;
+import org.apache.flink.cdc.connectors.maxcompute.common.Constant;
+import org.apache.flink.cdc.connectors.maxcompute.common.SessionIdentifier;
+import 
org.apache.flink.cdc.connectors.maxcompute.common.UncheckedOdpsException;
+import org.apache.flink.cdc.connectors.maxcompute.options.MaxComputeOptions;
+import 
org.apache.flink.cdc.connectors.maxcompute.options.MaxComputeWriteOptions;
+
+import com.aliyun.odps.Column;
+import com.aliyun.odps.Odps;
+import com.aliyun.odps.OdpsException;
+import com.aliyun.odps.PartitionSpec;
+import com.aliyun.odps.Table;
+import com.aliyun.odps.TableSchema;
+import com.aliyun.odps.account.Account;
+import com.aliyun.odps.account.AliyunAccount;
+import com.aliyun.odps.account.StsAccount;
+import com.aliyun.odps.tunnel.Configuration;
+import com.aliyun.odps.tunnel.TableTunnel;
+import com.aliyun.odps.tunnel.io.CompressOption;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+/** common utils use for maxcompute connector. */
+public class MaxComputeUtils {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(MaxComputeUtils.class);
+
+    public static Odps getOdps(MaxComputeOptions maxComputeOptions) {
+        Account account;
+        if 
(StringUtils.isNullOrWhitespaceOnly(maxComputeOptions.getStsToken())) {
+            account =
+                    new AliyunAccount(
+                            maxComputeOptions.getAccessId(), 
maxComputeOptions.getAccessKey());
+        } else {
+            account =
+                    new StsAccount(
+                            maxComputeOptions.getAccessId(),
+                            maxComputeOptions.getAccessKey(),
+                            maxComputeOptions.getStsToken());
+        }
+        Odps odps = new Odps(account);
+        odps.setEndpoint(maxComputeOptions.getEndpoint());
+        odps.setTunnelEndpoint(maxComputeOptions.getTunnelEndpoint());
+        odps.setDefaultProject(maxComputeOptions.getProject());
+        odps.setUserAgent("Flink CDC");
+        return odps;
+    }
+
+    public static TableTunnel getTunnel(
+            MaxComputeOptions maxComputeOptions, MaxComputeWriteOptions 
writeOptions) {
+        Odps odps = getOdps(maxComputeOptions);
+        Configuration configuration =
+                Configuration.builder(odps)
+                        .withRetryLogger(RetryUtils.getRetryLogger())
+                        .withRetryPolicy(new 
RetryUtils.FlinkDefaultRetryPolicy())
+                        .withCompressOptions(
+                                MaxComputeUtils.compressOptionOf(
+                                        writeOptions.getCompressAlgorithm()))
+                        .withQuotaName(maxComputeOptions.getQuotaName())
+                        .build();
+        TableTunnel tunnel = new TableTunnel(odps, configuration);
+        if 
(!StringUtils.isNullOrWhitespaceOnly(maxComputeOptions.getTunnelEndpoint())) {
+            tunnel.setEndpoint(maxComputeOptions.getTunnelEndpoint());
+        }
+        return tunnel;
+    }
+
+    public static Table getTable(MaxComputeOptions maxComputeOptions, TableId 
tableId) {
+        Odps odps = getOdps(maxComputeOptions);
+        if (maxComputeOptions.isSupportSchema()) {
+            return odps.tables()
+                    .get(
+                            maxComputeOptions.getProject(),
+                            tableId.getNamespace(),
+                            tableId.getTableName());
+        } else {
+            return odps.tables().get(tableId.getTableName());
+        }
+    }
+
+    public static TableSchema getTableSchema(MaxComputeOptions options, 
TableId tableId) {
+        Odps odps = getOdps(options);
+        if (options.isSupportSchema()) {
+            return odps.tables()
+                    .get(options.getProject(), tableId.getNamespace(), 
tableId.getTableName())
+                    .getSchema();
+        } else {
+            return odps.tables().get(options.getProject(), 
tableId.getTableName()).getSchema();
+        }
+    }
+
+    public static boolean supportSchema(MaxComputeOptions maxComputeOptions) {
+        Odps odps = getOdps(maxComputeOptions);
+        try {
+            boolean flag =
+                    Boolean.parseBoolean(
+                            
odps.projects().get().getProperty(Constant.SCHEMA_ENABLE_FLAG));
+            LOG.info("project {} is support schema: {}", 
maxComputeOptions.getProject(), flag);
+            return flag;
+        } catch (OdpsException e) {
+            throw new UncheckedOdpsException(e);
+        }
+    }
+
+    public static CompressOption compressOptionOf(String compressAlgo) {
+        CompressOption.CompressAlgorithm compressAlgorithm;
+        switch (compressAlgo) {

Review Comment:
   Perhaps using zlib and lz4 instead of odps_zlib and odps_lz4_frame would be 
clearer for users?
   
   



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