Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#2041][#2306] Improvement(catalog-hadoop):Add E2E integration test for Hadoop catalog (#2294)

Peidian li5131d17a00ae
diff --git a/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java
index bd911bbfd3..ea7a23abeb 100644
--- a/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java
+++ b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java
@@ -558,6 +558,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
? Maps.newHashMap()
: Maps.newHashMap(filesetEntity.properties());
String newName = ident.name();
+ String newComment = filesetEntity.comment();
for (FilesetChange change : changes) {
if (change instanceof FilesetChange.SetProperty) {
@@ -568,6 +569,8 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
props.remove(removeProperty.getProperty());
} else if (change instanceof FilesetChange.RenameFileset) {
newName = ((FilesetChange.RenameFileset) change).getNewName();
+ } else if (change instanceof FilesetChange.UpdateFilesetComment) {
+ newComment = ((FilesetChange.UpdateFilesetComment) change).getNewComment();
} else {
throw new IllegalArgumentException(
"Unsupported fileset change: " + change.getClass().getSimpleName());
@@ -578,7 +581,7 @@ public class HadoopCatalogOperations implements CatalogOperations, SupportsSchem
.withName(newName)
.withNamespace(ident.namespace())
.withId(filesetEntity.id())
- .withComment(filesetEntity.comment())
+ .withComment(newComment)
.withFilesetType(filesetEntity.filesetType())
.withStorageLocation(filesetEntity.storageLocation())
.withProperties(props)
diff --git a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java
index 78573dee00..e3aadbc06c 100644
--- a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java
+++ b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java
@@ -567,6 +567,29 @@ public class TestHadoopCatalogOperations {
}
}
+ @Test
+ public void testUpdateFilesetComment() throws IOException {
+ String schemaName = "schema26";
+ String comment = "comment26";
+ String schemaPath = TEST_ROOT_PATH + "/" + schemaName;
+ createSchema(schemaName, comment, null, schemaPath);
+
+ String name = "fileset26";
+ Fileset fileset = createFileset(name, schemaName, comment, Fileset.Type.MANAGED, null, null);
+
+ FilesetChange change1 = FilesetChange.updateComment("comment26_new");
+ try (HadoopCatalogOperations ops = new HadoopCatalogOperations(null, store)) {
+ ops.initialize(Maps.newHashMap());
+ NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, name);
+
+ Fileset fileset1 = ops.alterFileset(filesetIdent, change1);
+ Assertions.assertEquals(name, fileset1.name());
+ Assertions.assertEquals(Fileset.Type.MANAGED, fileset1.type());
+ Assertions.assertEquals("comment26_new", fileset1.comment());
+ Assertions.assertEquals(fileset.storageLocation(), fileset1.storageLocation());
+ }
+ }
+
private static Stream<Arguments> locationArguments() {
return Stream.of(
// Honor the catalog location
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java b/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java
index c66d8c33bb..3932d0b45e 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java
@@ -7,6 +7,7 @@ package com.datastrato.gravitino.storage.kv;
import static com.datastrato.gravitino.Configs.ENTITY_KV_STORE;
import static com.datastrato.gravitino.Entity.EntityType.CATALOG;
+import static com.datastrato.gravitino.Entity.EntityType.FILESET;
import static com.datastrato.gravitino.Entity.EntityType.SCHEMA;
import static com.datastrato.gravitino.Entity.EntityType.TABLE;
import static com.datastrato.gravitino.storage.kv.BinaryEntityKeyEncoder.LOG;
@@ -307,15 +308,19 @@ public class KvEntityStore implements EntityStore {
prefixes.add(replacePrefixTypeInfo(encode, CATALOG.getShortName()));
prefixes.add(replacePrefixTypeInfo(encode, SCHEMA.getShortName()));
prefixes.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, FILESET.getShortName()));
break;
case CATALOG:
prefixes.add(replacePrefixTypeInfo(encode, SCHEMA.getShortName()));
prefixes.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, FILESET.getShortName()));
break;
case SCHEMA:
prefixes.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, FILESET.getShortName()));
break;
case TABLE:
+ case FILESET:
break;
default:
LOG.warn("Currently unknown type: {}, please check it", type);
diff --git a/core/src/test/java/com/datastrato/gravitino/TestEntityStore.java b/core/src/test/java/com/datastrato/gravitino/TestEntityStore.java
index 81a53932ee..1388973aa4 100644
--- a/core/src/test/java/com/datastrato/gravitino/TestEntityStore.java
+++ b/core/src/test/java/com/datastrato/gravitino/TestEntityStore.java
@@ -6,9 +6,11 @@ package com.datastrato.gravitino;
import com.datastrato.gravitino.Entity.EntityType;
import com.datastrato.gravitino.exceptions.NoSuchEntityException;
+import com.datastrato.gravitino.file.Fileset;
import com.datastrato.gravitino.meta.AuditInfo;
import com.datastrato.gravitino.meta.BaseMetalake;
import com.datastrato.gravitino.meta.CatalogEntity;
+import com.datastrato.gravitino.meta.FilesetEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.meta.SchemaVersion;
import com.datastrato.gravitino.meta.TableEntity;
@@ -182,6 +184,16 @@ public class TestEntityStore {
.withAuditInfo(auditInfo)
.build();
+ FilesetEntity filesetEntity =
+ new FilesetEntity.Builder()
+ .withId(1L)
+ .withName("fileset")
+ .withFilesetType(Fileset.Type.MANAGED)
+ .withStorageLocation("file:/tmp")
+ .withNamespace(Namespace.of("metalake", "catalog", "db"))
+ .withAuditInfo(auditInfo)
+ .build();
+
InMemoryEntityStore store = new InMemoryEntityStore();
store.initialize(Mockito.mock(Config.class));
store.setSerDe(Mockito.mock(EntitySerDe.class));
@@ -190,6 +202,7 @@ public class TestEntityStore {
store.put(catalog);
store.put(schemaEntity);
store.put(tableEntity);
+ store.put(filesetEntity);
Metalake retrievedMetalake =
store.get(metalake.nameIdentifier(), EntityType.METALAKE, BaseMetalake.class);
@@ -207,6 +220,10 @@ public class TestEntityStore {
store.get(tableEntity.nameIdentifier(), EntityType.TABLE, TableEntity.class);
Assertions.assertEquals(tableEntity, retrievedTable);
+ FilesetEntity retrievedFileset =
+ store.get(filesetEntity.nameIdentifier(), EntityType.FILESET, FilesetEntity.class);
+ Assertions.assertEquals(filesetEntity, retrievedFileset);
+
store.delete(metalake.nameIdentifier(), EntityType.METALAKE);
NameIdentifier id = metalake.nameIdentifier();
Assertions.assertThrows(
diff --git a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestKvEntityStorage.java b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestKvEntityStorage.java
index 3f45c01a74..8ba6bfa37e 100644
--- a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestKvEntityStorage.java
+++ b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestKvEntityStorage.java
@@ -26,9 +26,11 @@ import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.exceptions.AlreadyExistsException;
import com.datastrato.gravitino.exceptions.NoSuchEntityException;
import com.datastrato.gravitino.exceptions.NonEmptyEntityException;
+import com.datastrato.gravitino.file.Fileset;
import com.datastrato.gravitino.meta.AuditInfo;
import com.datastrato.gravitino.meta.BaseMetalake;
import com.datastrato.gravitino.meta.CatalogEntity;
+import com.datastrato.gravitino.meta.FilesetEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.meta.SchemaVersion;
import com.datastrato.gravitino.meta.TableEntity;
@@ -108,6 +110,18 @@ public class TestKvEntityStorage {
.build();
}
+ public static FilesetEntity createFilesetEntity(
+ Namespace namespace, String name, AuditInfo auditInfo) {
+ return new FilesetEntity.Builder()
+ .withId(1L)
+ .withName(name)
+ .withNamespace(namespace)
+ .withFilesetType(Fileset.Type.MANAGED)
+ .withStorageLocation("/tmp")
+ .withAuditInfo(auditInfo)
+ .build();
+ }
+
@Test
void testRestart() throws IOException {
Config config = Mockito.mock(Config.class);
@@ -136,6 +150,9 @@ public class TestKvEntityStorage {
createSchemaEntity(Namespace.of("metalake", "catalog"), "schema1", auditInfo);
TableEntity table1 =
createTableEntity(Namespace.of("metalake", "catalog", "schema1"), "table1", auditInfo);
+ FilesetEntity fileset1 =
+ createFilesetEntity(
+ Namespace.of("metalake", "catalog", "schema1"), "fileset1", auditInfo);
// Store all entities
store.put(metalake);
@@ -143,6 +160,7 @@ public class TestKvEntityStorage {
store.put(catalogCopy);
store.put(schema1);
store.put(table1);
+ store.put(fileset1);
Assertions.assertDoesNotThrow(
() -> store.get(NameIdentifier.of("metalake"), EntityType.METALAKE, BaseMetalake.class));
@@ -164,6 +182,12 @@ public class TestKvEntityStorage {
NameIdentifier.of("metalake", "catalog", "schema1", "table1"),
EntityType.TABLE,
TableEntity.class));
+ Assertions.assertDoesNotThrow(
+ () ->
+ store.get(
+ NameIdentifier.of("metalake", "catalog", "schema1", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
}
// It will automatically close the store we create before, then we reopen the entity store
@@ -192,6 +216,12 @@ public class TestKvEntityStorage {
NameIdentifier.of("metalake", "catalog", "schema1", "table1"),
EntityType.TABLE,
TableEntity.class));
+ Assertions.assertDoesNotThrow(
+ () ->
+ store.get(
+ NameIdentifier.of("metalake", "catalog", "schema1", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
}
}
@@ -222,11 +252,17 @@ public class TestKvEntityStorage {
createSchemaEntity(Namespace.of("metalake", "catalog"), "schema1", auditInfo);
TableEntity table1 =
createTableEntity(Namespace.of("metalake", "catalog", "schema1"), "table1", auditInfo);
+ FilesetEntity fileset1 =
+ createFilesetEntity(
+ Namespace.of("metalake", "catalog", "schema1"), "fileset1", auditInfo);
SchemaEntity schema2 =
createSchemaEntity(Namespace.of("metalake", "catalog"), "schema2", auditInfo);
TableEntity table1InSchema2 =
createTableEntity(Namespace.of("metalake", "catalog", "schema2"), "table1", auditInfo);
+ FilesetEntity fileset1InSchema2 =
+ createFilesetEntity(
+ Namespace.of("metalake", "catalog", "schema2"), "fileset1", auditInfo);
// Store all entities
store.put(metalake);
@@ -236,230 +272,340 @@ public class TestKvEntityStorage {
store.put(schema2);
store.put(table1);
store.put(table1InSchema2);
+ store.put(fileset1);
+ store.put(fileset1InSchema2);
+
+ validateMetalakeChanged(store, metalake);
+ validateCatalogChanged(store);
+ validateSchemaChanged(store);
+ validateTableChanged(store);
+ validateFilesetChanged(store);
+ validateDeletedTable(store);
+ validateDeletedFileset(store);
+ validateAlreadyExistEntity(store);
+ validateNotChangedEntity(store);
+ }
+ }
- // Try to check an update option is what we expected
- store.update(
- metalake.nameIdentifier(),
- BaseMetalake.class,
- EntityType.METALAKE,
- e -> {
- AuditInfo auditInfo1 =
- AuditInfo.builder().withCreator("creator1").withCreateTime(Instant.now()).build();
- return createBaseMakeLake("metalakeChanged", auditInfo1);
- });
-
- // Check metalake entity and sub-entities are already changed.
- BaseMetalake updatedMetalake =
- store.get(NameIdentifier.of("metalakeChanged"), EntityType.METALAKE, BaseMetalake.class);
- Assertions.assertEquals("creator1", updatedMetalake.auditInfo().creator());
-
- Assertions.assertThrowsExactly(
- NoSuchEntityException.class,
- () -> store.get(NameIdentifier.of("metalake"), EntityType.METALAKE, BaseMetalake.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalog"),
- EntityType.CATALOG,
- CatalogEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalog", "schema1"),
- EntityType.SCHEMA,
- SchemaEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalog", "schema1", "table1"),
- EntityType.TABLE,
- TableEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalog", "schema2"),
- EntityType.SCHEMA,
- SchemaEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalog", "schema1", "table1"),
- EntityType.TABLE,
- TableEntity.class));
+ private void validateDeletedFileset(EntityStore store) throws IOException {
+ store.delete(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "fileset1"),
+ EntityType.FILESET);
+ // Update a deleted entities
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class,
+ () ->
+ store.update(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "fileset1"),
+ FilesetEntity.class,
+ EntityType.FILESET,
+ (e) -> e));
+ }
- // Check catalog entities and sub-entities are already changed.
- store.update(
- NameIdentifier.of("metalakeChanged", "catalog"),
- CatalogEntity.class,
- EntityType.CATALOG,
- e -> {
- AuditInfo auditInfo1 =
- AuditInfo.builder().withCreator("creator2").withCreateTime(Instant.now()).build();
- return createCatalog(Namespace.of("metalakeChanged"), "catalogChanged", auditInfo1);
- });
- CatalogEntity updatedCatalog =
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged"),
- EntityType.CATALOG,
- CatalogEntity.class);
- Assertions.assertEquals("creator2", updatedCatalog.auditInfo().creator());
- Assertions.assertThrowsExactly(
- NoSuchEntityException.class,
- () ->
- store.get(
- NameIdentifier.of("metalakeChanged", "catalog"),
- EntityType.CATALOG,
- CatalogEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1"),
- EntityType.SCHEMA,
- SchemaEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1", "table1"),
- EntityType.TABLE,
- TableEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
- EntityType.SCHEMA,
- SchemaEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
- EntityType.TABLE,
- TableEntity.class));
+ private void validateFilesetChanged(EntityStore store) throws IOException {
+ // Check fileset entities
+ store.update(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged", "fileset1"),
+ FilesetEntity.class,
+ EntityType.FILESET,
+ e -> {
+ AuditInfo auditInfo1 =
+ AuditInfo.builder().withCreator("creator5").withCreateTime(Instant.now()).build();
+ return createFilesetEntity(
+ Namespace.of("metalakeChanged", "catalogChanged", "schemaChanged"),
+ "filesetChanged",
+ auditInfo1);
+ });
+
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class,
+ () ->
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
+ FilesetEntity updatedFileset =
+ store.get(
+ NameIdentifier.of(
+ "metalakeChanged", "catalogChanged", "schemaChanged", "filesetChanged"),
+ EntityType.FILESET,
+ FilesetEntity.class);
+ Assertions.assertEquals("creator5", updatedFileset.auditInfo().creator());
+
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
+ }
- // Check schema entities and sub-entities are already changed.
- store.update(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1"),
- SchemaEntity.class,
- EntityType.SCHEMA,
- e -> {
- AuditInfo auditInfo1 =
- AuditInfo.builder().withCreator("creator3").withCreateTime(Instant.now()).build();
- return createSchemaEntity(
- Namespace.of("metalakeChanged", "catalogChanged"), "schemaChanged", auditInfo1);
- });
+ private void validateNotChangedEntity(EntityStore store) throws IOException {
+ // Update operations do not contain any changes in name
+ store.update(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
+ SchemaEntity.class,
+ EntityType.SCHEMA,
+ e -> {
+ AuditInfo auditInfo1 =
+ AuditInfo.builder().withCreator("creator6").withCreateTime(Instant.now()).build();
+ return createSchemaEntity(
+ Namespace.of("metalakeChanged", "catalogChanged"), "schema2", auditInfo1);
+ });
+ Assertions.assertEquals(
+ "creator6",
+ store
+ .get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
+ EntityType.SCHEMA,
+ SchemaEntity.class)
+ .auditInfo()
+ .creator());
+ }
- Assertions.assertThrowsExactly(
- NoSuchEntityException.class,
- () ->
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1"),
- EntityType.SCHEMA,
- SchemaEntity.class));
- SchemaEntity updatedSchema =
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged"),
- EntityType.SCHEMA,
- SchemaEntity.class);
- Assertions.assertEquals("creator3", updatedSchema.auditInfo().creator());
+ private void validateAlreadyExistEntity(EntityStore store) {
+ // The updated entities already existed, should throw exception
+ Assertions.assertThrowsExactly(
+ AlreadyExistsException.class,
+ () ->
+ store.update(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
+ SchemaEntity.class,
+ EntityType.SCHEMA,
+ e -> {
+ AuditInfo auditInfo1 =
+ AuditInfo.builder()
+ .withCreator("creator5")
+ .withCreateTime(Instant.now())
+ .build();
+ return createSchemaEntity(
+ Namespace.of("metalakeChanged", "catalogChanged"),
+ "schemaChanged",
+ auditInfo1);
+ }));
+ }
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged"),
- EntityType.SCHEMA,
- SchemaEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged", "table1"),
- EntityType.TABLE,
- TableEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
- EntityType.SCHEMA,
- SchemaEntity.class));
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
- EntityType.TABLE,
- TableEntity.class));
+ private void validateMetalakeChanged(EntityStore store, BaseMetalake metalake)
+ throws IOException {
+ // Try to check an update option is what we expected
+ store.update(
+ metalake.nameIdentifier(),
+ BaseMetalake.class,
+ EntityType.METALAKE,
+ e -> {
+ AuditInfo auditInfo1 =
+ AuditInfo.builder().withCreator("creator1").withCreateTime(Instant.now()).build();
+ return createBaseMakeLake("metalakeChanged", auditInfo1);
+ });
+
+ // Check metalake entity and sub-entities are already changed.
+ BaseMetalake updatedMetalake =
+ store.get(NameIdentifier.of("metalakeChanged"), EntityType.METALAKE, BaseMetalake.class);
+ Assertions.assertEquals("creator1", updatedMetalake.auditInfo().creator());
+
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class,
+ () -> store.get(NameIdentifier.of("metalake"), EntityType.METALAKE, BaseMetalake.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalog"),
+ EntityType.CATALOG,
+ CatalogEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalog", "schema1"),
+ EntityType.SCHEMA,
+ SchemaEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalog", "schema1", "table1"),
+ EntityType.TABLE,
+ TableEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalog", "schema1", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalog", "schema2"),
+ EntityType.SCHEMA,
+ SchemaEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalog", "schema2", "table1"),
+ EntityType.TABLE,
+ TableEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalog", "schema2", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
+ }
- // Check table entities
- store.update(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged", "table1"),
- TableEntity.class,
- EntityType.TABLE,
- e -> {
- AuditInfo auditInfo1 =
- AuditInfo.builder().withCreator("creator4").withCreateTime(Instant.now()).build();
- return createTableEntity(
- Namespace.of("metalakeChanged", "catalogChanged", "schemaChanged"),
- "tableChanged",
- auditInfo1);
- });
+ private void validateCatalogChanged(EntityStore store) throws IOException {
+ // Check catalog entities and sub-entities are already changed.
+ store.update(
+ NameIdentifier.of("metalakeChanged", "catalog"),
+ CatalogEntity.class,
+ EntityType.CATALOG,
+ e -> {
+ AuditInfo auditInfo1 =
+ AuditInfo.builder().withCreator("creator2").withCreateTime(Instant.now()).build();
+ return createCatalog(Namespace.of("metalakeChanged"), "catalogChanged", auditInfo1);
+ });
+ CatalogEntity updatedCatalog =
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged"),
+ EntityType.CATALOG,
+ CatalogEntity.class);
+ Assertions.assertEquals("creator2", updatedCatalog.auditInfo().creator());
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class,
+ () ->
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalog"),
+ EntityType.CATALOG,
+ CatalogEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1"),
+ EntityType.SCHEMA,
+ SchemaEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1", "table1"),
+ EntityType.TABLE,
+ TableEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
+ EntityType.SCHEMA,
+ SchemaEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
+ EntityType.TABLE,
+ TableEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
+ }
- Assertions.assertThrowsExactly(
- NoSuchEntityException.class,
- () ->
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1", "table1"),
- EntityType.TABLE,
- TableEntity.class));
- TableEntity updatedTable =
- store.get(
- NameIdentifier.of(
- "metalakeChanged", "catalogChanged", "schemaChanged", "tableChanged"),
- EntityType.TABLE,
- TableEntity.class);
- Assertions.assertEquals("creator4", updatedTable.auditInfo().creator());
+ private void validateSchemaChanged(EntityStore store) throws IOException {
+ // Check schema entities and sub-entities are already changed.
+ store.update(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1"),
+ SchemaEntity.class,
+ EntityType.SCHEMA,
+ e -> {
+ AuditInfo auditInfo1 =
+ AuditInfo.builder().withCreator("creator3").withCreateTime(Instant.now()).build();
+ return createSchemaEntity(
+ Namespace.of("metalakeChanged", "catalogChanged"), "schemaChanged", auditInfo1);
+ });
+
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class,
+ () ->
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1"),
+ EntityType.SCHEMA,
+ SchemaEntity.class));
+ SchemaEntity updatedSchema =
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged"),
+ EntityType.SCHEMA,
+ SchemaEntity.class);
+ Assertions.assertEquals("creator3", updatedSchema.auditInfo().creator());
+
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged"),
+ EntityType.SCHEMA,
+ SchemaEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged", "table1"),
+ EntityType.TABLE,
+ TableEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
+ EntityType.SCHEMA,
+ SchemaEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
+ EntityType.TABLE,
+ TableEntity.class));
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "fileset1"),
+ EntityType.FILESET,
+ FilesetEntity.class));
+ }
- Assertions.assertNotNull(
- store.get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
- EntityType.TABLE,
- TableEntity.class));
+ private void validateTableChanged(EntityStore store) throws IOException {
+ // Check table entities
+ store.update(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged", "table1"),
+ TableEntity.class,
+ EntityType.TABLE,
+ e -> {
+ AuditInfo auditInfo1 =
+ AuditInfo.builder().withCreator("creator4").withCreateTime(Instant.now()).build();
+ return createTableEntity(
+ Namespace.of("metalakeChanged", "catalogChanged", "schemaChanged"),
+ "tableChanged",
+ auditInfo1);
+ });
+
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class,
+ () ->
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema1", "table1"),
+ EntityType.TABLE,
+ TableEntity.class));
+ TableEntity updatedTable =
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schemaChanged", "tableChanged"),
+ EntityType.TABLE,
+ TableEntity.class);
+ Assertions.assertEquals("creator4", updatedTable.auditInfo().creator());
+
+ Assertions.assertNotNull(
+ store.get(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
+ EntityType.TABLE,
+ TableEntity.class));
+ }
- store.delete(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
- EntityType.TABLE);
- // Update a deleted entities
- Assertions.assertThrowsExactly(
- NoSuchEntityException.class,
- () ->
- store.update(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
- TableEntity.class,
- EntityType.TABLE,
- (e) -> e));
- // The updated entities already existed, should throw exception
- Assertions.assertThrowsExactly(
- AlreadyExistsException.class,
- () ->
- store.update(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
- SchemaEntity.class,
- EntityType.SCHEMA,
- e -> {
- AuditInfo auditInfo1 =
- AuditInfo.builder()
- .withCreator("creator5")
- .withCreateTime(Instant.now())
- .build();
- return createSchemaEntity(
- Namespace.of("metalakeChanged", "catalogChanged"),
- "schemaChanged",
- auditInfo1);
- }));
- // Update operations do not contain any changes in name
- store.update(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
- SchemaEntity.class,
- EntityType.SCHEMA,
- e -> {
- AuditInfo auditInfo1 =
- AuditInfo.builder().withCreator("creator6").withCreateTime(Instant.now()).build();
- return createSchemaEntity(
- Namespace.of("metalakeChanged", "catalogChanged"), "schema2", auditInfo1);
- });
- Assertions.assertEquals(
- "creator6",
- store
- .get(
- NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"),
- EntityType.SCHEMA,
- SchemaEntity.class)
- .auditInfo()
- .creator());
- }
+ private void validateDeletedTable(EntityStore store) throws IOException {
+ store.delete(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
+ EntityType.TABLE);
+ // Update a deleted entities
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class,
+ () ->
+ store.update(
+ NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2", "table1"),
+ TableEntity.class,
+ EntityType.TABLE,
+ (e) -> e));
}
@Test
@@ -491,11 +637,17 @@ public class TestKvEntityStorage {
createSchemaEntity(Namespace.of("metalake", "catalog"), "schema1", auditInfo);
TableEntity table1 =
createTableEntity(Namespace.of("metalake", "catalog", "schema1"), "table1", auditInfo);
+ FilesetEntity fileset1 =
+ createFilesetEntity(
+ Namespace.of("metalake", "catalog", "schema1"), "fileset1", auditInfo);
SchemaEntity schema2 =
createSchemaEntity(Namespace.of("metalake", "catalog"), "schema2", auditInfo);
TableEntity table1InSchema2 =
createTableEntity(Namespace.of("metalake", "catalog", "schema2"), "table1", auditInfo);
+ FilesetEntity fileset1InSchema2 =
+ createFilesetEntity(
+ Namespace.of("metalake", "catalog", "schema2"), "fileset1", auditInfo);
// Store all entities
store.put(metalake);
@@ -505,84 +657,31 @@ public class TestKvEntityStorage {
store.put(schema2);
store.put(table1);
store.put(table1InSchema2);
+ store.put(fileset1);
+ store.put(fileset1InSchema2);
- // Now try to get
- Assertions.assertEquals(
- metalake, store.get(metalake.nameIdentifier(), EntityType.METALAKE, BaseMetalake.class));
- Assertions.assertEquals(
- catalog, store.get(catalog.nameIdentifier(), EntityType.CATALOG, CatalogEntity.class));
- Assertions.assertEquals(
+ validateAllEntityExist(
+ metalake,
+ store,
+ catalog,
catalogCopy,
- store.get(catalogCopy.nameIdentifier(), EntityType.CATALOG, CatalogEntity.class));
- Assertions.assertEquals(
- schema1, store.get(schema1.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
- Assertions.assertEquals(
- schema2, store.get(schema2.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
- Assertions.assertEquals(
- table1, store.get(table1.nameIdentifier(), EntityType.TABLE, TableEntity.class));
- Assertions.assertEquals(
+ schema1,
+ schema2,
+ table1,
table1InSchema2,
- store.get(table1InSchema2.nameIdentifier(), EntityType.TABLE, TableEntity.class));
+ fileset1,
+ fileset1InSchema2);
- // Delete the table 'metalake.catalog.schema2.table1'
- Assertions.assertTrue(store.delete(table1InSchema2.nameIdentifier(), EntityType.TABLE));
- Assertions.assertFalse(store.exists(table1InSchema2.nameIdentifier(), EntityType.TABLE));
- // Make sure table 'metalake.catalog.schema1.table1' still exist;
- Assertions.assertEquals(
- table1, store.get(table1.nameIdentifier(), EntityType.TABLE, TableEntity.class));
- // Make sure schema 'metalake.catalog.schema2' still exist;
- Assertions.assertEquals(
- schema2, store.get(schema2.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
- // Re-insert table1Inschema2 and everything is OK
- store.put(table1InSchema2);
- Assertions.assertTrue(store.exists(table1InSchema2.nameIdentifier(), EntityType.TABLE));
-
- // Delete the schema 'metalake.catalog.schema1' but failed, because it ha sub-entities;
- NonEmptyEntityException exception =
- Assertions.assertThrowsExactly(
- NonEmptyEntityException.class,
- () -> store.delete(schema1.nameIdentifier(), EntityType.SCHEMA));
- Assertions.assertTrue(exception.getMessage().contains("metalake.catalog.schema1.table1"));
- // Make sure schema 'metalake.catalog.schema1' and table 'metalake.catalog.schema1.table1'
- // has not been deleted yet;
- Assertions.assertTrue(store.exists(schema1.nameIdentifier(), EntityType.SCHEMA));
- Assertions.assertTrue(store.exists(table1.nameIdentifier(), EntityType.TABLE));
-
- // Delete table1 and schema1
- Assertions.assertTrue(store.delete(table1.nameIdentifier(), EntityType.TABLE));
- Assertions.assertTrue(store.delete(schema1.nameIdentifier(), EntityType.SCHEMA));
- // Make sure table1 in 'metalake.catalog.schema1' can't be access;
- Assertions.assertFalse(store.exists(table1.nameIdentifier(), EntityType.TABLE));
- Assertions.assertFalse(store.exists(schema1.nameIdentifier(), EntityType.SCHEMA));
- // Now we re-insert table1 and schema1, and everything should be OK
- store.put(schema1);
- store.put(table1);
- Assertions.assertEquals(
- schema1, store.get(schema1.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
- Assertions.assertEquals(
- table1, store.get(table1.nameIdentifier(), EntityType.TABLE, TableEntity.class));
+ validateDeleteTable(store, schema2, table1, table1InSchema2);
- // Now try to delete all schemas under catalog;
- Assertions.assertThrowsExactly(
- NonEmptyEntityException.class,
- () -> store.delete(catalog.nameIdentifier(), EntityType.CATALOG));
- store.delete(table1.nameIdentifier(), EntityType.TABLE);
- store.delete(schema1.nameIdentifier(), EntityType.SCHEMA);
- store.delete(table1InSchema2.nameIdentifier(), EntityType.TABLE);
- store.delete(schema2.nameIdentifier(), EntityType.SCHEMA);
+ validateDeleteFileset(store, schema2, fileset1, fileset1InSchema2);
- store.delete(catalog.nameIdentifier(), EntityType.CATALOG);
- Assertions.assertFalse(store.exists(catalog.nameIdentifier(), EntityType.CATALOG));
+ validateDeleteSchema(store, schema1, table1, fileset1);
- // Now delete catalog 'catalogCopy' and metalake
- Assertions.assertThrowsExactly(
- NonEmptyEntityException.class,
- () -> store.delete(metalake.nameIdentifier(), EntityType.METALAKE));
- store.delete(catalogCopy.nameIdentifier(), EntityType.CATALOG);
- Assertions.assertFalse(store.exists(catalogCopy.nameIdentifier(), EntityType.CATALOG));
+ validateDeleteCatalog(
+ store, catalog, table1, schema1, table1InSchema2, schema2, fileset1, fileset1InSchema2);
- store.delete(metalake.nameIdentifier(), EntityType.METALAKE);
- Assertions.assertFalse(store.exists(metalake.nameIdentifier(), EntityType.METALAKE));
+ validateDeleteMetalake(store, metalake, catalogCopy);
// Store all entities again
store.put(metalake);
@@ -592,43 +691,231 @@ public class TestKvEntityStorage {
store.put(schema2);
store.put(table1);
store.put(table1InSchema2);
+ store.put(fileset1);
+ store.put(fileset1InSchema2);
- Assertions.assertThrowsExactly(
- NonEmptyEntityException.class,
- () -> store.delete(schema1.nameIdentifier(), EntityType.SCHEMA));
+ validateDeleteTableCascade(store, table1);
- Assertions.assertEquals(
- schema1, store.get(schema1.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
-
- // Test cascade delete
- store.delete(schema1.nameIdentifier(), EntityType.SCHEMA, true);
- try {
- store.get(table1.nameIdentifier(), EntityType.TABLE, TableEntity.class);
- } catch (Exception e) {
- Assertions.assertTrue(e instanceof NoSuchEntityException);
- Assertions.assertTrue(e.getMessage().contains("metalake.catalog.schema1"));
- }
+ validateDeleteFilesetCascade(store, fileset1);
- Assertions.assertThrowsExactly(
- NonEmptyEntityException.class,
- () -> store.delete(catalog.nameIdentifier(), EntityType.CATALOG));
- store.delete(catalog.nameIdentifier(), EntityType.CATALOG, true);
- NameIdentifier id = catalog.nameIdentifier();
- Assertions.assertThrowsExactly(
- NoSuchEntityException.class,
- () -> store.get(id, EntityType.CATALOG, CatalogEntity.class));
+ validateDeleteSchemaCascade(store, schema1, table1, fileset1);
- Assertions.assertThrowsExactly(
- NoSuchEntityException.class,
- () -> store.get(schema2.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
+ validateDeleteCatalogCascade(store, catalog, schema2);
+
+ validateDeleteMetalakeCascade(store, metalake, catalog, schema2);
+ }
+ }
+
+ private void validateDeleteFilesetCascade(EntityStore store, FilesetEntity fileset1)
+ throws IOException {
+ // Delete the fileset 'metalake.catalog.schema1.fileset1'
+ Assertions.assertTrue(store.delete(fileset1.nameIdentifier(), EntityType.FILESET, true));
+ Assertions.assertFalse(store.exists(fileset1.nameIdentifier(), EntityType.FILESET));
+ }
+
+ private void validateDeleteTableCascade(EntityStore store, TableEntity table1)
+ throws IOException {
+ // Delete the table 'metalake.catalog.schema1.table1'
+ Assertions.assertTrue(store.delete(table1.nameIdentifier(), EntityType.TABLE, true));
+ Assertions.assertFalse(store.exists(table1.nameIdentifier(), EntityType.TABLE));
+ }
- Assertions.assertTrue(store.delete(metalake.nameIdentifier(), EntityType.METALAKE, true));
+ private void validateDeleteFileset(
+ EntityStore store,
+ SchemaEntity schema2,
+ FilesetEntity fileset1,
+ FilesetEntity fileset1InSchema2)
+ throws IOException {
+ // Delete the fileset 'metalake.catalog.schema2.fileset1'
+ Assertions.assertTrue(store.delete(fileset1InSchema2.nameIdentifier(), EntityType.FILESET));
+ Assertions.assertFalse(store.exists(fileset1InSchema2.nameIdentifier(), EntityType.FILESET));
+
+ // Make sure fileset 'metalake.catalog.schema1.fileset1' still exist;
+ Assertions.assertEquals(
+ fileset1, store.get(fileset1.nameIdentifier(), EntityType.FILESET, FilesetEntity.class));
+ // Make sure schema 'metalake.catalog.schema2' still exist;
+ Assertions.assertEquals(
+ schema2, store.get(schema2.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
+ }
+
+ private void validateDeleteMetalakeCascade(
+ EntityStore store, BaseMetalake metalake, CatalogEntity catalog, SchemaEntity schema2)
+ throws IOException {
+ Assertions.assertTrue(store.delete(metalake.nameIdentifier(), EntityType.METALAKE, true));
+
+ // catalog has already deleted, so we can't delete it again and should return false
+ Assertions.assertFalse(store.delete(catalog.nameIdentifier(), EntityType.CATALOG));
+ Assertions.assertFalse(store.delete(schema2.nameIdentifier(), EntityType.SCHEMA));
+ Assertions.assertFalse(store.delete(metalake.nameIdentifier(), EntityType.METALAKE));
+ }
+
+ private void validateDeleteCatalogCascade(
+ EntityStore store, CatalogEntity catalog, SchemaEntity schema2) throws IOException {
+ Assertions.assertThrowsExactly(
+ NonEmptyEntityException.class,
+ () -> store.delete(catalog.nameIdentifier(), EntityType.CATALOG));
+ store.delete(catalog.nameIdentifier(), EntityType.CATALOG, true);
+ NameIdentifier id = catalog.nameIdentifier();
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class, () -> store.get(id, EntityType.CATALOG, CatalogEntity.class));
+
+ Assertions.assertThrowsExactly(
+ NoSuchEntityException.class,
+ () -> store.get(schema2.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
+ }
+
+ private void validateDeleteSchemaCascade(
+ EntityStore store, SchemaEntity schema1, TableEntity table1, FilesetEntity fileset1)
+ throws IOException {
+ store.put(table1);
+ store.put(fileset1);
+
+ Assertions.assertThrowsExactly(
+ NonEmptyEntityException.class,
+ () -> store.delete(schema1.nameIdentifier(), EntityType.SCHEMA));
- // catalog has already deleted, so we can't delete it again and should return false
- Assertions.assertFalse(store.delete(catalog.nameIdentifier(), EntityType.CATALOG));
- Assertions.assertFalse(store.delete(schema2.nameIdentifier(), EntityType.SCHEMA));
- Assertions.assertFalse(store.delete(metalake.nameIdentifier(), EntityType.METALAKE));
+ Assertions.assertEquals(
+ schema1, store.get(schema1.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
+
+ // Test cascade delete
+ store.delete(schema1.nameIdentifier(), EntityType.SCHEMA, true);
+ try {
+ store.get(table1.nameIdentifier(), EntityType.TABLE, TableEntity.class);
+ } catch (Exception e) {
+ Assertions.assertTrue(e instanceof NoSuchEntityException);
+ Assertions.assertTrue(e.getMessage().contains("metalake.catalog.schema1"));
}
+
+ Assertions.assertThrows(
+ NoSuchEntityException.class,
+ () -> store.get(fileset1.nameIdentifier(), EntityType.FILESET, FilesetEntity.class));
+ }
+
+ private static void validateDeleteMetalake(
+ EntityStore store, BaseMetalake metalake, CatalogEntity catalogCopy) throws IOException {
+ // Now delete catalog 'catalogCopy' and metalake
+ Assertions.assertThrowsExactly(
+ NonEmptyEntityException.class,
+ () -> store.delete(metalake.nameIdentifier(), EntityType.METALAKE));
+ store.delete(catalogCopy.nameIdentifier(), EntityType.CATALOG);
+ Assertions.assertFalse(store.exists(catalogCopy.nameIdentifier(), EntityType.CATALOG));
+
+ store.delete(metalake.nameIdentifier(), EntityType.METALAKE);
+ Assertions.assertFalse(store.exists(metalake.nameIdentifier(), EntityType.METALAKE));
+ }
+
+ private static void validateDeleteCatalog(
+ EntityStore store,
+ CatalogEntity catalog,
+ TableEntity table1,
+ SchemaEntity schema1,
+ TableEntity table1InSchema2,
+ SchemaEntity schema2,
+ FilesetEntity fileset1,
+ FilesetEntity fileset1InSchema2)
+ throws IOException {
+ // Now try to delete all schemas under catalog;
+ Assertions.assertThrowsExactly(
+ NonEmptyEntityException.class,
+ () -> store.delete(catalog.nameIdentifier(), EntityType.CATALOG));
+ store.delete(table1.nameIdentifier(), EntityType.TABLE);
+ store.delete(fileset1.nameIdentifier(), EntityType.FILESET);
+ store.delete(schema1.nameIdentifier(), EntityType.SCHEMA);
+ store.delete(table1InSchema2.nameIdentifier(), EntityType.TABLE);
+ store.delete(fileset1InSchema2.nameIdentifier(), EntityType.FILESET);
+ store.delete(schema2.nameIdentifier(), EntityType.SCHEMA);
+
+ store.delete(catalog.nameIdentifier(), EntityType.CATALOG);
+ Assertions.assertFalse(store.exists(catalog.nameIdentifier(), EntityType.CATALOG));
+ }
+
+ private static void validateDeleteSchema(
+ EntityStore store, SchemaEntity schema1, TableEntity table1, FilesetEntity fileset1)
+ throws IOException {
+ // Delete the schema 'metalake.catalog.schema1' but failed, because it ha sub-entities;
+ NonEmptyEntityException exception =
+ Assertions.assertThrowsExactly(
+ NonEmptyEntityException.class,
+ () -> store.delete(schema1.nameIdentifier(), EntityType.SCHEMA));
+ Assertions.assertTrue(exception.getMessage().contains("metalake.catalog.schema1.table1"));
+ // Make sure schema 'metalake.catalog.schema1' and table 'metalake.catalog.schema1.table1'
+ // and table 'metalake.catalog.schema1.fileset1' has not been deleted yet;
+ Assertions.assertTrue(store.exists(schema1.nameIdentifier(), EntityType.SCHEMA));
+ Assertions.assertTrue(store.exists(table1.nameIdentifier(), EntityType.TABLE));
+ Assertions.assertTrue(store.exists(fileset1.nameIdentifier(), EntityType.FILESET));
+
+ // Delete table1,fileset1 and schema1
+ Assertions.assertTrue(store.delete(table1.nameIdentifier(), EntityType.TABLE));
+ Assertions.assertTrue(store.delete(fileset1.nameIdentifier(), EntityType.FILESET));
+ Assertions.assertTrue(store.delete(schema1.nameIdentifier(), EntityType.SCHEMA));
+ // Make sure table1, fileset1 in 'metalake.catalog.schema1' can't be access;
+ Assertions.assertFalse(store.exists(table1.nameIdentifier(), EntityType.TABLE));
+ Assertions.assertFalse(store.exists(fileset1.nameIdentifier(), EntityType.FILESET));
+ Assertions.assertFalse(store.exists(schema1.nameIdentifier(), EntityType.SCHEMA));
+ // Now we re-insert table1 and schema1, and everything should be OK
+ store.put(schema1);
+ store.put(table1);
+ store.put(fileset1);
+ Assertions.assertEquals(
+ schema1, store.get(schema1.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
+ Assertions.assertEquals(
+ table1, store.get(table1.nameIdentifier(), EntityType.TABLE, TableEntity.class));
+ Assertions.assertEquals(
+ fileset1, store.get(fileset1.nameIdentifier(), EntityType.FILESET, FilesetEntity.class));
+ }
+
+ private void validateDeleteTable(
+ EntityStore store, SchemaEntity schema2, TableEntity table1, TableEntity table1InSchema2)
+ throws IOException {
+ // Delete the table 'metalake.catalog.schema2.table1'
+ Assertions.assertTrue(store.delete(table1InSchema2.nameIdentifier(), EntityType.TABLE));
+ Assertions.assertFalse(store.exists(table1InSchema2.nameIdentifier(), EntityType.TABLE));
+
+ // Make sure table 'metalake.catalog.schema1.table1' still exist;
+ Assertions.assertEquals(
+ table1, store.get(table1.nameIdentifier(), EntityType.TABLE, TableEntity.class));
+ // Make sure schema 'metalake.catalog.schema2' still exist;
+ Assertions.assertEquals(
+ schema2, store.get(schema2.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
+ // Re-insert table1Inschema2 and everything is OK
+ store.put(table1InSchema2);
+ Assertions.assertTrue(store.exists(table1InSchema2.nameIdentifier(), EntityType.TABLE));
+ }
+
+ private static void validateAllEntityExist(
+ BaseMetalake metalake,
+ EntityStore store,
+ CatalogEntity catalog,
+ CatalogEntity catalogCopy,
+ SchemaEntity schema1,
+ SchemaEntity schema2,
+ TableEntity table1,
+ TableEntity table1InSchema2,
+ FilesetEntity fileset1,
+ FilesetEntity fileset1Inschema2)
+ throws IOException {
+ // Now try to get
+ Assertions.assertEquals(
+ metalake, store.get(metalake.nameIdentifier(), EntityType.METALAKE, BaseMetalake.class));
+ Assertions.assertEquals(
+ catalog, store.get(catalog.nameIdentifier(), EntityType.CATALOG, CatalogEntity.class));
+ Assertions.assertEquals(
+ catalogCopy,
+ store.get(catalogCopy.nameIdentifier(), EntityType.CATALOG, CatalogEntity.class));
+ Assertions.assertEquals(
+ schema1, store.get(schema1.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
+ Assertions.assertEquals(
+ schema2, store.get(schema2.nameIdentifier(), EntityType.SCHEMA, SchemaEntity.class));
+ Assertions.assertEquals(
+ table1, store.get(table1.nameIdentifier(), EntityType.TABLE, TableEntity.class));
+ Assertions.assertEquals(
+ table1InSchema2,
+ store.get(table1InSchema2.nameIdentifier(), EntityType.TABLE, TableEntity.class));
+ Assertions.assertEquals(
+ fileset1, store.get(fileset1.nameIdentifier(), EntityType.FILESET, FilesetEntity.class));
+ Assertions.assertEquals(
+ fileset1Inschema2,
+ store.get(fileset1Inschema2.nameIdentifier(), EntityType.FILESET, FilesetEntity.class));
}
@Test
@@ -1012,6 +1299,31 @@ public class TestKvEntityStorage {
e ->
createTableEntity(
Namespace.of("metalake1", "catalog2", "schema2"), "table2", e.auditInfo()));
+
+ // Test Fileset
+ FilesetEntity fileset1 =
+ createFilesetEntity(
+ Namespace.of("metalake1", "catalog2", "schema2"), "fileset1", auditInfo);
+ FilesetEntity fileset2 =
+ createFilesetEntity(
+ Namespace.of("metalake1", "catalog2", "schema2"), "fileset2", auditInfo);
+
+ store.put(fileset1);
+ store.put(fileset2);
+
+ store.delete(
+ NameIdentifier.of("metalake1", "catalog2", "schema2", "fileset1"), EntityType.FILESET);
+ store.delete(
+ NameIdentifier.of("metalake1", "catalog2", "schema2", "fileset2"), EntityType.FILESET);
+
+ store.put(fileset1);
+ store.update(
+ NameIdentifier.of("metalake1", "catalog2", "schema2", "fileset1"),
+ FilesetEntity.class,
+ EntityType.FILESET,
+ e ->
+ createFilesetEntity(
+ Namespace.of("metalake1", "catalog2", "schema2"), "fileset2", e.auditInfo()));
}
}
diff --git a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestKvGarbageCollector.java b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestKvGarbageCollector.java
index 2e91436553..c1771d7dfd 100644
--- a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestKvGarbageCollector.java
+++ b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestKvGarbageCollector.java
@@ -13,6 +13,7 @@ import static com.datastrato.gravitino.Configs.KV_DELETE_AFTER_TIME;
import static com.datastrato.gravitino.Configs.STORE_TRANSACTION_MAX_SKEW_TIME;
import static com.datastrato.gravitino.storage.kv.TestKvEntityStorage.createBaseMakeLake;
import static com.datastrato.gravitino.storage.kv.TestKvEntityStorage.createCatalog;
+import static com.datastrato.gravitino.storage.kv.TestKvEntityStorage.createFilesetEntity;
import static com.datastrato.gravitino.storage.kv.TestKvEntityStorage.createSchemaEntity;
import static com.datastrato.gravitino.storage.kv.TestKvEntityStorage.createTableEntity;
@@ -26,6 +27,7 @@ import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.meta.AuditInfo;
import com.datastrato.gravitino.meta.BaseMetalake;
import com.datastrato.gravitino.meta.CatalogEntity;
+import com.datastrato.gravitino.meta.FilesetEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.meta.TableEntity;
import com.datastrato.gravitino.storage.TransactionIdGenerator;
@@ -175,11 +177,15 @@ class TestKvGarbageCollector {
createSchemaEntity(Namespace.of("metalake1", "catalog1"), "schema1", auditInfo);
TableEntity tableEntity =
createTableEntity(Namespace.of("metalake1", "catalog1", "schema1"), "table1", auditInfo);
+ FilesetEntity filesetEntity =
+ createFilesetEntity(
+ Namespace.of("metalake1", "catalog1", "schema1"), "fileset1", auditInfo);
kvEntityStore.put(metalake1);
kvEntityStore.put(catalog);
kvEntityStore.put(schemaEntity);
kvEntityStore.put(tableEntity);
+ kvEntityStore.put(filesetEntity);
// now try to scan raw data from kv store
KvBackend kvBackend = kvEntityStore.backend;
@@ -192,7 +198,7 @@ class TestKvGarbageCollector {
.endInclusive(false)
.build());
- Assertions.assertEquals(4, data.size());
+ Assertions.assertEquals(5, data.size());
KvGarbageCollector kvGarbageCollector = kvEntityStore.kvGarbageCollector;
for (Pair<byte[], byte[]> pair : data) {
@@ -215,6 +221,11 @@ class TestKvGarbageCollector {
Assertions.assertEquals(
NameIdentifier.of("metalake1", "catalog1", "schema1", "table1"), helper.identifier);
break;
+ case FILESET:
+ Assertions.assertEquals(
+ NameIdentifier.of("metalake1", "catalog1", "schema1", "fileset1"),
+ helper.identifier);
+ break;
default:
Assertions.fail();
}
diff --git a/integration-test/build.gradle.kts b/integration-test/build.gradle.kts
index 4a42bef7e2..952469e33b 100644
--- a/integration-test/build.gradle.kts
+++ b/integration-test/build.gradle.kts
@@ -25,6 +25,7 @@ dependencies {
implementation(project(":catalogs:catalog-jdbc-mysql"))
implementation(project(":catalogs:catalog-jdbc-postgresql"))
implementation(project(":catalogs:catalog-lakehouse-iceberg"))
+ implementation(project(":catalogs:catalog-hadoop"))
implementation(project(":clients:client-java"))
implementation(project(":common"))
implementation(project(":core"))
diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/fileset/CatalogFilesetIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/fileset/CatalogFilesetIT.java
new file mode 100644
index 0000000000..2e6cfe7652
--- /dev/null
+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/fileset/CatalogFilesetIT.java
@@ -0,0 +1,562 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.integration.test.catalog.fileset;
+
+import com.datastrato.gravitino.Catalog;
+import com.datastrato.gravitino.NameIdentifier;
+import com.datastrato.gravitino.Namespace;
+import com.datastrato.gravitino.catalog.hive.HiveSchemaPropertiesMetadata;
+import com.datastrato.gravitino.client.GravitinoMetaLake;
+import com.datastrato.gravitino.exceptions.FilesetAlreadyExistsException;
+import com.datastrato.gravitino.exceptions.NoSuchFilesetException;
+import com.datastrato.gravitino.file.Fileset;
+import com.datastrato.gravitino.file.FilesetChange;
+import com.datastrato.gravitino.integration.test.container.ContainerSuite;
+import com.datastrato.gravitino.integration.test.container.HiveContainer;
+import com.datastrato.gravitino.integration.test.util.AbstractIT;
+import com.datastrato.gravitino.integration.test.util.GravitinoITUtils;
+import com.datastrato.gravitino.rel.Schema;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Tag("gravitino-docker-it")
+public class CatalogFilesetIT extends AbstractIT {
+ private static final Logger LOG = LoggerFactory.getLogger(CatalogFilesetIT.class);
+ private static final ContainerSuite containerSuite = ContainerSuite.getInstance();
+
+ public static final String metalakeName =
+ GravitinoITUtils.genRandomName("CatalogFilesetIT_metalake");
+ public static final String catalogName =
+ GravitinoITUtils.genRandomName("CatalogFilesetIT_catalog");
+ public static final String SCHEMA_PREFIX = "CatalogFilesetIT_schema";
+ public static final String schemaName = GravitinoITUtils.genRandomName(SCHEMA_PREFIX);
+ private static final String provider = "hadoop";
+ private static GravitinoMetaLake metalake;
+ private static Catalog catalog;
+ private static FileSystem hdfs;
+ private static String defaultBaseLocation;
+
+ @BeforeAll
+ public static void setup() throws IOException {
+ containerSuite.startHiveContainer();
+
+ Configuration conf = new Configuration();
+ conf.set("fs.defaultFS", defaultBaseLocation());
+ hdfs = FileSystem.get(conf);
+
+ createMetalake();
+ createCatalog();
+ createSchema();
+ }
+
+ @AfterAll
+ public static void stop() throws IOException {
+ client.dropMetalake(NameIdentifier.of(metalakeName));
+
+ if (hdfs != null) {
+ hdfs.close();
+ }
+
+ try {
+ closer.close();
+ } catch (Exception e) {
+ LOG.error("Failed to close CloseableGroup", e);
+ }
+ }
+
+ private static void createMetalake() {
+ GravitinoMetaLake[] gravitinoMetaLakes = client.listMetalakes();
+ Assertions.assertEquals(0, gravitinoMetaLakes.length);
+
+ GravitinoMetaLake createdMetalake =
+ client.createMetalake(NameIdentifier.of(metalakeName), "comment", Collections.emptyMap());
+ GravitinoMetaLake loadMetalake = client.loadMetalake(NameIdentifier.of(metalakeName));
+ Assertions.assertEquals(createdMetalake, loadMetalake);
+
+ metalake = loadMetalake;
+ }
+
+ private static void createCatalog() {
+ metalake.createCatalog(
+ NameIdentifier.of(metalakeName, catalogName),
+ Catalog.Type.FILESET,
+ provider,
+ "comment",
+ ImmutableMap.of());
+
+ catalog = metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName));
+ }
+
+ private static void createSchema() {
+ NameIdentifier ident = NameIdentifier.of(metalakeName, catalogName, schemaName);
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put("key1", "val1");
+ properties.put("key2", "val2");
+ properties.put("location", defaultBaseLocation());
+ String comment = "comment";
+
+ catalog.asSchemas().createSchema(ident, comment, properties);
+ Schema loadSchema = catalog.asSchemas().loadSchema(ident);
+ Assertions.assertEquals(schemaName, loadSchema.name());
+ Assertions.assertEquals(comment, loadSchema.comment());
+ Assertions.assertEquals("val1", loadSchema.properties().get("key1"));
+ Assertions.assertEquals("val2", loadSchema.properties().get("key2"));
+ Assertions.assertNotNull(loadSchema.properties().get(HiveSchemaPropertiesMetadata.LOCATION));
+ }
+
+ private static void dropSchema() {
+ NameIdentifier ident = NameIdentifier.of(metalakeName, catalogName, schemaName);
+ catalog.asSchemas().dropSchema(ident, true);
+ Assertions.assertFalse(catalog.asSchemas().schemaExists(ident));
+ }
+
+ @Test
+ public void testCreateFileset() throws IOException {
+ // create fileset
+ String filesetName = "test_create_fileset";
+ String storageLocation = storageLocation(filesetName);
+ Assertions.assertFalse(
+ hdfs.exists(new Path(storageLocation)), "storage location should not exists");
+ Fileset fileset =
+ createFileset(
+ filesetName,
+ "comment",
+ Fileset.Type.MANAGED,
+ storageLocation,
+ ImmutableMap.of("k1", "v1"));
+
+ // verify fileset is created
+ assertFilesetExists(filesetName);
+ Assertions.assertNotNull(fileset, "fileset should be created");
+ Assertions.assertEquals("comment", fileset.comment());
+ Assertions.assertEquals(Fileset.Type.MANAGED, fileset.type());
+ Assertions.assertEquals(storageLocation, fileset.storageLocation());
+ Assertions.assertEquals(1, fileset.properties().size());
+ Assertions.assertEquals("v1", fileset.properties().get("k1"));
+
+ // test create a fileset that already exist
+ Assertions.assertThrows(
+ FilesetAlreadyExistsException.class,
+ () ->
+ createFileset(
+ filesetName,
+ "comment",
+ Fileset.Type.MANAGED,
+ storageLocation,
+ ImmutableMap.of("k1", "v1")),
+ "Should throw FilesetAlreadyExistsException when fileset already exists");
+
+ // create fileset with null storage location
+ String filesetName2 = "test_create_fileset_no_storage_location";
+ Fileset fileset2 = createFileset(filesetName2, null, Fileset.Type.MANAGED, null, null);
+ assertFilesetExists(filesetName2);
+ Assertions.assertNotNull(fileset2, "fileset should be created");
+ Assertions.assertNull(fileset2.comment(), "comment should be null");
+ Assertions.assertEquals(Fileset.Type.MANAGED, fileset2.type(), "type should be MANAGED");
+ Assertions.assertEquals(
+ storageLocation(filesetName2),
+ fileset2.storageLocation(),
+ "storage location should be created");
+ Assertions.assertEquals(ImmutableMap.of(), fileset2.properties(), "properties should be empty");
+
+ // create fileset with null fileset name
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ createFileset(
+ null,
+ "comment",
+ Fileset.Type.MANAGED,
+ storageLocation,
+ ImmutableMap.of("k1", "v1")),
+ "Should throw IllegalArgumentException when fileset name is null");
+
+ // create fileset with null fileset type
+ String filesetName3 = "test_create_fileset_no_type";
+ String storageLocation3 = storageLocation(filesetName3);
+ Fileset fileset3 =
+ createFileset(filesetName3, "comment", null, storageLocation3, ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName3);
+ Assertions.assertEquals(
+ Fileset.Type.MANAGED, fileset3.type(), "fileset type should be MANAGED by default");
+ }
+
+ @Test
+ public void testExternalFileset() throws IOException {
+ // create fileset
+ String filesetName = "test_external_fileset";
+ String storageLocation = storageLocation(filesetName);
+ Fileset fileset =
+ createFileset(
+ filesetName,
+ "comment",
+ Fileset.Type.EXTERNAL,
+ storageLocation,
+ ImmutableMap.of("k1", "v1"));
+
+ // verify fileset is created
+ assertFilesetExists(filesetName);
+ Assertions.assertNotNull(fileset, "fileset should be created");
+ Assertions.assertEquals("comment", fileset.comment());
+ Assertions.assertEquals(Fileset.Type.EXTERNAL, fileset.type());
+ Assertions.assertEquals(storageLocation, fileset.storageLocation());
+ Assertions.assertEquals(1, fileset.properties().size());
+ Assertions.assertEquals("v1", fileset.properties().get("k1"));
+ Assertions.assertTrue(
+ hdfs.exists(new Path(storageLocation)), "storage location should be created");
+
+ // create fileset with storage location that not exist
+ String filesetName2 = "test_external_fileset_no_exist";
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ createFileset(
+ filesetName2, "comment", Fileset.Type.EXTERNAL, null, ImmutableMap.of("k1", "v1")),
+ "Should throw IllegalArgumentException when storage location is null");
+ }
+
+ @Test
+ public void testLoadFileset() throws IOException {
+ // create fileset
+ String filesetName = "test_load_fileset";
+ String storageLocation = storageLocation(filesetName);
+
+ Fileset fileset =
+ createFileset(
+ filesetName,
+ "comment",
+ Fileset.Type.MANAGED,
+ storageLocation,
+ ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName);
+
+ // test load fileset
+ Fileset loadFileset =
+ catalog
+ .asFilesetCatalog()
+ .loadFileset(NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName));
+ Assertions.assertEquals(fileset.name(), loadFileset.name(), "fileset should be loaded");
+ Assertions.assertEquals(fileset.comment(), loadFileset.comment(), "comment should be loaded");
+ Assertions.assertEquals(fileset.type(), loadFileset.type(), "type should be loaded");
+ Assertions.assertEquals(
+ fileset.storageLocation(),
+ loadFileset.storageLocation(),
+ "storage location should be loaded");
+ Assertions.assertEquals(
+ fileset.properties(), loadFileset.properties(), "properties should be loaded");
+
+ // test load a fileset that not exist
+ Assertions.assertThrows(
+ NoSuchFilesetException.class,
+ () ->
+ catalog
+ .asFilesetCatalog()
+ .loadFileset(NameIdentifier.of(metalakeName, catalogName, schemaName, "not_exist")),
+ "Should throw NoSuchFilesetException when fileset does not exist");
+ }
+
+ @Test
+ public void testDropManagedFileset() throws IOException {
+ // create fileset
+ String filesetName = "test_drop_managed_fileset";
+ String storageLocation = storageLocation(filesetName);
+
+ Assertions.assertFalse(
+ hdfs.exists(new Path(storageLocation)), "storage location should not exists");
+
+ Fileset fileset =
+ createFileset(
+ filesetName,
+ "comment",
+ Fileset.Type.MANAGED,
+ storageLocation,
+ ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName);
+
+ // drop fileset
+ boolean dropped =
+ catalog
+ .asFilesetCatalog()
+ .dropFileset(NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName));
+ Assertions.assertTrue(dropped, "fileset should be dropped");
+
+ // verify fileset is dropped
+ Assertions.assertFalse(
+ catalog
+ .asFilesetCatalog()
+ .filesetExists(NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName)),
+ "fileset should not be exists");
+ Assertions.assertFalse(
+ hdfs.exists(new Path(storageLocation)), "storage location should be dropped");
+ }
+
+ @Test
+ public void testDropExternalFileset() throws IOException {
+ // create fileset
+ String filesetName = "test_drop_external_fileset";
+ String storageLocation = storageLocation(filesetName);
+
+ Fileset fileset =
+ createFileset(
+ filesetName,
+ "comment",
+ Fileset.Type.EXTERNAL,
+ storageLocation,
+ ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName);
+
+ // drop fileset
+ boolean dropped =
+ catalog
+ .asFilesetCatalog()
+ .dropFileset(NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName));
+ Assertions.assertTrue(dropped, "fileset should be dropped");
+
+ // verify fileset is dropped
+ Assertions.assertFalse(
+ catalog
+ .asFilesetCatalog()
+ .filesetExists(NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName)),
+ "fileset should not be exists");
+ Assertions.assertTrue(
+ hdfs.exists(new Path(storageLocation)), "storage location should not be dropped");
+ }
+
+ @Test
+ public void testListFilesets() throws IOException {
+ // clear schema
+ dropSchema();
+ createSchema();
+
+ // test no fileset exists
+ NameIdentifier[] nameIdentifiers =
+ catalog
+ .asFilesetCatalog()
+ .listFilesets(Namespace.ofFileset(metalakeName, catalogName, schemaName));
+ Assertions.assertEquals(0, nameIdentifiers.length, "should have no fileset");
+
+ // create fileset1
+ String filesetName1 = "test_list_filesets1";
+ String storageLocation = storageLocation(filesetName1);
+
+ Fileset fileset1 =
+ createFileset(
+ filesetName1,
+ "comment",
+ Fileset.Type.MANAGED,
+ storageLocation,
+ ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName1);
+
+ // create fileset2
+ String filesetName2 = "test_list_filesets2";
+ String storageLocation2 = storageLocation(filesetName2);
+
+ Fileset fileset2 =
+ createFileset(
+ filesetName2,
+ "comment",
+ Fileset.Type.MANAGED,
+ storageLocation2,
+ ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName2);
+
+ // list filesets
+ NameIdentifier[] nameIdentifiers1 =
+ catalog
+ .asFilesetCatalog()
+ .listFilesets(Namespace.ofFileset(metalakeName, catalogName, schemaName));
+ Arrays.sort(nameIdentifiers1, Comparator.comparing(NameIdentifier::name));
+ Assertions.assertEquals(2, nameIdentifiers1.length, "should have 2 filesets");
+ Assertions.assertEquals(fileset1.name(), nameIdentifiers1[0].name());
+ Assertions.assertEquals(fileset2.name(), nameIdentifiers1[1].name());
+ }
+
+ @Test
+ public void testRenameFileset() throws IOException {
+ // create fileset
+ String filesetName = "test_rename_fileset";
+ String storageLocation = storageLocation(filesetName);
+
+ createFileset(
+ filesetName, "comment", Fileset.Type.MANAGED, storageLocation, ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName);
+
+ // rename fileset
+ String newFilesetName = "test_rename_fileset_new";
+ Fileset newFileset =
+ catalog
+ .asFilesetCatalog()
+ .alterFileset(
+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName),
+ FilesetChange.rename(newFilesetName));
+
+ // verify fileset is updated
+ Assertions.assertNotNull(newFileset, "fileset should be created");
+ Assertions.assertEquals(newFilesetName, newFileset.name(), "fileset name should be updated");
+ Assertions.assertEquals("comment", newFileset.comment(), "comment should not be change");
+ Assertions.assertEquals(Fileset.Type.MANAGED, newFileset.type(), "type should not be change");
+ Assertions.assertEquals(
+ storageLocation, newFileset.storageLocation(), "storage location should not be change");
+ Assertions.assertEquals(1, newFileset.properties().size(), "properties should not be change");
+ Assertions.assertEquals(
+ "v1", newFileset.properties().get("k1"), "properties should not be change");
+ }
+
+ @Test
+ public void testFilesetUpdateComment() throws IOException {
+ // create fileset
+ String filesetName = "test_update_fileset_comment";
+ String storageLocation = storageLocation(filesetName);
+
+ createFileset(
+ filesetName, "comment", Fileset.Type.MANAGED, storageLocation, ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName);
+
+ // update fileset comment
+ String newComment = "new_comment";
+ Fileset newFileset =
+ catalog
+ .asFilesetCatalog()
+ .alterFileset(
+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName),
+ FilesetChange.updateComment(newComment));
+ assertFilesetExists(filesetName);
+
+ // verify fileset is updated
+ Assertions.assertNotNull(newFileset, "fileset should be created");
+ Assertions.assertEquals(newComment, newFileset.comment(), "comment should be updated");
+ Assertions.assertEquals(Fileset.Type.MANAGED, newFileset.type(), "type should not be change");
+ Assertions.assertEquals(
+ storageLocation, newFileset.storageLocation(), "storage location should not be change");
+ Assertions.assertEquals(1, newFileset.properties().size(), "properties should not be change");
+ Assertions.assertEquals(
+ "v1", newFileset.properties().get("k1"), "properties should not be change");
+ }
+
+ @Test
+ public void testFilesetSetProperties() throws IOException {
+ // create fileset
+ String filesetName = "test_update_fileset_properties";
+ String storageLocation = storageLocation(filesetName);
+
+ createFileset(
+ filesetName, "comment", Fileset.Type.MANAGED, storageLocation, ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName);
+
+ // update fileset properties
+ Fileset newFileset =
+ catalog
+ .asFilesetCatalog()
+ .alterFileset(
+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName),
+ FilesetChange.setProperty("k1", "v2"));
+ assertFilesetExists(filesetName);
+
+ // verify fileset is updated
+ Assertions.assertNotNull(newFileset, "fileset should be created");
+ Assertions.assertEquals("comment", newFileset.comment(), "comment should not be change");
+ Assertions.assertEquals(Fileset.Type.MANAGED, newFileset.type(), "type should not be change");
+ Assertions.assertEquals(
+ storageLocation, newFileset.storageLocation(), "storage location should not be change");
+ Assertions.assertEquals(1, newFileset.properties().size(), "properties should not be change");
+ Assertions.assertEquals(
+ "v2", newFileset.properties().get("k1"), "properties should be updated");
+ }
+
+ @Test
+ public void testFilesetRemoveProperties() throws IOException {
+ // create fileset
+ String filesetName = "test_remove_fileset_properties";
+ String storageLocation = storageLocation(filesetName);
+
+ createFileset(
+ filesetName, "comment", Fileset.Type.MANAGED, storageLocation, ImmutableMap.of("k1", "v1"));
+ assertFilesetExists(filesetName);
+
+ // update fileset properties
+ Fileset newFileset =
+ catalog
+ .asFilesetCatalog()
+ .alterFileset(
+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName),
+ FilesetChange.removeProperty("k1"));
+ assertFilesetExists(filesetName);
+
+ // verify fileset is updated
+ Assertions.assertNotNull(newFileset, "fileset should be created");
+ Assertions.assertEquals("comment", newFileset.comment(), "comment should not be change");
+ Assertions.assertEquals(Fileset.Type.MANAGED, newFileset.type(), "type should not be change");
+ Assertions.assertEquals(
+ storageLocation, newFileset.storageLocation(), "storage location should not be change");
+ Assertions.assertEquals(0, newFileset.properties().size(), "properties should be removed");
+ }
+
+ private Fileset createFileset(
+ String filesetName,
+ String comment,
+ Fileset.Type type,
+ String storageLocation,
+ Map<String, String> properties) {
+ if (storageLocation != null) {
+ Path location = new Path(storageLocation);
+ try {
+ hdfs.deleteOnExit(location);
+ } catch (IOException e) {
+ LOG.warn("Failed to delete location: {}", location, e);
+ }
+ }
+
+ return catalog
+ .asFilesetCatalog()
+ .createFileset(
+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName),
+ comment,
+ type,
+ storageLocation,
+ properties);
+ }
+
+ private void assertFilesetExists(String filesetName) throws IOException {
+ Assertions.assertTrue(
+ catalog
+ .asFilesetCatalog()
+ .filesetExists(NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName)),
+ "fileset should be exists");
+ Assertions.assertTrue(
+ hdfs.exists(new Path(storageLocation(filesetName))), "storage location should be exists");
+ }
+
+ private static String defaultBaseLocation() {
+ if (defaultBaseLocation == null) {
+ defaultBaseLocation =
+ String.format(
+ "hdfs://%s:%d/user/hadoop/%s.db",
+ containerSuite.getHiveContainer().getContainerIpAddress(),
+ HiveContainer.HDFS_DEFAULTFS_PORT,
+ schemaName.toLowerCase());
+ }
+ return defaultBaseLocation;
+ }
+
+ private static String storageLocation(String filesetName) {
+ return defaultBaseLocation() + "/" + filesetName;
+ }
+}