Skip to content

Commit da33f73

Browse files
TaoZexHisoka-X
andauthored
[Feature][Connector-V2][Google Sheets] Add Google Sheets option rules (#3364)
* [Feature][Connector-V2][Google Sheets] Add Google Sheets option rules * [Feature][Connector-V2][Google Sheets] Add optional schema in optionRule * [Feature][Connector-V2][Google Sheets] fix doc Co-authored-by: Hisoka <fanjiaeminem@qq.com>
1 parent fdaa85e commit da33f73

File tree

5 files changed

+75
-10
lines changed

5 files changed

+75
-10
lines changed

docs/en/connector-v2/source/GoogleSheets.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Used to read data from GoogleSheets.
2626
| service_account_key | string | yes | - |
2727
| sheet_id | string | yes | - |
2828
| sheet_name | string | yes | - |
29-
| schema | config | yes | - |
29+
| range | string | yes | - |
30+
| schema | config | no | - |
3031

3132
### service_account_key [string]
3233

@@ -40,6 +41,10 @@ sheet id in a Google Sheets URL
4041

4142
the name of the sheet you want to import
4243

44+
### range [string]
45+
46+
the range of the sheet you want to import
47+
4348
### schema [config]
4449

4550
#### fields [config]

seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/config/SheetsConfig.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@
1717

1818
package org.apache.seatunnel.connectors.seatunnel.google.sheets.config;
1919

20+
import org.apache.seatunnel.api.configuration.Option;
21+
import org.apache.seatunnel.api.configuration.Options;
22+
2023
public class SheetsConfig {
2124

22-
public static final String SERVICE_ACCOUNT_KEY = "service_account_key";
23-
public static final String SHEET_ID = "sheet_id";
24-
public static final String SHEET_NAME = "sheet_name";
25-
public static final String RANGE = "range";
25+
public static final Option<String> SERVICE_ACCOUNT_KEY = Options.key("service_account_key")
26+
.stringType()
27+
.noDefaultValue()
28+
.withDescription("Google Sheets login service account key");
29+
public static final Option<String> SHEET_ID = Options.key("sheet_id")
30+
.stringType()
31+
.noDefaultValue()
32+
.withDescription("Google Sheets sheet id");
33+
public static final Option<String> SHEET_NAME = Options.key("sheet_name")
34+
.stringType()
35+
.noDefaultValue()
36+
.withDescription("Google Sheets sheet name that you want to import");
37+
public static final Option<String> RANGE = Options.key("range")
38+
.stringType()
39+
.noDefaultValue()
40+
.withDescription("Google Sheets sheet range that you want to import");
2641
}

seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/config/SheetsParameters.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public class SheetsParameters implements Serializable {
3535
private String range;
3636

3737
public SheetsParameters buildWithConfig(Config config) {
38-
this.serviceAccountKey = config.getString(SheetsConfig.SERVICE_ACCOUNT_KEY).getBytes();
39-
this.sheetId = config.getString(SheetsConfig.SHEET_ID);
40-
this.sheetName = config.getString(SheetsConfig.SHEET_NAME);
41-
this.range = config.getString(SheetsConfig.RANGE);
38+
this.serviceAccountKey = config.getString(SheetsConfig.SERVICE_ACCOUNT_KEY.key()).getBytes();
39+
this.sheetId = config.getString(SheetsConfig.SHEET_ID.key());
40+
this.sheetName = config.getString(SheetsConfig.SHEET_NAME.key());
41+
this.range = config.getString(SheetsConfig.RANGE.key());
4242
return this;
4343
}
4444

seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/source/SheetsSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public String getPluginName() {
5555

5656
@Override
5757
public void prepare(Config pluginConfig) throws PrepareFailException {
58-
CheckResult checkResult = CheckConfigUtil.checkAllExists(pluginConfig, SheetsConfig.SERVICE_ACCOUNT_KEY, SheetsConfig.SHEET_ID, SheetsConfig.SHEET_NAME, SheetsConfig.RANGE, SeaTunnelSchema.SCHEMA.key());
58+
CheckResult checkResult = CheckConfigUtil.checkAllExists(pluginConfig, SheetsConfig.SERVICE_ACCOUNT_KEY.key(), SheetsConfig.SHEET_ID.key(), SheetsConfig.SHEET_NAME.key(), SheetsConfig.RANGE.key(), SeaTunnelSchema.SCHEMA.key());
5959
if (!checkResult.isSuccess()) {
6060
throw new PrepareFailException(getPluginName(), PluginType.SOURCE, checkResult.getMsg());
6161
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.connectors.seatunnel.google.sheets.source;
19+
20+
import org.apache.seatunnel.api.configuration.util.OptionRule;
21+
import org.apache.seatunnel.api.table.factory.Factory;
22+
import org.apache.seatunnel.api.table.factory.TableSourceFactory;
23+
import org.apache.seatunnel.connectors.seatunnel.common.schema.SeaTunnelSchema;
24+
import org.apache.seatunnel.connectors.seatunnel.google.sheets.config.SheetsConfig;
25+
26+
import com.google.auto.service.AutoService;
27+
28+
@AutoService(Factory.class)
29+
public class SheetsSourceFactory implements TableSourceFactory {
30+
@Override
31+
public String factoryIdentifier() {
32+
return "GoogleSheets";
33+
}
34+
35+
@Override
36+
public OptionRule optionRule() {
37+
return OptionRule.builder()
38+
.required(SheetsConfig.SERVICE_ACCOUNT_KEY)
39+
.required(SheetsConfig.SHEET_ID)
40+
.required(SheetsConfig.SHEET_NAME)
41+
.required(SheetsConfig.RANGE)
42+
.optional(SeaTunnelSchema.SCHEMA)
43+
.build();
44+
}
45+
}

0 commit comments

Comments
 (0)