Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve][API] Move catalog open to SaveModeHandler #7439

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public DefaultSaveModeHandler(
customSql);
}

@Override
public void open() {
catalog.open();
}

@Override
public void handleSchemaSaveMode() {
switch (schemaSaveMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

public interface SaveModeHandler extends AutoCloseable {

void open();

void handleSchemaSaveMode();

void handleDataSaveMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public Optional<SaveModeHandler> getSaveModeHandler() {
}

Catalog catalog = catalogFactory.createCatalog(catalogFactory.factoryIdentifier(), config);
catalog.open();
return Optional.of(
new DefaultSaveModeHandler(
config.get(DorisOptions.SCHEMA_SAVE_MODE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public Optional<SaveModeHandler> getSaveModeHandler() {
DataSaveMode dataSaveMode = config.get(SinkConfig.DATA_SAVE_MODE);

TablePath tablePath = TablePath.of("", catalogTable.getTableId().getTableName());
catalog.open();
return Optional.of(
new DefaultSaveModeHandler(
schemaSaveMode, dataSaveMode, catalog, tablePath, null, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public Optional<SaveModeHandler> getSaveModeHandler() {
}
Catalog catalog =
catalogFactory.createCatalog(catalogFactory.factoryIdentifier(), readonlyConfig);
catalog.open();
return Optional.of(
new DefaultSaveModeHandler(
config.getSchemaSaveMode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ public Optional<SaveModeHandler> getSaveModeHandler() {
if (catalogOptional.isPresent()) {
try {
Catalog catalog = catalogOptional.get();
catalog.open();
FieldIdeEnum fieldIdeEnumEnum = config.get(JdbcOptions.FIELD_IDE);
String fieldIde =
fieldIdeEnumEnum == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public Optional<SaveModeHandler> getSaveModeHandler() {
SchemaSaveMode schemaSaveMode = config.get(MilvusSinkConfig.SCHEMA_SAVE_MODE);
DataSaveMode dataSaveMode = config.get(MilvusSinkConfig.DATA_SAVE_MODE);

catalog.open();
return Optional.of(
new DefaultSaveModeHandler(
schemaSaveMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public Optional<SaveModeHandler> getSaveModeHandler() {
}
org.apache.seatunnel.api.table.catalog.Catalog catalog =
catalogFactory.createCatalog(catalogFactory.factoryIdentifier(), readonlyConfig);
catalog.open();
return Optional.of(
new PaimonSaveModeHandler(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public Optional<SaveModeHandler> getSaveModeHandler() {
sinkConfig.getPassword(),
sinkConfig.getJdbcUrl(),
sinkConfig.getSaveModeCreateTemplate());
catalog.open();
return Optional.of(
new DefaultSaveModeHandler(
schemaSaveMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public List<DataStreamTableInfo> execute(List<DataStreamTableInfo> upstreamDataS
Optional<SaveModeHandler> saveModeHandler = saveModeSink.getSaveModeHandler();
if (saveModeHandler.isPresent()) {
try (SaveModeHandler handler = saveModeHandler.get()) {
handler.open();
new SaveModeExecuteWrapper(handler).execute();
} catch (Exception e) {
throw new SeaTunnelRuntimeException(HANDLE_SAVE_MODE_FAILED, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public List<DataStreamTableInfo> execute(List<DataStreamTableInfo> upstreamDataS
Optional<SaveModeHandler> saveModeHandler = saveModeSink.getSaveModeHandler();
if (saveModeHandler.isPresent()) {
try (SaveModeHandler handler = saveModeHandler.get()) {
handler.open();
new SaveModeExecuteWrapper(handler).execute();
} catch (Exception e) {
throw new SeaTunnelRuntimeException(HANDLE_SAVE_MODE_FAILED, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public List<DatasetTableInfo> execute(List<DatasetTableInfo> upstreamDataStreams
Optional<SaveModeHandler> saveModeHandler = saveModeSink.getSaveModeHandler();
if (saveModeHandler.isPresent()) {
try (SaveModeHandler handler = saveModeHandler.get()) {
handler.open();
new SaveModeExecuteWrapper(handler).execute();
} catch (Exception e) {
throw new SeaTunnelRuntimeException(HANDLE_SAVE_MODE_FAILED, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public List<DatasetTableInfo> execute(List<DatasetTableInfo> upstreamDataStreams
Optional<SaveModeHandler> saveModeHandler = saveModeSink.getSaveModeHandler();
if (saveModeHandler.isPresent()) {
try (SaveModeHandler handler = saveModeHandler.get()) {
handler.open();
new SaveModeExecuteWrapper(handler).execute();
} catch (Exception e) {
throw new SeaTunnelRuntimeException(HANDLE_SAVE_MODE_FAILED, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.seatunnel.e2e.connector.doris;

import org.apache.seatunnel.api.configuration.ReadonlyConfig;
import org.apache.seatunnel.api.sink.SaveModeHandler;
import org.apache.seatunnel.api.sink.SupportSaveMode;
import org.apache.seatunnel.api.source.SeaTunnelSource;
import org.apache.seatunnel.api.table.catalog.CatalogTable;
Expand Down Expand Up @@ -245,7 +246,9 @@ private CatalogTable assertCreateTable(
Thread.currentThread().getContextClassLoader(),
Collections.emptyList());
SupportSaveMode sink = (SupportSaveMode) dorisSinkFactory.createSink(context).createSink();
sink.getSaveModeHandler().get().handleSaveMode();
SaveModeHandler handler = sink.getSaveModeHandler().get();
handler.open();
handler.handleSaveMode();
CatalogTable createdTable = catalog.getTable(TablePath.of(fullName));
Assertions.assertEquals(
upstreamTable.getTableSchema().getColumns().size(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public InMemorySaveModeHandler(CatalogTable catalogTable) {
this.catalogTable = catalogTable;
}

@Override
public void open() {}

@Override
public void handleSchemaSaveMode() {
log.info("handle schema savemode with table path: {}", catalogTable.getTablePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ public void handleSaveMode(SeaTunnelSink<?, ?, ?, ?> sink) {
Optional<SaveModeHandler> saveModeHandler = saveModeSink.getSaveModeHandler();
if (saveModeHandler.isPresent()) {
try (SaveModeHandler handler = saveModeHandler.get()) {
handler.open();
new SaveModeExecuteWrapper(handler).execute();
} catch (Exception e) {
throw new SeaTunnelRuntimeException(HANDLE_SAVE_MODE_FAILED, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ public static void handleSaveMode(SeaTunnelSink sink) {
((SupportSaveMode) sink).getSaveModeHandler();
if (saveModeHandler.isPresent()) {
try (SaveModeHandler handler = saveModeHandler.get()) {
handler.open();
new SaveModeExecuteWrapper(handler).execute();
} catch (Exception e) {
throw new SeaTunnelRuntimeException(HANDLE_SAVE_MODE_FAILED, e);
Expand Down
Loading