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

[#4303] improvement(core): Improved removed loop code and readability #4335

Merged
merged 4 commits into from
Aug 5, 2024

Conversation

khmgobe
Copy link
Contributor

@khmgobe khmgobe commented Aug 1, 2024

What changes were proposed in this pull request?
Reflect changes to improve readability

Why are the changes needed?
Readability and no unnecessary repetition compared to existing code

Fix: #4303

Does this PR introduce any user-facing change?
No

How was this patch tested?
Check change code and existing code comparison

@jerryshao
Copy link
Contributor

@xloya would you please help to review this code?

SchemaMetaService.getInstance().getSchemaIdByCatalogIdAndName(parentEntityId, name);
break;
}
if (namespace.levels().length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using namespace.levels().length >=1 here? The same treatment is also applied below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xloya

Thank you for your suggestion. I guess I missed something.

if (namespace.levels().length >= 1) {
      parentEntityId = MetalakeMetaService.getInstance().getMetalakeIdByName(namespace.level(0));
}

if (namespace.levels().length >= 2) {
      parentEntityId =
          CatalogMetaService.getInstance()
              .getCatalogIdByMetalakeIdAndName(parentEntityId, namespace.level(1));
}

if (namespace.levels().length >= 3) {
      parentEntityId =
          SchemaMetaService.getInstance()
              .getSchemaIdByCatalogIdAndName(parentEntityId, namespace.level(2));
}

Is it correct that you mentioned changing it like this? If it is, we will proceed with the change like this.

Copy link
Member

Choose a reason for hiding this comment

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

parentEntityId only needs to be set once, if the level is 3 it will be set 3 times above.

Copy link
Contributor

Choose a reason for hiding this comment

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

@justinmclean Hi, according to the current storage structure design, if the namespace has 3 levels, it is reasonable to recursively obtain the parentEntityId 3 times, because we cannot guarantee that the parent resource can be obtained uniquely through Name, so we need to use parentEntityId and Name to locate the upper-level resource at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

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

@xloya

Thank you for your suggestion. I guess I missed something.

if (namespace.levels().length >= 1) {
      parentEntityId = MetalakeMetaService.getInstance().getMetalakeIdByName(namespace.level(0));
}

if (namespace.levels().length >= 2) {
      parentEntityId =
          CatalogMetaService.getInstance()
              .getCatalogIdByMetalakeIdAndName(parentEntityId, namespace.level(1));
}

if (namespace.levels().length >= 3) {
      parentEntityId =
          SchemaMetaService.getInstance()
              .getSchemaIdByCatalogIdAndName(parentEntityId, namespace.level(2));
}

Is it correct that you mentioned changing it like this? If it is, we will proceed with the change like this.

Yes, I think this can better express the Namespace levels:

if (namespace.levels().length >= 1) {
      ......
}

if (namespace.levels().length >= 2) {
      ......
}

if (namespace.levels().length == 3) {
      ......
}

Copy link
Member

@justinmclean justinmclean Aug 2, 2024

Choose a reason for hiding this comment

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

For example if level is 3 then parentEntityId will be set three times with 2 of those values being thrown away. In this order:

  1. via getMetalakeIdByName (result overwritten by 2 and 3)
  2. via getCatalogIdByMetalakeIdAndName (result overwritten by 3)
  3. via getSchemaIdByCatalogIdAndName

Why not just obtain it by directly calling getSchemaIdByCatalogIdAndName? e.g reverse the order of the if statements and change them to if/else ifs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think what @khmgobe is reasonable, it is more readable than the original code, we can also improve like what @xloya mentioned.

The only bad thing is that parentEntityId is mutable, which is not a good programming practice, but I think it is acceptable as there's no side-effect here.

@khmgobe would you please modify the code like what @xloya suggested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jerryshao @justinmclean

Is there a consensus?
Please let me know if you don't.

If it's matched, we're going to make a change.

The reason for asking again is that I think I'll change it
when it's decided for sure because I'm afraid there will be a change in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please go ahead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jerryshao I revised the code as per the common opinion, so please check it.

@xloya
Copy link
Contributor

xloya commented Aug 1, 2024

This change is generally okay for me, except for one minor suggestion.

Copy link
Contributor

@jerryshao jerryshao left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @khmgobe for the contributions.

@jerryshao jerryshao merged commit 24b305d into apache:main Aug 5, 2024
33 checks passed
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.

4 participants