17
17
18
18
package org .apache .seatunnel .connectors .seatunnel .starrocks .config ;
19
19
20
- import org .apache .seatunnel .shade .com .typesafe .config .Config ;
21
-
22
20
import org .apache .seatunnel .api .configuration .Option ;
23
21
import org .apache .seatunnel .api .configuration .Options ;
24
- import org .apache .seatunnel .common . config . TypesafeConfigUtils ;
22
+ import org .apache .seatunnel .api . configuration . ReadonlyConfig ;
25
23
26
24
import lombok .Getter ;
27
- import lombok .NonNull ;
28
25
import lombok .Setter ;
29
26
30
27
import java .util .HashMap ;
31
- import java .util .List ;
32
28
import java .util .Map ;
33
29
34
30
@ Setter
@@ -37,13 +33,26 @@ public class SourceConfig extends CommonConfig {
37
33
38
34
private static final long DEFAULT_SCAN_MEM_LIMIT = 1024 * 1024 * 1024L ;
39
35
40
- public SourceConfig (
41
- @ NonNull List <String > nodeUrls ,
42
- @ NonNull String username ,
43
- @ NonNull String password ,
44
- @ NonNull String database ,
45
- @ NonNull String table ) {
46
- super (nodeUrls , username , password , database , table );
36
+ public SourceConfig (ReadonlyConfig config ) {
37
+ super (config );
38
+ this .maxRetries = config .get (MAX_RETRIES );
39
+ this .requestTabletSize = config .get (QUERY_TABLET_SIZE );
40
+ this .scanFilter = config .get (SCAN_FILTER );
41
+ this .connectTimeoutMs = config .get (SCAN_CONNECT_TIMEOUT );
42
+ this .batchRows = config .get (SCAN_BATCH_ROWS );
43
+ this .keepAliveMin = config .get (SCAN_KEEP_ALIVE_MIN );
44
+ this .queryTimeoutSec = config .get (SCAN_QUERY_TIMEOUT_SEC );
45
+ this .memLimit = config .get (SCAN_MEM_LIMIT );
46
+
47
+ String prefix = STARROCKS_SCAN_CONFIG_PREFIX .key ();
48
+ config .toMap ()
49
+ .forEach (
50
+ (key , value ) -> {
51
+ if (key .startsWith (prefix )) {
52
+ this .sourceOptionProps .put (
53
+ key .substring (prefix .length ()).toLowerCase (), value );
54
+ }
55
+ });
47
56
}
48
57
49
58
public static final Option <Integer > MAX_RETRIES =
@@ -105,57 +114,5 @@ public SourceConfig(
105
114
private int keepAliveMin = SCAN_KEEP_ALIVE_MIN .defaultValue ();
106
115
private int batchRows = SCAN_BATCH_ROWS .defaultValue ();
107
116
private int connectTimeoutMs = SCAN_CONNECT_TIMEOUT .defaultValue ();
108
- private final Map <String , String > sourceOptionProps = new HashMap <>();
109
-
110
- public static SourceConfig loadConfig (Config pluginConfig ) {
111
- SourceConfig sourceConfig =
112
- new SourceConfig (
113
- pluginConfig .getStringList (NODE_URLS .key ()),
114
- pluginConfig .getString (USERNAME .key ()),
115
- pluginConfig .getString (PASSWORD .key ()),
116
- pluginConfig .getString (DATABASE .key ()),
117
- pluginConfig .getString (TABLE .key ()));
118
-
119
- if (pluginConfig .hasPath (MAX_RETRIES .key ())) {
120
- sourceConfig .setMaxRetries (pluginConfig .getInt (MAX_RETRIES .key ()));
121
- }
122
- if (pluginConfig .hasPath (QUERY_TABLET_SIZE .key ())) {
123
- sourceConfig .setRequestTabletSize (pluginConfig .getInt (QUERY_TABLET_SIZE .key ()));
124
- }
125
- if (pluginConfig .hasPath (SCAN_FILTER .key ())) {
126
- sourceConfig .setScanFilter (pluginConfig .getString (SCAN_FILTER .key ()));
127
- }
128
- if (pluginConfig .hasPath (SCAN_CONNECT_TIMEOUT .key ())) {
129
- sourceConfig .setConnectTimeoutMs (pluginConfig .getInt (SCAN_CONNECT_TIMEOUT .key ()));
130
- }
131
- if (pluginConfig .hasPath (SCAN_BATCH_ROWS .key ())) {
132
- sourceConfig .setBatchRows (pluginConfig .getInt (SCAN_BATCH_ROWS .key ()));
133
- }
134
- if (pluginConfig .hasPath (SCAN_KEEP_ALIVE_MIN .key ())) {
135
- sourceConfig .setKeepAliveMin (pluginConfig .getInt (SCAN_KEEP_ALIVE_MIN .key ()));
136
- }
137
- if (pluginConfig .hasPath (SCAN_QUERY_TIMEOUT_SEC .key ())) {
138
- sourceConfig .setQueryTimeoutSec (pluginConfig .getInt (SCAN_QUERY_TIMEOUT_SEC .key ()));
139
- }
140
- if (pluginConfig .hasPath (SCAN_MEM_LIMIT .key ())) {
141
- sourceConfig .setMemLimit (pluginConfig .getLong (SCAN_MEM_LIMIT .key ()));
142
- }
143
- parseSourceOptionProperties (pluginConfig , sourceConfig );
144
- return sourceConfig ;
145
- }
146
-
147
- private static void parseSourceOptionProperties (
148
- Config pluginConfig , SourceConfig sourceConfig ) {
149
- Config sourceOptionConfig =
150
- TypesafeConfigUtils .extractSubConfig (
151
- pluginConfig , STARROCKS_SCAN_CONFIG_PREFIX .key (), false );
152
- sourceOptionConfig
153
- .entrySet ()
154
- .forEach (
155
- entry -> {
156
- final String configKey = entry .getKey ().toLowerCase ();
157
- sourceConfig .sourceOptionProps .put (
158
- configKey , (String ) entry .getValue ().unwrapped ());
159
- });
160
- }
117
+ private Map <String , String > sourceOptionProps = new HashMap <>();
161
118
}
0 commit comments