-
Notifications
You must be signed in to change notification settings - Fork 383
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
[#5070] improvement(core): Add check for the full name of the metadata object #5075
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,16 +18,22 @@ | |
*/ | ||
package org.apache.gravitino.utils; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.BiMap; | ||
import com.google.common.collect.ImmutableBiMap; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.gravitino.Entity; | ||
import org.apache.gravitino.GravitinoEnv; | ||
import org.apache.gravitino.MetadataObject; | ||
import org.apache.gravitino.NameIdentifier; | ||
import org.apache.gravitino.authorization.AuthorizationUtils; | ||
import org.apache.gravitino.exceptions.NoSuchMetadataObjectException; | ||
import org.apache.gravitino.exceptions.NoSuchRoleException; | ||
|
||
public class MetadataObjectUtil { | ||
|
||
|
@@ -98,4 +104,77 @@ public static NameIdentifier toEntityIdent(String metalakeName, MetadataObject m | |
"Unknown metadata object type: " + metadataObject.type()); | ||
} | ||
} | ||
|
||
/** | ||
* This method will check if the entity is existed explicitly, internally this check will load the | ||
* entity from underlying sources to entity store if not stored, and will allocate an uid for this | ||
* entity, with this uid tags can be associated with this entity. This method should be called out | ||
* of the tree lock, otherwise it will cause deadlock. | ||
* | ||
* @param metalake The metalake name | ||
* @param object The metadata object | ||
* @param env The Gravitino environment | ||
* @throws NoSuchMetadataObjectException if the metadata object type doesn't exist. | ||
*/ | ||
public static void checkMetadataObject(String metalake, MetadataObject object, GravitinoEnv env) { | ||
NameIdentifier identifier = toEntityIdent(metalake, object); | ||
|
||
Supplier<NoSuchMetadataObjectException> exceptionToThrowSupplier = | ||
() -> | ||
new NoSuchMetadataObjectException( | ||
"Metadata object %s type %s doesn't exist", object.fullName(), object.type()); | ||
|
||
switch (object.type()) { | ||
case METALAKE: | ||
NameIdentifierUtil.checkMetalake(identifier); | ||
check(env.metalakeDispatcher().metalakeExists(identifier), exceptionToThrowSupplier); | ||
break; | ||
|
||
case CATALOG: | ||
NameIdentifierUtil.checkCatalog(identifier); | ||
check(env.catalogDispatcher().catalogExists(identifier), exceptionToThrowSupplier); | ||
break; | ||
|
||
case SCHEMA: | ||
NameIdentifierUtil.checkSchema(identifier); | ||
check(env.schemaDispatcher().schemaExists(identifier), exceptionToThrowSupplier); | ||
break; | ||
|
||
case FILESET: | ||
NameIdentifierUtil.checkFileset(identifier); | ||
check(env.filesetDispatcher().filesetExists(identifier), exceptionToThrowSupplier); | ||
break; | ||
|
||
case TABLE: | ||
NameIdentifierUtil.checkTable(identifier); | ||
check(env.tableDispatcher().tableExists(identifier), exceptionToThrowSupplier); | ||
break; | ||
|
||
case TOPIC: | ||
NameIdentifierUtil.checkTopic(identifier); | ||
check(env.topicDispatcher().topicExists(identifier), exceptionToThrowSupplier); | ||
break; | ||
|
||
case ROLE: | ||
AuthorizationUtils.checkRole(identifier); | ||
try { | ||
env.accessControlDispatcher().getRole(metalake, object.fullName()); | ||
} catch (NoSuchRoleException nsr) { | ||
throw checkNotNull(exceptionToThrowSupplier).get(); | ||
} | ||
break; | ||
|
||
case COLUMN: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we support checking columns or not? If the answer is 'No', you can remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. |
||
default: | ||
throw new IllegalArgumentException( | ||
String.format("Doesn't support the type %s", object.type())); | ||
} | ||
} | ||
|
||
private static void check( | ||
final boolean expression, Supplier<? extends RuntimeException> exceptionToThrowSupplier) { | ||
if (!expression) { | ||
throw checkNotNull(exceptionToThrowSupplier).get(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we doesn't need
GravitinoEnv env
params in thecheckMetadataObject(...)
function.We can directly call
GravitinoEnv.getInstance()
in the function body.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
env
as a method parameter will make the mock test easy to achieve.