Skip to content

Conversation

dk2k
Copy link
Contributor

@dk2k dk2k commented Apr 2, 2025

Comparison with == and != checks memory adresses
equals() check values

Copy link

sonarqubecloud bot commented Apr 2, 2025

Copy link

@aturoczy aturoczy left a comment

Choose a reason for hiding this comment

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

Please fill out the PR description accordingly.

private static String getMetricStageName(String stageName, ReplicationMetricCollector metricCollector) {
if( stageName == "REPL_DUMP" || stageName == "REPL_LOAD" || stageName == "ATLAS_DUMP" || stageName == "ATLAS_LOAD"
|| stageName == "RANGER_DUMP" || stageName == "RANGER_LOAD" || stageName == "RANGER_DENY"){
if( "REPL_DUMP".equals(stageName) || "REPL_LOAD".equals(stageName) || "ATLAS_DUMP".equals(stageName) || "ATLAS_LOAD".equals(stageName)

Choose a reason for hiding this comment

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

I do not have to much sentiment if the string is equals or ==. Both are acceptable. I would chime @deniskuzZ and @ayushtkn to tell which is the most commonly used style in Hive.

Copy link
Contributor

Choose a reason for hiding this comment

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

In Java the == operator compares only the references not the actual content of the objects so this change is needed here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Old code also works because Java uses constant folding at compile time for optimization.
and this stageName comes from private final String STAGE_NAME = "REPL_LOAD";
but to make it consistent with non-final fields, .equals() is a better option.

You can check the first answer from this.

https://stackoverflow.com/questions/8581824/does-java-compiler-include-string-constant-folding

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Feel free to reach out on the [email protected] list if the patch is in need of reviews.

@github-actions github-actions bot added the stale label Jul 16, 2025
@github-actions github-actions bot closed this Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants