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


##########
seatunnel-connectors-v2/connector-google-sheets/pom.xml:
##########
@@ -0,0 +1,95 @@
+<?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-google-sheets</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>connector-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>seatunnel-format-json</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.apis</groupId>
+            <artifactId>google-api-services-sheets</artifactId>
+            <version>v4-rev612-1.25.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.auth</groupId>
+            <artifactId>google-auth-library-oauth2-http</artifactId>
+            <version>1.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>31.1-android</version>
+        </dependency>
+
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>3.1.0</version>

Review Comment:
   remove version 



##########
seatunnel-connectors-v2/connector-google-sheets/pom.xml:
##########
@@ -0,0 +1,95 @@
+<?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-google-sheets</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>connector-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>seatunnel-format-json</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.apis</groupId>
+            <artifactId>google-api-services-sheets</artifactId>
+            <version>v4-rev612-1.25.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.auth</groupId>
+            <artifactId>google-auth-library-oauth2-http</artifactId>
+            <version>1.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>31.1-android</version>
+        </dependency>
+
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>3.1.0</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <relocations>
+                                <relocation>
+                                    <pattern>com.google.common</pattern>
+                                    
<shadedPattern>my_guava.common</shadedPattern>

Review Comment:
   ```suggestion
                                       
<shadedPattern>${seatunnel.shade.package}.google.sheets.com.google.common</shadedPattern>
   ```



##########
seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/source/SheetsSourceReader.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.google.sheets.source;
+
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.common.utils.JsonUtils;
+import 
org.apache.seatunnel.connectors.seatunnel.common.source.AbstractSingleSplitReader;
+import 
org.apache.seatunnel.connectors.seatunnel.common.source.SingleSplitReaderContext;
+import 
org.apache.seatunnel.connectors.seatunnel.google.sheets.config.SheetsParameters;
+
+import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
+import com.google.api.client.http.HttpRequestInitializer;
+import com.google.api.client.http.javanet.NetHttpTransport;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.gson.GsonFactory;
+import com.google.api.services.sheets.v4.Sheets;
+import com.google.api.services.sheets.v4.SheetsScopes;
+import com.google.api.services.sheets.v4.model.ValueRange;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.ServiceAccountCredentials;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SheetsSourceReader extends 
AbstractSingleSplitReader<SeaTunnelRow> {
+
+    private SheetsParameters sheetsParameters;
+
+    private HttpRequestInitializer requestInitializer;
+
+    private static final String APPLICATION_NAME = "SeaTunnel Google Sheets";
+
+    private static final JsonFactory JSON_FACTORY = 
GsonFactory.getDefaultInstance();
+
+    private final SingleSplitReaderContext context;
+
+    private DeserializationSchema<SeaTunnelRow> deserializationSchema;
+
+    public SheetsSourceReader(SheetsParameters sheetsParameters, 
SingleSplitReaderContext context, DeserializationSchema<SeaTunnelRow> 
deserializationSchema) throws IOException {
+        this.sheetsParameters = sheetsParameters;
+        this.context = context;
+        this.deserializationSchema = deserializationSchema;
+    }
+
+    @Override
+    public void open() throws Exception {
+        byte[] keyBytes = 
Base64.getDecoder().decode(sheetsParameters.getServiceAccountKey());
+        ServiceAccountCredentials sourceCredentials = ServiceAccountCredentials
+            .fromStream(new ByteArrayInputStream(keyBytes));
+        sourceCredentials = (ServiceAccountCredentials) sourceCredentials
+            
.createScoped(Collections.singletonList(SheetsScopes.SPREADSHEETS));
+        requestInitializer = new HttpCredentialsAdapter(sourceCredentials);
+
+    }
+
+    @Override
+    public void close() throws IOException {
+
+    }
+
+    @Override
+    public void pollNext(Collector<SeaTunnelRow> output) throws Exception {
+        final NetHttpTransport httpTransport = 
GoogleNetHttpTransport.newTrustedTransport();
+        Sheets service = new Sheets.Builder(httpTransport, JSON_FACTORY, 
requestInitializer)
+            .setApplicationName(APPLICATION_NAME)
+            .build();
+        ValueRange response = service.spreadsheets().values()
+            .get(sheetsParameters.getSheetId(), 
sheetsParameters.getSheetName() + "!" + sheetsParameters.getRange())
+            .execute();
+        List<List<Object>> values = response.getValues();
+        if (values != null) {
+            for (List<Object> row : values) {
+                Map<String, Object> data = new HashMap<>();
+                for (int i = 0; i < row.size(); i++) {
+                    String key = i + "";
+                    if (sheetsParameters != null && i < 
sheetsParameters.getHeaders().size()) {
+                        if (!sheetsParameters.getHeaders().get(i).equals("")) {
+                            key = sheetsParameters.getHeaders().get(i);
+                        }
+                    }
+                    data.put(key, row.get(i));
+                }
+                String dataStr = JsonUtils.toJsonString(data);
+                deserializationSchema.deserialize(dataStr.getBytes(), output);

Review Comment:
   Thx. you should implement `GoogleSheetsDeserialization` yourself.
   
   GoogleSheetsDeserialization using `seaTunnelRowType` to convert 
`List<Object> row` to SeaTunnelRow



##########
docs/en/connector-v2/source/GoogleSheets.md:
##########
@@ -0,0 +1,60 @@
+# GoogleSheets
+
+> GoogleSheets source connector
+
+## Description
+
+Used to read data from GoogleSheets.
+
+## Options
+
+| name                | type         | required | default value |
+|-------------------  |--------------|----------|---------------|
+| service_account_key | string       | yes      | -             |
+| sheet_id            | string       | yes      | -             |
+| sheet_name          | string       | yes      | -             |
+| headers             | array        | yes      | -             |
+| schema              | config       | yes      | -             |
+
+### service_account_key [string]
+
+google cloud service account, base64 required
+
+### sheet_id [string]
+
+sheet id in a Google Sheets URL
+
+### sheet_name [string]
+
+the name of the sheet you want to import
+
+### headers [array]
+
+as column name
+
+### schema [config]
+
+#### fields [config]
+
+the schema fields of upstream data
+
+## Example
+
+simple:
+
+```hocon
+  GoogleSheets {
+    service_account_key = "seatunnel-test"
+    sheet_id = "1VI0DvyZK-NIdssSdsDSsSSSC-_-rYMi7ppJiI_jhE"
+    sheet_name = "sheets01"
+    range = "A1:C3"
+    headers = ["a", "b", "c"]
+    schema = {
+      fields {
+        a: int
+        b: string
+        c: string

Review Comment:
   Should use `=` ?
   
   example 
   a = int



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