-
Notifications
You must be signed in to change notification settings - Fork 382
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
base: main
Are you sure you want to change the base?
Conversation
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); | |||
} |
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.
move 54-56 before 53 so that this is easier to understand?
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 |
Assertions.assertEquals("role", roleObject.fullName()); | ||
|
||
// Test illegal name | ||
Assertions.assertThrows( |
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.
role.test
is a legal name.
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.
You should add the test case in TestJdbcBackend instead of this place.
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.
But it does throw the IllegalArgumentException error?
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.
It won't throw IllegalArgumentException
.
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.
You should create the role metadata object by
MetadataObjects.of(null, "role.test", ROLE);
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.
The name with dot should be legal name for role instead of illegal name. It shouldn't throw IllegalArgumentException.
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.
Oh, I see, so I need to change the legacy implement code?
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.
Yes.
d4ac267
to
49b8254
Compare
Long roleIdWithoutDot = | ||
RoleMetaService.getInstance().getRoleIdByMetalakeIdAndName(metalakeId, roleNameWithoutDot); | ||
assertEquals(roleWithoutDot.id(), roleIdWithoutDot); | ||
} |
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.
@jerqi
Is this correct?
just test the method with and without dot
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.
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
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.
You can modify the logic MetadataObjects.of(null, "role.test", ROLE)
.
You would better modify the logic of MetadataObjects.parse
.
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.
Ok
…ption and add corresponding unit test
@jerqi |
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