|
17 | 17 |
|
18 | 18 | package org.apache.seatunnel.connectors.seatunnel.amazondynamodb.sink;
|
19 | 19 |
|
20 |
| -import org.apache.seatunnel.shade.com.typesafe.config.Config; |
21 |
| - |
22 |
| -import org.apache.seatunnel.api.common.PrepareFailException; |
23 |
| -import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode; |
24 |
| -import org.apache.seatunnel.api.sink.SeaTunnelSink; |
25 | 20 | import org.apache.seatunnel.api.sink.SinkWriter;
|
26 | 21 | import org.apache.seatunnel.api.table.catalog.CatalogTable;
|
27 | 22 | import org.apache.seatunnel.api.table.type.SeaTunnelRow;
|
28 |
| -import org.apache.seatunnel.api.table.type.SeaTunnelRowType; |
29 |
| -import org.apache.seatunnel.common.config.CheckConfigUtil; |
30 |
| -import org.apache.seatunnel.common.config.CheckResult; |
31 |
| -import org.apache.seatunnel.common.constants.PluginType; |
32 |
| -import org.apache.seatunnel.connectors.seatunnel.amazondynamodb.config.AmazonDynamoDBSourceOptions; |
33 |
| -import org.apache.seatunnel.connectors.seatunnel.amazondynamodb.exception.AmazonDynamoDBConnectorException; |
| 23 | +import org.apache.seatunnel.connectors.seatunnel.amazondynamodb.config.AmazonDynamoDBConfig; |
34 | 24 | import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSimpleSink;
|
35 | 25 | import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
|
36 | 26 |
|
37 |
| -import com.google.auto.service.AutoService; |
38 |
| - |
39 | 27 | import java.io.IOException;
|
40 | 28 | import java.util.Optional;
|
41 | 29 |
|
42 |
| -import static org.apache.seatunnel.connectors.seatunnel.amazondynamodb.config.AmazonDynamoDBConfig.ACCESS_KEY_ID; |
43 |
| -import static org.apache.seatunnel.connectors.seatunnel.amazondynamodb.config.AmazonDynamoDBConfig.REGION; |
44 |
| -import static org.apache.seatunnel.connectors.seatunnel.amazondynamodb.config.AmazonDynamoDBConfig.SECRET_ACCESS_KEY; |
45 |
| -import static org.apache.seatunnel.connectors.seatunnel.amazondynamodb.config.AmazonDynamoDBConfig.TABLE; |
46 |
| -import static org.apache.seatunnel.connectors.seatunnel.amazondynamodb.config.AmazonDynamoDBConfig.URL; |
47 |
| - |
48 |
| -@AutoService(SeaTunnelSink.class) |
49 | 30 | public class AmazonDynamoDBSink extends AbstractSimpleSink<SeaTunnelRow, Void> {
|
50 | 31 |
|
51 |
| - private SeaTunnelRowType rowType; |
| 32 | + private CatalogTable catalogTable; |
52 | 33 |
|
53 |
| - private AmazonDynamoDBSourceOptions amazondynamodbSourceOptions; |
| 34 | + private AmazonDynamoDBConfig amazondynamodbConfig; |
54 | 35 |
|
55 |
| - @Override |
56 |
| - public String getPluginName() { |
57 |
| - return "AmazonDynamodb"; |
| 36 | + public AmazonDynamoDBSink( |
| 37 | + CatalogTable catalogTable, AmazonDynamoDBConfig amazondynamodbConfig) { |
| 38 | + this.catalogTable = catalogTable; |
| 39 | + this.amazondynamodbConfig = amazondynamodbConfig; |
58 | 40 | }
|
59 | 41 |
|
60 | 42 | @Override
|
61 |
| - public void prepare(Config pluginConfig) throws PrepareFailException { |
62 |
| - CheckResult result = |
63 |
| - CheckConfigUtil.checkAllExists( |
64 |
| - pluginConfig, |
65 |
| - URL.key(), |
66 |
| - TABLE.key(), |
67 |
| - REGION.key(), |
68 |
| - ACCESS_KEY_ID.key(), |
69 |
| - SECRET_ACCESS_KEY.key()); |
70 |
| - if (!result.isSuccess()) { |
71 |
| - throw new AmazonDynamoDBConnectorException( |
72 |
| - SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED, |
73 |
| - String.format( |
74 |
| - "PluginName: %s, PluginType: %s, Message: %s", |
75 |
| - getPluginName(), PluginType.SINK, result.getMsg())); |
76 |
| - } |
77 |
| - amazondynamodbSourceOptions = new AmazonDynamoDBSourceOptions(pluginConfig); |
| 43 | + public Optional<CatalogTable> getWriteCatalogTable() { |
| 44 | + return Optional.of(catalogTable); |
78 | 45 | }
|
79 | 46 |
|
80 | 47 | @Override
|
81 |
| - public void setTypeInfo(SeaTunnelRowType seaTunnelRowType) { |
82 |
| - this.rowType = seaTunnelRowType; |
| 48 | + public String getPluginName() { |
| 49 | + return "AmazonDynamodb"; |
83 | 50 | }
|
84 | 51 |
|
85 | 52 | @Override
|
86 | 53 | public AbstractSinkWriter<SeaTunnelRow, Void> createWriter(SinkWriter.Context context)
|
87 | 54 | throws IOException {
|
88 |
| - return new AmazonDynamoDBWriter(amazondynamodbSourceOptions, rowType); |
89 |
| - } |
90 |
| - |
91 |
| - @Override |
92 |
| - public Optional<CatalogTable> getWriteCatalogTable() { |
93 |
| - return super.getWriteCatalogTable(); |
| 55 | + return new AmazonDynamoDBWriter(amazondynamodbConfig, catalogTable.getSeaTunnelRowType()); |
94 | 56 | }
|
95 | 57 | }
|
0 commit comments