You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/08/25 13:11:13 UTC

[GitHub] [incubator-seatunnel] chessplay opened a new pull request, #2529: [Feature][File connector] Support datahub sink

chessplay opened a new pull request, #2529:
URL: https://github.com/apache/incubator-seatunnel/pull/2529

   ** Support datahub sink #1946 
   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [x] Code changed are covered with tests, or it does not need tests for reason:
   * [x] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [x] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] CalvinKirs commented on a diff in pull request #2529: [Feature][File connector] Support datahub sink

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on code in PR #2529:
URL: https://github.com/apache/incubator-seatunnel/pull/2529#discussion_r955076664


##########
seatunnel-connectors-v2/connector-datahub/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DataHubWriter.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+
+import com.aliyun.datahub.client.DatahubClient;
+import com.aliyun.datahub.client.DatahubClientBuilder;
+import com.aliyun.datahub.client.auth.AliyunAccount;
+import com.aliyun.datahub.client.common.DatahubConfig;
+import com.aliyun.datahub.client.exception.DatahubClientException;
+import com.aliyun.datahub.client.http.HttpConfig;
+import com.aliyun.datahub.client.model.PutRecordsResult;
+import com.aliyun.datahub.client.model.RecordEntry;
+import com.aliyun.datahub.client.model.RecordSchema;
+import com.aliyun.datahub.client.model.TupleRecordData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Datahub write class
+ */
+public class DataHubWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DataHubWriter.class);
+    private DatahubClient dataHubClient;
+    private String project;
+    private String topic;
+    private SeaTunnelRowType seaTunnelRowType;
+    private static final int DATAHUB_CONNECT_MAX_TIMEOUT = 10000;
+    public DataHubWriter(SeaTunnelRowType seaTunnelRowType, String endpoint, String accessId, String accessKey, String project, String topic) {
+        this.dataHubClient = DatahubClientBuilder.newBuilder()
+                .setDatahubConfig(new DatahubConfig(endpoint,
+                                new AliyunAccount(accessId, accessKey), true))
+                .setHttpConfig(new HttpConfig().setCompressType(HttpConfig.CompressType.LZ4)
+                .setConnTimeout(DATAHUB_CONNECT_MAX_TIMEOUT))
+                .build();
+        this.seaTunnelRowType = seaTunnelRowType;
+        this.project = project;
+        this.topic = topic;
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) throws IOException {
+        String[] fieldNames = seaTunnelRowType.getFieldNames();
+        Object[] fields = element.getFields();
+        List<RecordEntry> recordEntries = new ArrayList<>();
+        RecordSchema recordSchema = dataHubClient.getTopic(project, topic).getRecordSchema();
+        for (int i = 0; i < fieldNames.length; i++) {
+            TupleRecordData data = new TupleRecordData(recordSchema);
+            data.setField(fieldNames[i], fields[i]);
+            RecordEntry recordEntry = new RecordEntry();
+            recordEntry.setRecordData(data);
+            recordEntries.add(recordEntry);
+        }
+        try {
+            PutRecordsResult result = dataHubClient.putRecords(project, topic, recordEntries);
+            LOG.info("putRecordResult:" + result.toString());
+        }  catch (DatahubClientException e) {
+            LOG.error("requestId:" + e.getRequestId() + "\tmessage:" + e.getErrorMessage());
+        }
+    }
+
+    @Override
+    public void close() throws IOException {
+

Review Comment:
   Does the Client need to be closed?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #2529: [Feature][File connector] Support datahub sink

Posted by GitBox <gi...@apache.org>.
hailin0 commented on code in PR #2529:
URL: https://github.com/apache/incubator-seatunnel/pull/2529#discussion_r955572793


##########
seatunnel-examples/seatunnel-flink-connector-v2-example/pom.xml:
##########
@@ -76,6 +76,11 @@
             <artifactId>connector-dingtalk</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>connector-datahub</artifactId>
+            <version>${project.version}</version>
+        </dependency>

Review Comment:
   Would you like to add an `DataHub` example?
   
   reference
   https://github.com/apache/incubator-seatunnel/tree/dev/seatunnel-examples/seatunnel-flink-connector-v2-example/src/main/java/org/apache/seatunnel/example/flink/v2
   https://github.com/apache/incubator-seatunnel/tree/dev/seatunnel-examples/seatunnel-spark-connector-v2-example



##########
plugin-mapping.properties:
##########
@@ -111,7 +111,6 @@ seatunnel.source.HdfsFile = connector-file-hadoop
 seatunnel.sink.HdfsFile = connector-file-hadoop
 seatunnel.source.LocalFile = connector-file-local
 seatunnel.sink.LocalFile = connector-file-local
-seatunnel.source.OssFile = connector-file-oss

Review Comment:
   Why remove?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] CalvinKirs commented on a diff in pull request #2529: [Feature][File connector] Support datahub sink

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on code in PR #2529:
URL: https://github.com/apache/incubator-seatunnel/pull/2529#discussion_r955071489


