Skip to content

Commit

Permalink
[apache#1760] Fix(core): Fix bug when introducing fileset api in Cata…
Browse files Browse the repository at this point in the history
…logOperationDispatcher (apache#1762)

### What changes were proposed in this pull request?

Using the correct PropertiesMetadata to check the value when doing
operations.

### Why are the changes needed?

This is bug introduced in apache#1667 , fix it here.

Fix: apache#1706 

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Add UTs.
  • Loading branch information
jerryshao authored and ch3yne committed Jan 29, 2024
1 parent ee8d4a7 commit 23b045e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public Table loadTable(NameIdentifier ident) throws NoSuchTableException {
.withHiddenPropertiesSet(
getHiddenPropertyNames(
catalogIdentifier,
HasPropertyMetadata::filesetPropertiesMetadata,
HasPropertyMetadata::tablePropertiesMetadata,
table.properties()));
}

Expand Down Expand Up @@ -667,7 +667,9 @@ public Fileset loadFileset(NameIdentifier ident) throws NoSuchFilesetException {
return EntityCombinedFileset.of(fileset)
.withHiddenPropertiesSet(
getHiddenPropertyNames(
catalogIdent, HasPropertyMetadata::tablePropertiesMetadata, fileset.properties()));
catalogIdent,
HasPropertyMetadata::filesetPropertiesMetadata,
fileset.properties()));
}

@Override
Expand Down Expand Up @@ -705,7 +707,7 @@ public Fileset createFileset(
.withHiddenPropertiesSet(
getHiddenPropertyNames(
catalogIdent,
HasPropertyMetadata::tablePropertiesMetadata,
HasPropertyMetadata::filesetPropertiesMetadata,
createdFileset.properties()));
}

Expand All @@ -725,7 +727,7 @@ public Fileset alterFileset(NameIdentifier ident, FilesetChange... changes)
.withHiddenPropertiesSet(
getHiddenPropertyNames(
catalogIdent,
HasPropertyMetadata::tablePropertiesMetadata,
HasPropertyMetadata::filesetPropertiesMetadata,
alteredFileset.properties()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public TestCatalogOperations(Map<String, String> config) {
filesets = Maps.newHashMap();
tablePropertiesMetadata = new TestBasePropertiesMetadata();
schemaPropertiesMetadata = new TestBasePropertiesMetadata();
filesetPropertiesMetadata = new TestBasePropertiesMetadata();
filesetPropertiesMetadata = new TestFilesetPropertiesMetadata();
this.config = config;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino;

import com.datastrato.gravitino.catalog.PropertyEntry;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;

public class TestFilesetPropertiesMetadata extends TestBasePropertiesMetadata {

public static final String TEST_FILESET_HIDDEN_KEY = "fileset_key";

private static final Map<String, PropertyEntry<?>> TEST_FILESET_PROPERTY;

static {
List<PropertyEntry<?>> tablePropertyMetadata =
ImmutableList.of(
PropertyEntry.stringPropertyEntry(
TEST_FILESET_HIDDEN_KEY,
"test fileset required k1 property",
false,
false,
"test",
true,
false));

TEST_FILESET_PROPERTY = Maps.uniqueIndex(tablePropertyMetadata, PropertyEntry::getName);
}

@Override
protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
return ImmutableMap.<String, PropertyEntry<?>>builder()
.putAll(super.specificPropertyEntries())
.putAll(TEST_FILESET_PROPERTY)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static com.datastrato.gravitino.Entity.EntityType.TABLE;
import static com.datastrato.gravitino.StringIdentifier.ID_KEY;
import static com.datastrato.gravitino.TestBasePropertiesMetadata.COMMENT_KEY;
import static com.datastrato.gravitino.TestFilesetPropertiesMetadata.TEST_FILESET_HIDDEN_KEY;
import static com.datastrato.gravitino.catalog.BasePropertiesMetadata.GRAVITINO_MANAGED_ENTITY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -678,6 +679,7 @@ private void testProperties(Map<String, String> expectedProps, Map<String, Strin
});
Assertions.assertFalse(testProps.containsKey(StringIdentifier.ID_KEY));
Assertions.assertFalse(testProps.containsKey(GRAVITINO_MANAGED_ENTITY));
Assertions.assertFalse(testProps.containsKey(TEST_FILESET_HIDDEN_KEY));
}

private void testPropertyException(Executable operation, String... errorMessage) {
Expand Down

0 comments on commit 23b045e

Please sign in to comment.