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

[#6750] improvement(core): property framework supports prefix #6751

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

Conversation

mchades
Copy link
Contributor

@mchades mchades commented Mar 25, 2025

What changes were proposed in this pull request?

property framework supports prefix

Why are the changes needed?

some properties with fixed prefixes maybe immutable or required and need to be verified.

Fix: #6750

Does this PR introduce any user-facing change?

no

How was this patch tested?

tests added

@mchades mchades force-pushed the oss-prop-prefix branch 2 times, most recently from 44b4462 to 9d8cec6 Compare March 26, 2025 03:04
@mchades mchades requested review from jerryshao and yuqi1129 March 26, 2025 06:05
@mchades mchades marked this pull request as ready for review March 26, 2025 06:05
@mchades mchades force-pushed the oss-prop-prefix branch 2 times, most recently from 5244adf to 597e34e Compare March 26, 2025 06:41
.collect(Collectors.toList());
Preconditions.checkArgument(
absentProperties.isEmpty(),
"Properties are required and must be set: %s",
"Properties or properties with a fixed prefix are required and must be set: %s",
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't get Properties or properties with a fixed prefix are required. According to your code, it should be Required properties should be set or required prefix properties should be set with prefixes in the key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be more accurate, prefix properties should be a property with a fixed prefix, then you can understand the above description well

* @return the property entry object of the property.
* @throws IllegalArgumentException if the property is not defined.
*/
default PropertyEntry<?> getPropertyEntry(String propertyName) throws IllegalArgumentException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you provide more comments on this method? will we get the value of the longest key for prefix property and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@@ -125,6 +125,8 @@ void testCatalogProperty() {
throwable
.getMessage()
.contains(
String.format("Properties are required and must be set: [%s]", METASTORE_URIS)));
String.format(
"Properties or properties with a fixed prefix are required and must be set: [%s]",
Copy link
Contributor

Choose a reason for hiding this comment

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

"Properties or property prefixes..."

: propertyEntries().entrySet().stream()
.filter(e -> e.getValue().isPrefix() && propertyName.startsWith(e.getKey()))
// get the longest prefix property
.max(Map.Entry.comparingByKey(Comparator.comparingInt(String::length)))
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the meaning here, can you explain more?

@mchades mchades requested review from jerryshao and yuqi1129 March 31, 2025 14:21
return propertyEntries().containsKey(propertyName)
&& propertyEntries().get(propertyName).isReserved();
// First check non-prefix exact match
PropertyEntry<?> directEntry = propertyEntries().get(propertyName);
Copy link
Contributor

Choose a reason for hiding this comment

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

nonPrefixEntry.

Comment on lines 158 to 160
* <p>For example, if there are two property prefix entries "foo." and "foo.bar", and the property
* name is "foo.bar.baz", the entry for "foo.bar" will be returned. If the property entry
* "foo.bar.baz" is defined, it will be returned instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a valid scenario? Do we need to allow such scenario or ban this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we already have the scenario, see the chained authorization plugin properties:

property authorization.chain.plugins and property prefix authorization.chain. have the same prefix

* @return the non-prefix property entry object of the property.
* @throws IllegalArgumentException if the property is not defined or is a prefix.
*/
default PropertyEntry<?> getNonPrefixEntry(String propertyName) throws IllegalArgumentException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to use Optional instead of throw and catch an exception.

@mchades mchades requested a review from jerryshao April 1, 2025 12:52
@mchades mchades closed this Apr 1, 2025
@mchades mchades reopened this Apr 1, 2025
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] support validation of property with fixed prefix
3 participants