##########
seatunnel-connectors-v2/connector-datahub/pom.xml:
##########
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>seatunnel-connectors-v2</artifactId>
+    <groupId>org.apache.seatunnel</groupId>
+    <version>${revision}</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>connector-datahub</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.seatunnel</groupId>
+      <artifactId>connector-common</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.aliyun.datahub</groupId>
+      <artifactId>aliyun-sdk-datahub</artifactId>
+      <version>2.19.0-public</version>
+    </dependency>

Review Comment:
   Hi, Version should be managed uniformly in the root pom



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] chessplay closed pull request #2529: [Feature][File connector] Support datahub sink

Posted by GitBox <gi...@apache.org>.
chessplay closed pull request #2529: [Feature][File connector] Support datahub sink 
URL: https://github.com/apache/incubator-seatunnel/pull/2529


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] CalvinKirs commented on a diff in pull request #2529: [Feature][File connector] Support datahub sink

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on code in PR #2529:
URL: https://github.com/apache/incubator-seatunnel/pull/2529#discussion_r955074524


##########
seatunnel-connectors-v2/connector-datahub/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DataHubWriter.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+
+import com.aliyun.datahub.client.DatahubClient;
+import com.aliyun.datahub.client.DatahubClientBuilder;
+import com.aliyun.datahub.client.auth.AliyunAccount;
+import com.aliyun.datahub.client.common.DatahubConfig;
+import com.aliyun.datahub.client.exception.DatahubClientException;
+import com.aliyun.datahub.client.http.HttpConfig;
+import com.aliyun.datahub.client.model.PutRecordsResult;
+import com.aliyun.datahub.client.model.RecordEntry;
+import com.aliyun.datahub.client.model.RecordSchema;
+import com.aliyun.datahub.client.model.TupleRecordData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Datahub write class
+ */
+public class DataHubWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DataHubWriter.class);
+    private DatahubClient dataHubClient;
+    private String project;
+    private String topic;
+    private SeaTunnelRowType seaTunnelRowType;
+    private static final int DATAHUB_CONNECT_MAX_TIMEOUT = 10000;

Review Comment:
   Is it possible to give this parameter to the user as an optional configuration?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] CalvinKirs commented on a diff in pull request #2529: [Feature][File connector] Support datahub sink

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on code in PR #2529:
URL: https://github.com/apache/incubator-seatunnel/pull/2529#discussion_r955082419


##########
seatunnel-connectors-v2/connector-datahub/src/main/java/org/apache/seatunnel/connectors/seatunnel/sink/DataHubWriter.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+
+import com.aliyun.datahub.client.DatahubClient;
+import com.aliyun.datahub.client.DatahubClientBuilder;
+import com.aliyun.datahub.client.auth.AliyunAccount;
+import com.aliyun.datahub.client.common.DatahubConfig;
+import com.aliyun.datahub.client.exception.DatahubClientException;
+import com.aliyun.datahub.client.http.HttpConfig;
+import com.aliyun.datahub.client.model.PutRecordsResult;
+import com.aliyun.datahub.client.model.RecordEntry;
+import com.aliyun.datahub.client.model.RecordSchema;
+import com.aliyun.datahub.client.model.TupleRecordData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Datahub write class
+ */
+public class DataHubWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DataHubWriter.class);
+    private DatahubClient dataHubClient;
+    private String project;
+    private String topic;
+    private SeaTunnelRowType seaTunnelRowType;
+    private static final int DATAHUB_CONNECT_MAX_TIMEOUT = 10000;
+    public DataHubWriter(SeaTunnelRowType seaTunnelRowType, String endpoint, String accessId, String accessKey, String project, String topic) {
+        this.dataHubClient = DatahubClientBuilder.newBuilder()
+                .setDatahubConfig(new DatahubConfig(endpoint,
+                                new AliyunAccount(accessId, accessKey), true))
+                .setHttpConfig(new HttpConfig().setCompressType(HttpConfig.CompressType.LZ4)
+                .setConnTimeout(DATAHUB_CONNECT_MAX_TIMEOUT))
+                .build();
+        this.seaTunnelRowType = seaTunnelRowType;
+        this.project = project;
+        this.topic = topic;
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) throws IOException {
+        String[] fieldNames = seaTunnelRowType.getFieldNames();
+        Object[] fields = element.getFields();
+        List<RecordEntry> recordEntries = new ArrayList<>();
+        RecordSchema recordSchema = dataHubClient.getTopic(project, topic).getRecordSchema();
+        for (int i = 0; i < fieldNames.length; i++) {
+            TupleRecordData data = new TupleRecordData(recordSchema);
+            data.setField(fieldNames[i], fields[i]);
+            RecordEntry recordEntry = new RecordEntry();
+            recordEntry.setRecordData(data);
+            recordEntries.add(recordEntry);
+        }
+        try {
+            PutRecordsResult result = dataHubClient.putRecords(project, topic, recordEntries);

Review Comment:
   I'm not sure if I need to judge the corresponding result code.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org