Skip to content
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 @@ -62,6 +62,7 @@
import java.util.stream.Collectors;

import static org.apache.paimon.CoreOptions.DATA_FILE_EXTERNAL_PATHS;
import static org.apache.paimon.CoreOptions.GLOBAL_INDEX_EXTERNAL_PATH;
import static org.apache.paimon.CoreOptions.PATH;
import static org.apache.paimon.CoreOptions.TYPE;
import static org.apache.paimon.catalog.CatalogUtils.checkNotBranch;
Expand Down Expand Up @@ -387,7 +388,15 @@ private List<Path> getSchemaExternalPaths(List<TableSchema> schemas) {
return Collections.emptyList();
}
return schemas.stream()
.map(schema -> schema.toSchema().options().get(DATA_FILE_EXTERNAL_PATHS.key()))
.flatMap(
schema -> {
Map<String, String> options = schema.toSchema().options();
return Arrays.stream(
new String[] {
options.get(DATA_FILE_EXTERNAL_PATHS.key()),
options.get(GLOBAL_INDEX_EXTERNAL_PATH.key())
});
})
.filter(Objects::nonNull)
.flatMap(externalPath -> Arrays.stream(externalPath.split(",")))
.map(Path::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

import javax.annotation.Nullable;

import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -1081,6 +1082,38 @@ public void testDropTable() throws Exception {
assertThatCode(() -> catalog.dropTable(nonExistingTable, true)).doesNotThrowAnyException();
}

@Test
public void testDropTableWithExternalPaths() throws Exception {
catalog.createDatabase("test_db", false);
Identifier identifier = Identifier.create("test_db", "table_with_external_paths");
java.nio.file.Path dataExternalPath = tempFile.resolve("data-external-path");
java.nio.file.Path globalIndexExternalPath = tempFile.resolve("global-index-external-path");
Files.createDirectories(dataExternalPath.resolve("data"));
Files.createDirectories(globalIndexExternalPath.resolve("index"));

Map<String, String> options = new HashMap<>();
options.put(
CoreOptions.DATA_FILE_EXTERNAL_PATHS.key(), dataExternalPath.toUri().toString());
options.put(
CoreOptions.GLOBAL_INDEX_EXTERNAL_PATH.key(),
globalIndexExternalPath.toUri().toString());
Schema schema =
new Schema(
Lists.newArrayList(
new DataField(0, "pk", DataTypes.INT()),
new DataField(1, "col", DataTypes.STRING())),
Collections.emptyList(),
Collections.emptyList(),
options,
"");

catalog.createTable(identifier, schema, false);
catalog.dropTable(identifier, false);

assertThat(Files.exists(dataExternalPath)).isFalse();
assertThat(Files.exists(globalIndexExternalPath)).isFalse();
}

@Test
public void testRenameTable() throws Exception {
catalog.createDatabase("test_db", false);
Expand Down