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

[#6349] fix(core,hive-catalog): Fix bugs in AuthorizationUtils and remove protobuf-java from catalog hive #6351

Merged
merged 3 commits into from
Jan 22, 2025
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
2 changes: 2 additions & 0 deletions catalogs/catalog-hive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ tasks {
exclude("guava-*.jar")
exclude("log4j-*.jar")
exclude("slf4j-*.jar")
// Exclude the following jars to avoid conflict with the jars in authorization-gcp
exclude("protobuf-java-*.jar")
}
into("$rootDir/distribution/package/catalogs/hive/libs")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Entity;
import org.apache.gravitino.GravitinoEnv;
Expand Down Expand Up @@ -476,7 +477,7 @@ public static List<String> getMetadataObjectLocation(
Schema schema = GravitinoEnv.getInstance().schemaDispatcher().loadSchema(ident);
if (schema.properties().containsKey(HiveConstants.LOCATION)) {
String schemaLocation = schema.properties().get(HiveConstants.LOCATION);
if (schemaLocation != null && schemaLocation.isEmpty()) {
if (StringUtils.isNotBlank(schemaLocation)) {
locations.add(schemaLocation);
} else {
LOG.warn("Schema %s location is not found", ident);
Expand All @@ -497,7 +498,7 @@ public static List<String> getMetadataObjectLocation(
Table table = GravitinoEnv.getInstance().tableDispatcher().loadTable(ident);
if (table.properties().containsKey(HiveConstants.LOCATION)) {
String tableLocation = table.properties().get(HiveConstants.LOCATION);
if (tableLocation != null && tableLocation.isEmpty()) {
if (StringUtils.isNotBlank(tableLocation)) {
locations.add(tableLocation);
} else {
LOG.warn("Table %s location is not found", ident);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@
*/
package org.apache.gravitino.authorization;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.util.List;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Entity;
import org.apache.gravitino.GravitinoEnv;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
import org.apache.gravitino.catalog.CatalogDispatcher;
import org.apache.gravitino.catalog.TableDispatcher;
import org.apache.gravitino.exceptions.IllegalNameIdentifierException;
import org.apache.gravitino.exceptions.IllegalNamespaceException;
import org.apache.gravitino.meta.AuditInfo;
import org.apache.gravitino.meta.RoleEntity;
import org.apache.gravitino.rel.Table;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

class TestAuthorizationUtils {

Expand Down Expand Up @@ -210,4 +219,32 @@ void testFilteredSecurableObjects() {
Assertions.assertTrue(filteredRole.securableObjects().contains(schema2Object));
Assertions.assertTrue(filteredRole.securableObjects().contains(table2Object));
}

@Test
void testGetMetadataObjectLocation() throws IllegalAccessException {
CatalogDispatcher catalogDispatcher = Mockito.mock(CatalogDispatcher.class);
TableDispatcher tableDispatcher = Mockito.mock(TableDispatcher.class);
Catalog catalog = Mockito.mock(Catalog.class);
Table table = Mockito.mock(Table.class);

Mockito.when(table.properties()).thenReturn(ImmutableMap.of("location", "gs://bucket/1"));
Mockito.when(catalog.provider()).thenReturn("hive");
Mockito.when(catalogDispatcher.loadCatalog(Mockito.any())).thenReturn(catalog);
Mockito.when(tableDispatcher.loadTable(Mockito.any())).thenReturn(table);

FieldUtils.writeField(GravitinoEnv.getInstance(), "catalogDispatcher", catalogDispatcher, true);
FieldUtils.writeField(GravitinoEnv.getInstance(), "tableDispatcher", tableDispatcher, true);

List<String> locations =
AuthorizationUtils.getMetadataObjectLocation(
NameIdentifier.of("catalog", "schema", "table"), Entity.EntityType.TABLE);
Assertions.assertEquals(1, locations.size());
Assertions.assertEquals("gs://bucket/1", locations.get(0));

locations =
AuthorizationUtils.getMetadataObjectLocation(
NameIdentifier.of("catalog", "schema", "fileset"), Entity.EntityType.TABLE);
Assertions.assertEquals(1, locations.size());
Assertions.assertEquals("gs://bucket/1", locations.get(0));
}
}
Loading