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

[#6004] fix: use fullName instead of names.get(0) when get role #6057

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cool9850311
Copy link
Contributor

What changes were proposed in this pull request?
use fullName instead of names.get(0) when get role Why are the changes needed?
Fix: #6004

Does this PR introduce any user-facing change?
NO

How was this patch tested?
existing ut

What changes were proposed in this pull request?
use fullName instead of names.get(0) when get role
Why are the changes needed?
Fix: apache#6004

Does this PR introduce any user-facing change?
NO

How was this patch tested?
existing ut
@@ -52,7 +52,7 @@ public static long getMetadataObjectId(

List<String> names = DOT_SPLITTER.splitToList(fullName);
if (type == MetadataObject.Type.ROLE) {
return RoleMetaService.getInstance().getRoleIdByMetalakeIdAndName(metalakeId, names.get(0));
return RoleMetaService.getInstance().getRoleIdByMetalakeIdAndName(metalakeId, fullName);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

move 54-56 before 53 so that this is easier to understand?

@jerqi
Copy link
Contributor

jerqi commented Jan 2, 2025

Could you add a UT for this?

@cool9850311
Copy link
Contributor Author

Could you add a UT for this?

This part is covered by testMetaLifeCycleFromCreationToDeletion in TestJDBCBackend, do i have to add other ut for this?

@jerqi
Copy link
Contributor

jerqi commented Jan 2, 2025

Could you add a UT for this?

This part is covered by testMetaLifeCycleFromCreationToDeletion in TestJDBCBackend, do i have to add other ut for this?

Yes, you need to add a new test case. If the fullName contains ., legacy implement will produce an error result. The legacy test case doesn't cover this.

Assertions.assertEquals("role", roleObject.fullName());

// Test illegal name
Assertions.assertThrows(
Copy link
Contributor

Choose a reason for hiding this comment

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

role.test is a legal name.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should add the test case in TestJdbcBackend instead of this place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it does throw the IllegalArgumentException error?

Copy link
Contributor

Choose a reason for hiding this comment

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

It won't throw IllegalArgumentException.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should create the role metadata object by

MetadataObjects.of(null, "role.test", ROLE);

Copy link
Contributor

Choose a reason for hiding this comment

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

The name with dot should be legal name for role instead of illegal name. It shouldn't throw IllegalArgumentException.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see, so I need to change the legacy implement code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

Long roleIdWithoutDot =
RoleMetaService.getInstance().getRoleIdByMetalakeIdAndName(metalakeId, roleNameWithoutDot);
assertEquals(roleWithoutDot.id(), roleIdWithoutDot);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jerqi
Is this correct?
just test the method with and without dot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public static MetadataObject of(List<String> names, MetadataObject.Type type) {
    Preconditions.checkArgument(names != null, "Cannot create a metadata object with null names");
    Preconditions.checkArgument(!names.isEmpty(), "Cannot create a metadata object with no names");
    Preconditions.checkArgument(
        names.size() <= 4,
        "Cannot create a metadata object with the name length which is greater than 4");
    Preconditions.checkArgument(type != null, "Cannot create a metadata object with no type");

    Preconditions.checkArgument(
        names.size() != 1
            || type == MetadataObject.Type.CATALOG
            || type == MetadataObject.Type.METALAKE
            || type == MetadataObject.Type.ROLE,
        "If the length of names is 1, it must be the CATALOG, METALAKE, or ROLE type");

    Preconditions.checkArgument(
        names.size() != 2 || type == MetadataObject.Type.SCHEMA,
        "If the length of names is 2, it must be the SCHEMA type");

    Preconditions.checkArgument(
        names.size() != 3
            || type == MetadataObject.Type.FILESET
            || type == MetadataObject.Type.TABLE
            || type == MetadataObject.Type.TOPIC
            || type == MetadataObject.Type.MODEL,
        "If the length of names is 3, it must be FILESET, TABLE, TOPIC or MODEL");

    Preconditions.checkArgument(
        names.size() != 4 || type == MetadataObject.Type.COLUMN,
        "If the length of names is 4, it must be COLUMN");

    for (String name : names) {
      checkName(name);
    }

    return new MetadataObjectImpl(getParentFullName(names), getLastName(names), type);
  }

I am kinda confused now
So what is the Rule of Role name?
Does it have length limit?
For current impl
if Role name contains dot
insertRelation will throw IllegalArgumentException, cause it will run through MetadataObjects.of(null, "role.test", ROLE); and above checks and conflict with "must be the * type" Preconditions
insert and other methods will not throw any exception

Copy link
Contributor

@jerqi jerqi Jan 3, 2025

Choose a reason for hiding this comment

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

You can modify the logic MetadataObjects.of(null, "role.test", ROLE).
You would better modify the logic of MetadataObjects.parse.

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

@cool9850311
Copy link
Contributor Author

@jerqi
could you review the new commit, Thanks.

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.

[Improvement] when get metadata object id of role, should get role fullName
3 participants