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

[#3460] feat(api): Add API design for Tag system #3486

Merged
merged 6 commits into from
May 23, 2024

Conversation

jerryshao
Copy link
Contributor

What changes were proposed in this pull request?

This PR adds the API support for Tag system in Gravitino.

Why are the changes needed?

This is the first step to add a tag system.

Fix: #3460

Does this PR introduce any user-facing change?

Yes.

How was this patch tested?

No. Test will be added later when implementing the logic.

* @param tagsToRemove The array of tag name to be removed from the entity.
* @return The array of tag names that are associated with the entity.
*/
String[] associateTags(String[] tagsToAdd, String[] tagsToRemove);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this method, the requestor need to know which tags are new, which are existed but to be removed, this might be a little complicated for the requestor; how about change it to "applyTags(String[] tags)", so that each time the requestor pass in a full set of the tags, no need to distinguish which are new and which are to be remove;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the current API, users still don't need to distinguish whether the tag is new or not. They can add all the tags they want to tagsToAdd, I will handle this in the backend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, the backend will compare and recognize that, which is good for the client.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a tag appears in two arrays at the same time, what will be the result?

Copy link
Contributor Author

@jerryshao jerryshao May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be no-op. Same as if we both enable setProperty and removeProperty on the same key for alterTable.

@jerqi
Copy link
Collaborator

jerqi commented May 22, 2024

For snowflake, tag is related to the securable object. You can see https://docs.snowflake.com/en/user-guide/object-tagging

Tag lineage[¶](https://docs.snowflake.com/en/user-guide/object-tagging#tag-lineage)
A tag is inherited based on the Snowflake securable object hierarchy. Snowflake recommends defining the tag keys as closely as possible to the [securable object](https://docs.snowflake.com/en/user-guide/security-access-control-overview.html#label-access-control-securable-objects) hierarchy in your Snowflake environment.

shaofengshi
shaofengshi previously approved these changes May 22, 2024
}

/** @return The number of entities that are using this tag. */
int inUse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this method have a default implementation?

return usedEntities().length

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

@jerryshao
Copy link
Contributor Author

@shaofengshi @jerqi @mchades can you please review again?

Copy link
Contributor

@mchades mchades left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shaofengshi
Copy link
Contributor

@shaofengshi @jerqi @mchades can you please review again?

LGTM

shaofengshi
shaofengshi previously approved these changes May 23, 2024
int inUse();

/** @return The list of objects that are using this tag. */
MetadataObject[] usedObjects();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about associatedObjects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

/** The extended information of the tag. */
interface Extended {
/** @return The number of objects that are using this tag. */
default int inUse() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inUse seems a state. Could you give this a better name?

* @throws NoSuchTagException If the tag does not exist.
* @throws IllegalArgumentException If the changes cannot be applied to the tag.
*/
Tag alterTag(String name, TagChange... changes)
Copy link
Collaborator

@jerqi jerqi May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use updateTag? Snowflake use AlterTag. Git uses UpdateTag. All is ok for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with either, I have no strong preference.

* @return The tag.
* @throws NoSuchTagException If the tag does not exist.
*/
Tag getTag(String name) throws NoSuchTagException;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need extended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, there's no such requirement based on our UI requirement, I think we can add it later on.

@jerryshao
Copy link
Contributor Author

I changed to inAssociation, WDYT? @jerqi

@jerqi
Copy link
Collaborator

jerqi commented May 23, 2024

I changed to inAssociation, WDYT? @jerqi

Extended's inAssocation may be confusing for users. Because Extended can't give any information about this is related to object. I may prefer associatedObjectsCount.
Or
we can have another abstraction layer like

Extened {
    AssociationObjects {
         count
         objects
   }
}

or we remove extended this layer.

    AssociationObjects {
         count
         objects
   }

Maybe I don't provide a enough proper solution, you can think a better solution.

@jerryshao
Copy link
Contributor Author

jerryshao commented May 23, 2024

Extended basically means that we have some extended information method for the tag, this may not be limited to the current two interfaces, we can add more later. While changing to AssociationObjects will limit the extensions, the reason why I use Extended is referred from Spark's explain API to add more information to the current object.

@jerryshao
Copy link
Contributor Author

@jerqi please review again?

/** The interface of the associated objects of the tag. */
interface AssociatedObjects {

/** @return The number of objects that are associated with this Tag */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag -> tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix this in the following PR.

Copy link
Collaborator

@jerqi jerqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just one nit.

@jerryshao jerryshao merged commit 29a3d62 into apache:main May 23, 2024
22 checks passed
diqiu50 pushed a commit to diqiu50/gravitino that referenced this pull request Jun 13, 2024
### What changes were proposed in this pull request?

This PR adds the API support for Tag system in Gravitino.

### Why are the changes needed?

This is the first step to add a tag system.

Fix: apache#3460 

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

Yes.

### How was this patch tested?

No. Test will be added later when implementing the logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Subtask] API design and implementation for Tag system.
5 participants