33
33
import org .apache .seatunnel .api .table .catalog .exception .TableAlreadyExistException ;
34
34
import org .apache .seatunnel .api .table .catalog .exception .TableNotExistException ;
35
35
import org .apache .seatunnel .api .table .converter .BasicTypeDefine ;
36
+ import org .apache .seatunnel .connectors .seatunnel .maxcompute .config .MaxcomputeBaseOptions ;
37
+ import org .apache .seatunnel .connectors .seatunnel .maxcompute .config .MaxcomputeSinkOptions ;
36
38
import org .apache .seatunnel .connectors .seatunnel .maxcompute .datatype .MaxComputeTypeConverter ;
37
39
import org .apache .seatunnel .connectors .seatunnel .maxcompute .util .MaxcomputeUtil ;
38
40
55
57
import java .util .List ;
56
58
import java .util .Optional ;
57
59
58
- import static org .apache .seatunnel .connectors .seatunnel .maxcompute .config .MaxcomputeConfig .ACCESS_ID ;
59
- import static org .apache .seatunnel .connectors .seatunnel .maxcompute .config .MaxcomputeConfig .ACCESS_KEY ;
60
- import static org .apache .seatunnel .connectors .seatunnel .maxcompute .config .MaxcomputeConfig .ENDPOINT ;
61
- import static org .apache .seatunnel .connectors .seatunnel .maxcompute .config .MaxcomputeConfig .PARTITION_SPEC ;
62
- import static org .apache .seatunnel .connectors .seatunnel .maxcompute .config .MaxcomputeConfig .PROJECT ;
63
- import static org .apache .seatunnel .connectors .seatunnel .maxcompute .config .MaxcomputeConfig .SAVE_MODE_CREATE_TEMPLATE ;
64
60
import static org .apache .seatunnel .shade .com .google .common .base .Preconditions .checkArgument ;
65
61
66
62
@ Slf4j
@@ -78,7 +74,10 @@ public MaxComputeCatalog(String catalogName, ReadonlyConfig options) {
78
74
79
75
@ Override
80
76
public void open () throws CatalogException {
81
- account = new AliyunAccount (readonlyConfig .get (ACCESS_ID ), readonlyConfig .get (ACCESS_KEY ));
77
+ account =
78
+ new AliyunAccount (
79
+ readonlyConfig .get (MaxcomputeBaseOptions .ACCESS_ID ),
80
+ readonlyConfig .get (MaxcomputeBaseOptions .ACCESS_KEY ));
82
81
}
83
82
84
83
@ Override
@@ -91,13 +90,13 @@ public String name() {
91
90
92
91
@ Override
93
92
public String getDefaultDatabase () throws CatalogException {
94
- return readonlyConfig .get (PROJECT );
93
+ return readonlyConfig .get (MaxcomputeBaseOptions . PROJECT );
95
94
}
96
95
97
96
@ Override
98
97
public boolean databaseExists (String databaseName ) throws CatalogException {
99
98
try {
100
- Odps odps = getOdps (readonlyConfig .get (PROJECT ));
99
+ Odps odps = getOdps (readonlyConfig .get (MaxcomputeBaseOptions . PROJECT ));
101
100
Projects projects = odps .projects ();
102
101
return projects .exists (databaseName );
103
102
} catch (OdpsException e ) {
@@ -109,7 +108,7 @@ public boolean databaseExists(String databaseName) throws CatalogException {
109
108
public List <String > listDatabases () throws CatalogException {
110
109
try {
111
110
// todo: how to get all projects
112
- String project = readonlyConfig .get (PROJECT );
111
+ String project = readonlyConfig .get (MaxcomputeBaseOptions . PROJECT );
113
112
if (databaseExists (project )) {
114
113
return Lists .newArrayList (project );
115
114
}
@@ -210,7 +209,8 @@ public void createTable(TablePath tablePath, CatalogTable table, boolean ignoreI
210
209
SQLTask .run (
211
210
odps ,
212
211
MaxComputeCatalogUtil .getCreateTableStatement (
213
- readonlyConfig .get (SAVE_MODE_CREATE_TEMPLATE ),
212
+ readonlyConfig .get (
213
+ MaxcomputeSinkOptions .SAVE_MODE_CREATE_TEMPLATE ),
214
214
tablePath ,
215
215
table ))
216
216
.waitForSuccess ();
@@ -250,8 +250,10 @@ public void truncateTable(TablePath tablePath, boolean ignoreIfNotExists)
250
250
Odps odps = getOdps (tablePath .getDatabaseName ());
251
251
Table odpsTable = odps .tables ().get (tablePath .getTableName ());
252
252
if (odpsTable .isPartitioned ()
253
- && StringUtils .isNotEmpty (readonlyConfig .get (PARTITION_SPEC ))) {
254
- PartitionSpec partitionSpec = new PartitionSpec (readonlyConfig .get (PARTITION_SPEC ));
253
+ && StringUtils .isNotEmpty (
254
+ readonlyConfig .get (MaxcomputeBaseOptions .PARTITION_SPEC ))) {
255
+ PartitionSpec partitionSpec =
256
+ new PartitionSpec (readonlyConfig .get (MaxcomputeBaseOptions .PARTITION_SPEC ));
255
257
odpsTable .deletePartition (partitionSpec , ignoreIfNotExists );
256
258
odpsTable .createPartition (partitionSpec , true );
257
259
} else {
@@ -313,7 +315,7 @@ public PreviewResult previewAction(
313
315
checkArgument (catalogTable .isPresent (), "CatalogTable cannot be null" );
314
316
return new SQLPreviewResult (
315
317
MaxComputeCatalogUtil .getCreateTableStatement (
316
- readonlyConfig .get (SAVE_MODE_CREATE_TEMPLATE ),
318
+ readonlyConfig .get (MaxcomputeSinkOptions . SAVE_MODE_CREATE_TEMPLATE ),
317
319
tablePath ,
318
320
catalogTable .get ()));
319
321
} else if (actionType == ActionType .DROP_TABLE ) {
@@ -325,7 +327,7 @@ public PreviewResult previewAction(
325
327
326
328
private Odps getOdps (String project ) {
327
329
Odps odps = new Odps (account );
328
- odps .setEndpoint (readonlyConfig .get (ENDPOINT ));
330
+ odps .setEndpoint (readonlyConfig .get (MaxcomputeBaseOptions . ENDPOINT ));
329
331
odps .setDefaultProject (project );
330
332
return odps ;
331
333
}
0 commit comments